Magento 自定义块
我正在尝试使用 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'));
?>
因此这给了我指定页面和限制的热门产品,但我无法加载分页工具栏(通过直接将工具栏添加到popular.phtml 或者通过创建块布局功能),哪里错了?有人可以告诉我吗?
谢谢
I am trying to show the popular product list using ajax in magento on the home page using ajax, I could do that for 5 or "N" no.of products, but what i want is the pagination toolbar to be added with the result set.
This is what i added to show the popular products,
// Magento layout
$magento_block = Mage::getSingleton('core/layout');
$productsHtml = $magento_block->createBlock('catalog/product');
$productsHtml->setTemplate('catalog/product/popular.phtml');
echo $productsHtml ->toHTML();
And under 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'));
?>
So this gives me the popular products of specified page and limit, but i could not load the pagination toolbar(by directly adding the toolbar to popular.phtml or through create block layout function), Where am wrong? Could anybody tell me please.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试创建一个 Mage_Catalog_Block_Product_List 块并自行设置热门产品的集合。
产品列表块始终初始化工具栏块本身。
您可以使用 getToolbarHtml() ?> 在模板中显示工具栏
编辑:
这是 Magento 1.4.1.1 中示例前端操作的工作示例:
我希望这能让它更清楚。
Try creating a Mage_Catalog_Block_Product_List block and setting the collection of the popular products yourself.
The product list block always initializes a toolbar block itself.
You can display the toolbar in the template by using <?php echo $this->getToolbarHtml() ?>
EDIT:
Here is a working example of a sample frontend action in Magento 1.4.1.1:
I hope that makes it clearer.
对于其他人参考,这是我根据 Vinai 的代码添加的内容。
它完美地呈现了分页工具栏。
For others reference this is what i added as per Vinai's code.
It renders the pagination toolbar perfectly.
我猜你应该从你的集合中初始化工具栏。您看过此页面吗?
You should initialize the toolbar from your collection I guess. Have you seen this page?