예제 #1
0
 public function testGetIdentities()
 {
     $productTag = ['compare_item_1'];
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $product->expects($this->once())->method('getIdentities')->will($this->returnValue($productTag));
     $itemsCollection = new \ReflectionProperty('Magento\\Catalog\\Block\\Product\\ProductList\\Upsell', '_items');
     $itemsCollection->setAccessible(true);
     $itemsCollection->setValue($this->block, [$product]);
     $this->assertEquals($productTag, $this->block->getIdentities());
 }
예제 #2
0
 /**
  * @return $this
  */
 protected function _prepareData($execute = true)
 {
     if ($this->bxHelperData->isUpsellEnabled()) {
         $products = $this->_coreRegistry->registry('product');
         $config = $this->_scopeConfig->getValue('bxRecommendations/upsell', $this->scopeStore);
         $choiceId = isset($config['widget']) && $config['widget'] != "" ? $config['widget'] : 'complementary';
         try {
             $entity_ids = $this->p13nHelper->getRecommendation($choiceId, $products, 'product', $config['min'], $config['max'], $execute);
         } catch (\Exception $e) {
             $this->bxHelperData->setFallback(true);
             $this->_logger->critical($e);
             return parent::_prepareData();
         }
         if (!$execute) {
             return null;
         }
         if (count($entity_ids) == 0) {
             $entity_ids = array(0);
         }
         $this->_itemCollection = $this->factory->create()->addFieldToFilter('entity_id', $entity_ids)->addAttributeToSelect('*');
         $this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
         $this->_itemCollection->load();
         foreach ($this->_itemCollection as $product) {
             $product->setDoNotUseCategoryId(true);
         }
         return $this;
     }
     return parent::_prepareData();
 }
예제 #3
0
 /**
  * Get crosssell items
  *
  * @return array
  */
 public function getItemCollection()
 {
     if (!$this->helper->isActiveEngine() || !$this->helper->isUpsellEnabled()) {
         return parent::getItemCollection();
     }
     $items = $this->_items;
     if (is_null($items)) {
         reset($this->_itemCollection);
         $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();
         $this->_itemCollection = $this->_getCollection()->addAttributeToFilter('entity_id', array('in' => $crossSellIds));
     }
     return $this->_itemCollection;
 }
예제 #4
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);
     }
 }
예제 #5
0
 /**
  * Rewrite parent _prepareData method to use PredictionIO results when available
  *
  * @return $this
  */
 protected function _prepareData()
 {
     if (!$this->_config->isEnabled()) {
         return parent::_prepareData();
     }
     $product = $this->_coreRegistry->registry('product');
     $categoryIds = $this->_upsell->getCategoryIds($product);
     $personalisedIds = $this->_upsell->getProductCollection([$product->getId()], $categoryIds);
     if (!$personalisedIds) {
         return parent::_prepareData();
     }
     $this->_isPredictedResults = true;
     $collection = $this->_upsell->getPersonalisedProductCollection($personalisedIds);
     $this->_itemCollection = $collection;
     if ($this->moduleManager->isEnabled('Magento_Checkout')) {
         $this->_addProductAttributesAndPrices($this->_itemCollection);
     }
     $this->_eventManager->dispatch('catalog_product_upsell', ['product' => $product, 'collection' => $this->_itemCollection, 'limit' => null]);
     foreach ($this->_itemCollection as $product) {
         $product->setDoNotUseCategoryId(true);
     }
     return $this;
 }
예제 #6
0
 /**
  * {@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);
     }
 }