public function testAddInventoryData()
 {
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $this->event->expects($this->once())->method('getProduct')->will($this->returnValue($product));
     $this->stockHelper->expects($this->once())->method('assignStatusToProduct')->with($product)->will($this->returnSelf());
     $this->observer->execute($this->eventObserver);
 }
Esempio n. 2
0
 /**
  * Before prepare product collection handler
  *
  * @param \Magento\Catalog\Model\Layer $subject
  * @param \Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection $collection
  *
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function beforePrepareProductCollection(\Magento\Catalog\Model\Layer $subject, \Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection $collection)
 {
     if ($this->_isEnabledShowOutOfStock()) {
         return;
     }
     $this->stockHelper->addIsInStockFilterToCollection($collection);
 }
 /**
  * Add stock information to product
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     $product = $observer->getEvent()->getProduct();
     if ($product instanceof \Magento\Catalog\Model\Product) {
         $this->stockHelper->assignStatusToProduct($product);
     }
 }
Esempio n. 4
0
 /**
  * @dataProvider stockStatusDataProvider
  */
 public function testAfterGetProductCollectionShow($status, $callCount)
 {
     list($collectionMock, $subjectMock) = $this->buildMocks();
     $this->configMock->expects($this->once())->method('isShowOutOfStock')->will($this->returnValue($status));
     $this->stockHelperMock->expects($this->exactly($callCount))->method('addInStockFilterToCollection')->with($collectionMock);
     $this->assertEquals($collectionMock, $this->model->afterGetProductCollection($subjectMock, $collectionMock));
 }
 public function testAddStockStatusToCollection()
 {
     $productCollection = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection')->disableOriginalConstructor()->getMock();
     $this->event->expects($this->once())->method('getCollection')->will($this->returnValue($productCollection));
     $this->stockHelper->expects($this->once())->method('addStockStatusToProducts')->with($productCollection)->will($this->returnSelf());
     $this->observer->execute($this->eventObserver);
 }
Esempio n. 6
0
 /**
  * @param Link $subject
  * @param Collection $collection
  * @return Collection
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterGetProductCollection(Link $subject, Collection $collection)
 {
     if ($this->configuration->isShowOutOfStock() != 1) {
         $this->stockHelper->addInStockFilterToCollection($collection);
     }
     return $collection;
 }
Esempio n. 7
0
 /**
  *  Test add stock status to collection with 'display out of stock' option enabled
  */
 public function testAddStockStatusEnabledShow()
 {
     $this->_scopeConfigMock->expects($this->once())->method('isSetFlag')->with('cataloginventory/options/show_out_of_stock')->will($this->returnValue(false));
     $collectionMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', [], [], '', false);
     $this->_stockHelperMock->expects($this->once())->method('addIsInStockFilterToCollection')->with($collectionMock);
     $subjectMock = $this->getMock('\\Magento\\Catalog\\Model\\Layer', [], [], '', false);
     $this->_model->beforePrepareProductCollection($subjectMock, $collectionMock);
 }
Esempio n. 8
0
 public function testAddIsInStockFilterToCollection()
 {
     $collectionMock = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection')->disableOriginalConstructor()->getMock();
     $stockStatusMock = $this->getMockBuilder('Magento\\CatalogInventory\\Model\\ResourceModel\\Stock\\Status')->disableOriginalConstructor()->setMethods(['addStockDataToCollection'])->getMock();
     $stockStatusMock->expects($this->once())->method('addStockDataToCollection')->with($collectionMock);
     $this->statusFactoryMock->expects($this->once())->method('create')->willReturn($stockStatusMock);
     $this->assertNull($this->stock->addIsInStockFilterToCollection($collectionMock));
 }
Esempio n. 9
0
 /**
  * Get crosssell products collection
  *
  * @return \Magento\Catalog\Model\Resource\Product\Link\Product\Collection
  */
 protected function _getCollection()
 {
     /** @var \Magento\Catalog\Model\Resource\Product\Link\Product\Collection $collection */
     $collection = $this->_productLinkFactory->create()->useCrossSellLinks()->getProductCollection()->setStoreId($this->_storeManager->getStore()->getId())->addStoreFilter()->setPageSize($this->_maxItemCount)->setVisibility($this->_productVisibility->getVisibleInCatalogIds());
     $this->_addProductAttributesAndPrices($collection);
     $this->stockHelper->addInStockFilterToCollection($collection);
     return $collection;
 }
Esempio n. 10
0
 public function testGetProductCollection()
 {
     $this->stockHelperMock->expects($this->once())->method('addInStockFilterToCollection')->with($this->productCollection);
     $this->assertInstanceOf('Magento\\Catalog\\Model\\ResourceModel\\Product\\Link\\Product\\Collection', $this->model->getProductCollection());
 }
Esempio n. 11
0
 /**
  * Add stock status to prepare index select
  *
  * @param EventObserver $observer
  * @return void
  */
 public function addStockStatusToPrepareIndexSelect(EventObserver $observer)
 {
     $website = $observer->getEvent()->getWebsite();
     $select = $observer->getEvent()->getSelect();
     $this->stockHelper->addStockStatusToSelect($select, $website);
 }
Esempio n. 12
0
 /**
  * Retrieve linked product collection
  *
  * @return ProductCollection
  */
 public function getProductCollection()
 {
     $collection = $this->_productCollectionFactory->create()->setLinkModel($this);
     $this->stockHelper->addInStockFilterToCollection($collection);
     return $collection;
 }
 /**
  * Add information about product stock status to collection
  * Used in for product collection after load
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     $productCollection = $observer->getEvent()->getCollection();
     $this->stockHelper->addStockStatusToProducts($productCollection);
 }
 /**
  * @param Collection $productCollection
  * @param bool $printQuery
  * @param bool $logQuery
  * @return array
  */
 public function beforeLoad(Collection $productCollection, $printQuery = false, $logQuery = false)
 {
     $this->stockHelper->addIsInStockFilterToCollection($productCollection);
     return [$printQuery, $logQuery];
 }
 public function testAddStockStatusToCollection()
 {
     $productCollection = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection')->disableOriginalConstructor()->getMock();
     $this->stockHelper->expects($this->once())->method('addIsInStockFilterToCollection')->with($productCollection)->will($this->returnSelf());
     $this->plugin->beforeLoad($productCollection);
 }