【问题标题】:Display Out of Stock at the end of the product list and search result page在产品列表和搜索结果页面的末尾显示缺货
【发布时间】:2014-02-26 14:58:40
【问题描述】:

我已经在 SO 和其他论坛上尝试过这里提到的方法,但它不起作用。我正在使用 Magento 版本。 1.7.0.2,我想将所有缺货产品移到产品列表和搜索结果页面的末尾。

这是我尝试过的:

我将 Collection.php 从/app/code/core/Mage/Catalog/Model/Resource/Product/ 复制到/app/code/local/Mage/Catalog/Model/Resource/Product/ 并粘贴在 addAttributeToSort 函数开头的代码下方。

$this->getSelect()->joinLeft(array('_inventory_table' => $this->getTable('cataloginventory/stock_status')), '_inventory_table.product_id = e.entity_id', array('stock_status'));
$this->getSelect()->order('stock_status DESC');

但它不起作用,我更喜欢可以通过 magento 主题完成的选项,而不是编辑核心文件并将其复制到本地目录。我该怎么做?

【问题讨论】:

    标签: php magento magento-1.7 e-commerce


    【解决方案1】:

    我希望在 list.phtml 文件中实现更直接的方法,或者在相应的类文件中使用函数,例如 Yourpackage/Yourmodule/Block/Product/List.php。

    您可以使用此代码访问每个 $_product 的库存水平

      $cabac_stockObject = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product); 
      //get the stock levels
      $cabac_stockQuantityAvailable = (int)$cabac_stockObject->getQty() - (int)$cabac_stockObject->getMinimumQty(); //returns string! Like 10.000 or 0.0000 for 10 or 0 so cast to (int)  
      $cabac_stockStatus = (int)$cabac_stockObject->getIsInStock(); //returns string! Like 10.000 or 0.0000 for 10 or 0 so cast to (int)  
    

    然后可能会遍历集合,将产品对象和库存计数添加到数组中,按库存计数排序,然后将排序后的数组传递到您的 list.phtmlforeach 循环中。

    类似这样的东西(对于粗略的伪代码表示歉意)

       foreach ($_productCollection as $_product){
          $cabac_stockObject = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product); 
          //get the stock levels
          $cabac_stockQuantityAvailable = (int)$cabac_stockObject->getQty() - (int)$cabac_stockObject->getMinimumQty();
          $cabac_stockStatus = (int)$cabac_stockObject->getIsInStock(); 
    
        if($cabac_stockQuantityAvailable==0 || $cabac_stockStatus==0 ){
          $cabac_stockQuantityAvailable = 0;
        }
        //store the stock quantity and $_product in an array
    
      }
    
    //sort the array as you see fit
    //foreach ($sortedArray['products'] as $_product){
    
      //display the products
    
    //}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-30
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多