Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何修改畅销书块以显示特定类别的产品?_Php_Magento - Fatal编程技术网

Php 如何修改畅销书块以显示特定类别的产品?

Php 如何修改畅销书块以显示特定类别的产品?,php,magento,Php,Magento,我是Magento 1.9.0.1的新手,并且安装了第三方主题。它在主页上有4套滑块,每个滑块显示不同的产品列表,如畅销书、浏览量最大的产品等等 我试图用一个特定类别的产品列表来代替其中的一个(畅销书)。根据主题作者的说法,这可以通过以下块文件完成: <?php class Magentothem_Bestsellerproductslider_Block_Bestsellerproductslider extends Mage_Catalog_Block_Product_Abstract

我是Magento 1.9.0.1的新手,并且安装了第三方主题。它在主页上有4套滑块,每个滑块显示不同的产品列表,如畅销书、浏览量最大的产品等等

我试图用一个特定类别的产品列表来代替其中的一个(畅销书)。根据主题作者的说法,这可以通过以下块文件完成:

<?php
class Magentothem_Bestsellerproductslider_Block_Bestsellerproductslider extends Mage_Catalog_Block_Product_Abstract
{
public function _prepareLayout()
{
    return parent::_prepareLayout();
}

protected function useFlatCatalogProduct()
{
    return Mage::getStoreConfig('catalog/frontend/flat_catalog_product');
}

public function getBestsellerproductslider()     
{ 
    if (!$this->hasData('bestsellerproductslider')) {
        $this->setData('bestsellerproductslider', Mage::registry('bestsellerproductslider'));
    }
    return $this->getData('bestsellerproductslider');
}
public function getProducts()
{
    $collection = Mage::getResourceModel('bestsellerproductslider/product_bestseller')
                ->addOrderedQty()
                ;
    $collection = $this->_addProductAttributesAndPrices($collection)
                ->addMinimalPrice()
                ->setOrder('ordered_qty', 'desc');

    // getNumProduct
    $collection->setPageSize($this->getConfig('qty'));

    if($this->useFlatCatalogProduct())
    {
        // fix error mat image vs name while Enable useFlatCatalogProduct
        foreach ($collection as $product) 
        {
            $productId = $product->_data['entity_id'];
            $_product = Mage::getModel('catalog/product')->load($productId); //Product ID
            $product->_data['name']        = $_product->getName();
            $product->_data['thumbnail']   = $_product->getThumbnail();
            $product->_data['small_image'] = $_product->getSmallImage();
        }            
    }       

    $this->setProductCollection($collection);
}
public function getConfig($att) 
{
    $config = Mage::getStoreConfig('bestsellerproductslider');
    if (isset($config['bestsellerproductslider_config']) ) {
        $value = $config['bestsellerproductslider_config'][$att];
        return $value;
    } else {
        throw new Exception($att.' value not set');
    }
}

function cut_string_bestsellerproductslider($string,$number){ 
        if(strlen($string) <= $number) {
            return $string;
        }
        else {  
            if(strpos($string," ",$number) > $number){
                $new_space = strpos($string," ",$number);
                $new_string = substr($string,0,$new_space)."..";
                return $new_string;
            }
            $new_string = substr($string,0,$number)."..";
            return $new_string;
        }
}
}

此处getProducts()是为您设置产品集合的函数。您需要修改此函数以从特定类别获取数据。请查看下面的链接“如何从类别获取产品”。这里getProducts()是为您设置产品集合的函数。您需要修改此函数以从特定类别获取数据。请查看下面的链接“如何从类别获取产品”。