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();
.
내가 아는 한 (지금 이것을 테스트하지 않았습니다), 그것은 자동으로 특별 가격과 제품 목록을 만드는 데 필요한 모든 것을 자동으로 적용해야합니다.그것을 스스로하는 것은 문제를 묻고 있습니다.
제휴하지 않습니다 magento.stackexchange