コード例 #1
0
 public function testGetIdentities()
 {
     $productTag = array('compare_item_1');
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', array(), array(), '', false);
     $product->expects($this->once())->method('getIdentities')->will($this->returnValue($productTag));
     $itemsCollection = new \ReflectionProperty('Magento\\Catalog\\Block\\Product\\ProductList\\Related', '_itemCollection');
     $itemsCollection->setAccessible(true);
     $itemsCollection->setValue($this->block, array($product));
     $this->assertEquals($productTag, $this->block->getIdentities());
 }
コード例 #2
0
 /**
  * @dataProvider canItemsAddToCartDataProvider
  * @param bool $isComposite
  * @param bool $isSaleable
  * @param bool $hasRequiredOptions
  * @param bool $canItemsAddToCart
  */
 public function testCanItemsAddToCart($isComposite, $isSaleable, $hasRequiredOptions, $canItemsAddToCart)
 {
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', ['isComposite', 'isSaleable', 'getRequiredOptions'], [], '', false);
     $product->expects($this->any())->method('isComposite')->willReturn($isComposite);
     $product->expects($this->any())->method('isSaleable')->willReturn($isSaleable);
     $product->expects($this->any())->method('getRequiredOptions')->willReturn($hasRequiredOptions);
     $itemsCollection = new \ReflectionProperty('Magento\\Catalog\\Block\\Product\\ProductList\\Related', '_itemCollection');
     $itemsCollection->setAccessible(true);
     $itemsCollection->setValue($this->block, [$product]);
     $this->assertEquals($canItemsAddToCart, $this->block->canItemsAddToCart());
 }
コード例 #3
0
ファイル: Related.php プロジェクト: boxalino/plugin-magento2
 /**
  * @return $this
  */
 protected function _prepareData($execute = true)
 {
     if ($this->bxHelperData->isRelatedEnabled()) {
         $products = $this->_coreRegistry->registry('product');
         $config = $this->_scopeConfig->getValue('bxRecommendations/related', $this->scopeStore);
         $choiceId = isset($config['widget']) && $config['widget'] != "" ? $config['widget'] : 'similar';
         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('*');
         if ($this->moduleManager->isEnabled('Magento_Checkout')) {
             $this->_addProductAttributesAndPrices($this->_itemCollection);
         }
         $this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds());
         $this->_itemCollection->load();
         foreach ($this->_itemCollection as $product) {
             $product->setDoNotUseCategoryId(true);
         }
         return $this;
     }
     return parent::_prepareData();
 }
コード例 #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
 /**
  * {@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);
     }
 }