(self)
Suggest accessories based on 'Accessory Products' of products in cart
Suggest accessories based on 'Accessory Products' of products in cart
Suggest accessories based on Accessory Products of products in cart
def _cart_accessories(self):
        """ Suggest accessories based on 'Accessory Products' of products in cart """
        for order in self:
            products = order.website_order_line.mapped('product_id')
            accessory_products = self.env['product.product']
            for line in order.website_order_line.filtered(lambda l: l.product_id):
                combination = line.product_id.product_template_attribute_value_ids + line.product_no_variant_attribute_value_ids
                accessory_products |= line.product_id.product_tmpl_id._get_website_accessory_product().filtered(lambda product:
                    product not in products and
                    product._is_variant_possible(parent_combination=combination) and
                    (product.company_id == line.company_id or not product.company_id)
                )

            return random.sample(accessory_products, len(accessory_products))
def _cart_accessories ( self ) : for order in self : products = order . website_order_line . mapped ( 'product_id' ) accessory_products = self . env [ 'product.product' ] for line in order . website_order_line . filtered ( lambda l : l . product_id ) : combination = line . product_id . product_template_attribute_value_ids + line . product_no_variant_attribute_value_ids accessory_products |= line . product_id . product_tmpl_id . _get_website_accessory_product ( ) . filtered ( lambda product : product not in products and product . _is_variant_possible ( parent_combination = combination ) and ( product . company_id == line . company_id or not product . company_id ) ) return random . sample ( accessory_products , len ( accessory_products ) )