Magento产品系列少于原价
-
28-09-2020 - |
题
如何获得特殊价格少或不
<?php
$categoryIds = array(469);//category id
$todayDate = date('m/d/y');
$tomorrow = mktime(0, 0, 0, date('m'), date('d'), date('y'));
$tomorrowDate = date('m/d/y', $tomorrow);
$collection = Mage::getModel('catalog/product')
->getCollection()
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
->addMinimalPrice()->addFinalPrice()
->addAttributeToSelect('*')
->addAttributeToFilter('category_id', array('in' => $categoryIds))
->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
->addFinalPrice()
->getSelect()
->where('price_index.final_price < price_index.price')
->addAttributeToFilter('special_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $tomorrowDate))
), 'left')
?>
.
我想展示特价的特价低于原始价格如何获得?
解决方案
$categoryIds = array(469);//category id
$products = Mage::getResourceModel('catalog/product_collection')
->addCategoryFilter(Mage::getModel('catalog/category')->load($categoryIds));
$_productCollection = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('entity_id', array('in' => $products->getAllIds()));;
$_productCollection->addAttributeToSelect(array(
'image',
'name',
'short_description'
))
->addFieldToFilter('visibility', array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
))
->addFinalPrice()
->getSelect()
->where('price_index.final_price < price_index.price')
print_r($_productCollection->getAllIds());
. 其他提示
为获得价格添加->addMinimalPrice()->addFinalPrice()
。
要做的事情是使用Mage_Catalog_Model_Layer
类来准备您的产品集合。提高性能(而不是只使用addAttributeToSelect
中的通配符)并完全准备您的收藏,相同的方式发生在通用类别产品列表中。
所以,例如,你做这样的事情:
$products = Mage::getModel('catalog/layer')
->setCurrentCategory(469)
->getProductCollection();
.
据我所知(现在没有测试过这个),它应该自动应用您需要创建产品列表所需的特殊价格。自己这样做是要求麻烦。