2

Magento提供的解决方案如何将新产品块中显示的产品数量限制在主页上显示的随机产品块中?

我目前有代码

<reference name="random">
<block type="catalog/product_list_random" name="product_random" template="catalog/product/grid_only.phtml">
 <action method="setProductsCount"><count>3</count></action>
 </block>
    </reference>

在我的布局更新 XML。网格产品视图默认值似乎主导了该值,该值在后端系统 > 配置 > 目录 > 目录 > 前端 > “网格默认值上的每页产品”中设置。

4

4 回答 4

3

看一看 @

也尝试改变

 <action method="setProductsCount"><count>3</count></action>

 <action method="setData"><key>num_products</key><value>[# to display]</value></action>

或者

 <action method="setNumProducts"><num_products>[# to display]</num_products></action>

见/app/code/core/Mage/Catalog/Block/Product/List/Random.php

 $numProducts = $this->getNumProducts() ? $this->getNumProducts() : 0;

您也可以尝试将此添加到您的 cms 页面

{{block type="catalog/product_list_random" category_id="YOUR_CATEGORY_ID" template="catalog/product/list.phtml" column_count="4" num_products="12"}}
于 2013-05-05T15:11:37.913 回答
1

在您的 grid_only.phtml 文件中,您应该编写以下代码来获取随机产品,这里限制您可以随意传递,这里我给出了类别明智的随机产品代码。

$categoryid = 15;
$category = new Mage_Catalog_Model_Category();
$category->load($categoryid);
$products = $category->getProductCollection();
$products->addAttributeToSelect('*');
$products->getSelect()->order('RAND()');
$products->getSelect()->limit(4);
foreach($products as $prod)
{
  echo $prod->getName() ."<br>";
  $img=$prod->getSmallImageUrl();
  echo "<img src='$img'>" ."<br>";
}
于 2013-05-06T06:45:52.187 回答
0

You can get latest products in magento with the following code:

<?php
$products = Mage::getModel('catalog/product')->getCollection();
//Magento does not load all attributes by default
//Add as many as you like
$products->addAttributeToSelect('name');
$products->setOrder('created_at', 'desc');
$products->getSelect()->limit(22);
foreach($products as $product) {

echo '<a href="'.$product->getProductUrl().'">'.$product->name.'</a> - ';     
}

Taken from here

于 2013-10-26T07:35:45.633 回答
0

请参阅这些链接http://blog.magikcommerce.com/random-products-magento-home-page/

希望这会帮助你。

于 2013-08-22T05:04:09.613 回答