문제

내가 필요한지 확인하려면 제품 카탈로그는 가격은 규칙이 있는 경우,필요한 전시는 특정 div.

그래서 나는 같은 뭔가가 필요:

<?php if catalog price rule : ?>
<div>
Text
</div>
<?php endif; ?>

는 방법을 달성할 수 있습니까?

도움이 되었습니까?

해결책

지 않는 경우가 많은 규칙 또는 여러 제품을 당신이 시도 할 수 있습니다:

$website = Mage::app()->getWebsite();
$product = $this->getProduct();
$rules = Mage::getModel('catalogrule/rule')->getCollection()
    ->addWebsiteFilter($website) //filter rules for current site
    ->addIsActiveFilter(1); //filter active rules

foreach ($rules as $rule) {
    $affectedProductIds = $rule->getMatchingProductIds();
    if (in_array($product->getId(), $affectedProductIds)) {
        //product has a price rule set for it
    }
}

빠르고 더러운 아이디어를 검색에 대한 테이블에 기록 catalogrule_product.
모든 제품에 의해 영향을 받는 카탈로그 규칙에서 참조되는 테이블.

$resource = Mage::getSingleton('core/resource');
$connection = $resource->getConnection('core_read');
$tableName = $resource->getTableName('catalogrule_product');
$count = $connection->fetchOne('SELECT COUNT(1) as c FROM '.$tableName.' WHERE product_id = '. $product->getId());

if ($count == 1) { 
    //you have a rule for the product
}

하지만 이것은 가장 좋습니다.

다른 팁

오래된 질문,하지만 다른 사람들에게는 효율적인 방법 인 것처럼 보입니다 :

$product = $this->getProduct();
Mage::getModel('catalogrule/rule')->loadProductRules($product);
var_dump($product->getMatchedRules());
.

mage_catalogrule_model_rule 참조를 참조하십시오.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top