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());
. 他のヒント
価格を取得するためのCollectionへの->addMinimalPrice()->addFinalPrice()
を追加します。
は、Mage_Catalog_Model_Layer
クラスを使用して製品コレクションを準備することです。(addAttributeToSelect
でワイルドカードを使用するのは対照的に)パフォーマンスを向上させ、一般的なカテゴリ製品リストで起こるのと同じ方法で、コレクションを準備します。
だから、あなたはこのようなことをするでしょう:
$products = Mage::getModel('catalog/layer')
->setCurrentCategory(469)
->getProductCollection();
.
私が知っている限り(今これをテストしていない)、それは自動的に特別価格を適用する必要があり、あなたが製品リストを作成する必要があるすべてのものをすべて適用するべきです。自分でやることはトラブルを求めています。
所属していません magento.stackexchange