gpt4 book ai didi

Magento 自定义 block

转载 作者:行者123 更新时间:2023-12-04 10:05:51 24 4
gpt4 key购买 nike

我正在尝试在主页上使用 ajax 在 magento 中使用 ajax 显示流行的产品列表,我可以为 5 或“N”个产品执行此操作,但我想要的是将分页工具栏与结果集一起添加.

这是我添加的以显示流行产品的内容,

// Magento layout
$magento_block = Mage::getSingleton('core/layout');
$productsHtml = $magento_block->createBlock('catalog/product');
$productsHtml->setTemplate('catalog/product/popular.phtml');
echo $productsHtml ->toHTML();

在popular.phtml下
<?php   

$_productCollection = Mage::getModel('catalog/product')->getCollection()
->addPriceData()
->addAttributeToSort('ordered_qty', 'DESC')
->addAttributeToSort('name', 'ASC')
->setPageSize($limit)
->setPage($p, $limit)
->addAttributeToSelect(array('entity_id', 'entity_type_id', 'attribute_set_id', 'type_id', 'sku', 'category_ids', 'created_at', 'updated_at','has_options', 'sync', 'name', 'stock_status', 'wc_review_iwc_rating', 'wc_review_wa_rating', 'wc_review_bh_rating', 'small_image', 'status', 'pre_arrival', 'description', 'short_description', 'price', 'is_salable', 'stock_item', 'gift_message_available', 'featured'));

?>

所以这给了我指定页面和限制的热门产品,但我无法加载分页工具栏(直接将工具栏添加到 流行.phtml 或通过创建块布局功能),哪里错了?谁能告诉我。

谢谢

最佳答案

尝试创建一个 Mage_Catalog_Block_Product_List 块并自己设置热门产品的集合。

$collection = Mage::getModel('catalog/product')->addAttributeToFilter('your popular products');
// do not load the collection yet, otherwise the toolbar will not work

$listBlock = Mage::getSingleton('core/layout')->createBlock('catalog/product_list');
$listBlock->setCollection($collection)->setTemplate('your/alternative/catalog/product/list.phtml');

产品列表块总是初始化工具栏块本身。
您可以使用 getToolbarHtml() ?> 在模板中显示工具栏

编辑:
这是 Magento 1.4.1.1 中示例前端操作的工作示例:
public function productListAction()
{

$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*');

Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

$this->loadLayout();

$listBlock = $this->getLayout()->createBlock('catalog/product_list')
->setTemplate('catalog/product/list.phtml')
->setCollection($collection);

$this->getLayout()->getBlock('content')->append($listBlock);

$this->renderLayout();
}

我希望这能让它更清楚。

关于Magento 自定义 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4008119/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com