リンク/ダウンロード可能なファイルは製品エンティティではありません (したがって、 price_index テーブルがなく、製品として扱われません)
製品にプロモーションを適用するには 2 つの方法があります
カタログ価格ルール
ショッピングカートの価格ルール
あなたの質問はカタログ価格ルールを使用したと述べたので、私はカタログ価格ルールを使用してあなたの質問を解決しました.
モジュールを作成してモデルを書き換える
Mage_Downloadable_Model_Product_Type
======
<global>
<models>
<downloadable>
<rewrite>
<product_type>Web_Eproduct_Model_Downloadable_Product_Type</product_type>
</rewrite>
</downloadable>
</models>
</global>
以下のコードは、各リンクの価格をオンザフライで計算します (同じ製品に複数のルールが適用されている場合でも)。
class Namespace_Modulename_Model_Downloadable_Product_Type extends Mage_Downloadable_Model_Product_Type {
public function getLinks($product = null)
{
$product = $this->getProduct($product);
$wId = Mage::app()->getWebsite()->getId();
$gId = Mage::getSingleton('customer/session')->getCustomerGroupId();
$catalogRules = Mage::getSingleton('catalogrule/resource_rule')->getRulesFromProduct('',$wId,$gId,$product->getId());
/* @var Mage_Catalog_Model_Product $product */
if (is_null($product->getDownloadableLinks())) {
$_linkCollection = Mage::getModel('downloadable/link')->getCollection()
->addProductToFilter($product->getId())
->addTitleToResult($product->getStoreId())
->addPriceToResult($product->getStore()->getWebsiteId());
$linksCollectionById = array();
foreach ($_linkCollection as $link) {
/* @var Mage_Downloadable_Model_Link $link */
$link->setProduct($product);
$link->setPrice($this->calcLinkPrice($catalogRules,$link->getPrice()));
$linksCollectionById[$link->getId()] = $link;
}
$product->setDownloadableLinks($linksCollectionById);
}
return $product->getDownloadableLinks();
}
public function calcLinkPrice(array $rules = array(),$productPrice = 0 )
{
foreach($rules as $ruleData)
{
$productPrice = Mage::helper('catalogrule')->calcPriceRule(
$ruleData['action_operator'],
$ruleData['action_amount'],
$productPrice);
}
return $productPrice;
}
}
私はそれをテストし、期待どおりに動作することを確認しました:)
試してみて、あなたの考えを教えてください:)
ショッピング カートの価格ルールを使用する場合、これを実現する別の方法があります。後で投稿します。