Ejemplo n.º 1
0
 /**
  * Apply sort params to the collection.
  *
  * @param \Magento\Catalog\Model\Layer                                       $layer      Catalog / search layer.
  * @param \Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection $collection Product collection.
  *
  * @return $this
  */
 private function setSortParams(\Magento\Catalog\Model\Layer $layer, \Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection $collection)
 {
     $searchQuery = $this->queryFactory->get();
     if (!$searchQuery->getQueryText() && $layer->getCurrentCategory()) {
         $categoryId = $layer->getCurrentCategory()->getId();
         $collection->addSortFilterParameters('position', 'category.position', 'category', ['category.category_id' => $categoryId]);
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Add stock status information to products
  *
  * @param AbstractCollection $productCollection
  * @return void
  */
 public function addStockStatusToProducts(AbstractCollection $productCollection)
 {
     $websiteId = $this->storeManager->getStore($productCollection->getStoreId())->getWebsiteId();
     foreach ($productCollection as $product) {
         $productId = $product->getId();
         $stockStatus = $this->stockRegistryProvider->getStockStatus($productId, $websiteId);
         $status = $stockStatus->getStockStatus();
         $product->setIsSalable($status);
     }
 }
Ejemplo n.º 3
0
 /**
  * Set Order field
  *
  * @param string $attribute
  * @param string $dir
  * @return $this
  */
 public function setOrder($attribute, $dir = Select::SQL_DESC)
 {
     if ($attribute == 'price') {
         $this->addAttributeToSort($attribute, $dir);
     } else {
         parent::setOrder($attribute, $dir);
     }
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Load collection
  *
  * @param bool $printQuery
  * @param bool $logQuery
  * @return $this
  */
 public function load($printQuery = false, $logQuery = false)
 {
     if ($this->isLoaded()) {
         return $this;
     }
     if ($this->_loadWithProductCount) {
         $this->addAttributeToSelect('all_children');
         $this->addAttributeToSelect('is_anchor');
     }
     parent::load($printQuery, $logQuery);
     if ($this->_loadWithProductCount) {
         $this->_loadProductCount();
     }
     return $this;
 }