4
votes

Initial conditions:

  • Magento 1.7 installed (haven't tried with previous versions)
  • One (downloadable) product with multiple downloadable files, with prices added to the default product (let's say product that costs 50$ + 2 downloadable files, one free, the other an extra 50$ )
  • A new promotion (Catalog price rule) that applies to all products (let's say -20%)

More info about promotion:

Applies to all products, all groups, is active and applied, applies 'by percentage of original price', enable discount for subproducts -> Yes, stop further rule for processing -> No

Expected result:

Price for the product with the 50$ file: 80$ (80% from 100$)

Actual result:

Price for the product with the 50$ file: 90$ (80% from the initial 50$, and the full price for the downloadable file).

Conclusion:

The promotion doesn't apply to the extra prices that downloadable files have.

Question(s):

  • Is this the desired behavior for downloadable files? Or is this a bug ?
  • Any tips on how to modify the code (eventually create a module) to make it work as expected ? (Just tips, ie. what to extend)
2
ill post you the answer soon :)Meabed

2 Answers

1
votes

Links / downloadable files its not products entities ( so it doesn't have price_index table and it doesn't treated as products )

There is 2 Ways to apply promotion in products

  1. Catalog Price Rules

  2. Shopping Cart Price Rules

As your question stated that you used Catalog Price Rules I have solved your question using Catalog Price Rules.

Create Module and rewrite the Model

Mage_Downloadable_Model_Product_Type

======

<global>
    <models>
        <downloadable>
            <rewrite>
                <product_type>Web_Eproduct_Model_Downloadable_Product_Type</product_type>
            </rewrite>
        </downloadable>
    </models>
</global>

and the Code Below calculate the price of each Link on the fly ( even if you have more than one rule applied to the same product )

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;
    }
}

I have tested it and confirmed its working as you expect :)

Try it and let me know your thoughts :)

There is another way to achieve this if you will use Shopping Cart Price Rules i will post it later.

-1
votes

There are 2 types of price rules in Magento, Catalog and Shopping Cart Price Rules. Catalog Rules are enacted on products before they are added to the cart, while Shopping Cart Price Rules are applied in the shopping cart.

You should set this promo as a Shopping Cart Price Rule.