Magento 帮助 ->难以过滤新产品

发布于 2024-08-16 23:58:57 字数 993 浏览 4 评论 0原文

我有点进退两难。以下代码正确显示分配的产品,同时忽略最低定价。 “低至”选项。

<?php 

$cat_id = 123; // category id
$category = Mage::getModel('catalog/category')->load($cat_id);

$todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);        

$_products = $category->
getProductCollection()->
addCategoryFilter($category)->
addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate))->
addAttributeToFilter('news_to_date', array('or'=> array(
        0 => array('date' => true, 'from' => $todayDate),
        1 => array('is' => new Zend_Db_Expr('null')))
), 'left')->            
addAttributeToSelect('*');

if (($this->getProductCollection()) && $_products->getSize()): ?>

对最后一行进行小幅调整,正确显示“低至”价格,但最终会在该类别中添加未分配的产品。

if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>

我缺少什么?谢谢

I'm having a little dilemma. The following code correctly displays the assigned products while ignoring the minimal pricing. The "as low as" option.

<?php 

$cat_id = 123; // category id
$category = Mage::getModel('catalog/category')->load($cat_id);

$todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);        

$_products = $category->
getProductCollection()->
addCategoryFilter($category)->
addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate))->
addAttributeToFilter('news_to_date', array('or'=> array(
        0 => array('date' => true, 'from' => $todayDate),
        1 => array('is' => new Zend_Db_Expr('null')))
), 'left')->            
addAttributeToSelect('*');

if (($this->getProductCollection()) && $_products->getSize()): ?>

Minor adjustment of last line, correctly shows the "as low as" price, but ends up adding un-assigned products within said category.

if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>

What am I missing? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柒七 2024-08-23 23:58:57

这是适合任何感兴趣的人的解决方案。

<?php 

if (($_products = $this->getProductCollection()) && $_products->getSize()):

$cat_id = 123; // category id
$category = Mage::getModel('catalog/category')->load($cat_id);

$todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);         

$_products = $this
->getProductCollection()
->addCategoryFilter($category)
->addAttributeToSelect('*')
->addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate))
->addAttributeToFilter('news_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $todayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left');
?>

我有兴趣在同一文件中使用另一个类别 ID 重复此过程。清理初始产品集合的最佳方法是什么?

Here's the solution that worked for anyone interested.

<?php 

if (($_products = $this->getProductCollection()) && $_products->getSize()):

$cat_id = 123; // category id
$category = Mage::getModel('catalog/category')->load($cat_id);

$todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);         

$_products = $this
->getProductCollection()
->addCategoryFilter($category)
->addAttributeToSelect('*')
->addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate))
->addAttributeToFilter('news_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $todayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left');
?>

I am interested repeating this procedure within same file with another category id. What's the best way clearing the initial product collection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文