/**
  * Get crosssell items
  *
  * @return array
  */
 public function getItems()
 {
     if (!$this->helper->isActiveEngine() || !$this->helper->isCrosssellEnabled()) {
         return parent::getItems();
     }
     $items = $this->getData('items');
     if (is_null($items)) {
         $lastAdded = null;
         //This code path covers the 2 cases - product page and shopping cart
         if ($this->getProduct() != null) {
             $lastAdded = $this->getProduct()->getId();
         } else {
             $cartProductIds = $this->_getCartProductIds();
             $lastAdded = null;
             for ($i = count($cartProductIds) - 1; $i >= 0; $i--) {
                 $id = $cartProductIds[$i];
                 $parentIds = $this->_confModel->getParentIdsByChild($id);
                 if (empty($parentIds)) {
                     $lastAdded = $id;
                     break;
                 }
             }
         }
         $crossSellIds = $this->crossSellHelper->getRecommendationsIds($lastAdded);
         $this->_maxItemCount = $this->helper->getCrosssellLimit();
         $items = $this->_getCollection()->addAttributeToFilter('entity_id', array('in' => $crossSellIds));
     }
     $this->setData('items', $items);
     $this->_itemCollection = $items;
     return $items;
 }
Esempio n. 2
0
 /**
  * @param bool $execute
  * @return $this|array|null
  */
 public function getItems($execute = true)
 {
     if ($this->bxHelperData->isCrosssellEnabled()) {
         $config = $this->_scopeConfig->getValue('bxRecommendations/cart', $this->scopeStore);
         $products = array();
         foreach ($this->getQuote()->getAllItems() as $item) {
             $product = $item->getProduct();
             if ($product) {
                 $products[] = $product;
             }
         }
         $choiceId = isset($config['widget']) && $config['widget'] != "" ? $config['widget'] : 'basket';
         try {
             $entity_ids = $this->p13nHelper->getRecommendation($choiceId, $products, 'basket', $config['min'], $config['max'], $execute);
         } catch (\Exception $e) {
             $this->bxHelperData->setFallback(true);
             $this->_logger->critical($e);
             return parent::getItems();
         }
         if (!$execute) {
             return null;
         }
         if (count($entity_ids) == 0) {
             $entity_ids = array(0);
         }
         $items = $this->factory->create()->addFieldToFilter('entity_id', $entity_ids)->addAttributeToSelect('*');
         $items->load();
         foreach ($items as $product) {
             $product->setDoNotUseCategoryId(true);
         }
         return $items;
     }
     return parent::getItems();
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function getImage($product, $imageId, $attributes = array())
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getImage');
     if (!$pluginInfo) {
         return parent::getImage($product, $imageId, $attributes);
     } else {
         return $this->___callPlugins('getImage', func_get_args(), $pluginInfo);
     }
 }
 /**
  * Get the crossell items for the basket page
  *
  * @return array
  */
 public function getItems()
 {
     if (!$this->_config->isEnabled()) {
         return parent::getItems();
     }
     $personalisedIds = $this->_crosssell->getProductCollection();
     if (!$personalisedIds) {
         return parent::getItems();
     }
     $collection = $this->_crosssell->getPersonalisedProductCollection($personalisedIds);
     if ($this->_moduleManager->isEnabled('Magento_Checkout')) {
         $this->_addProductAttributesAndPrices($collection);
     }
     $items = [];
     foreach ($collection as $item) {
         $items[] = $item;
     }
     return $items;
 }
 /**
  * {@inheritdoc}
  */
 public function offsetGet($offset)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'offsetGet');
     if (!$pluginInfo) {
         return parent::offsetGet($offset);
     } else {
         return $this->___callPlugins('offsetGet', func_get_args(), $pluginInfo);
     }
 }