0

We have a product that is setup with a price of $0.00. When the product is added to the cart, programatically, we set the price according to a fee schedule that we have setup in an off line table.

Now, the product has been setup in it's own category and I have setup a coupon to discount it 100%. The coupon also discount another product from another category 100% so the entire cart must be discounted 100% when the 2 products are in the cart.

Now, because we are setting the price when we add the product to the cart, the discount is not being applied to the price set in the cart but to the ORIGINAL price of the item, $0.00.

How can I make this coupon work?

Here are the particulars:

Conditions:

Apply the rule only if the following conditions are met (leave blank for all products)
    If ANY  of these conditions are TRUE :
        If an item is FOUND  in the cart with ANY  of these conditions true: 
            Category  is  9  
        If an item is FOUND  in the cart with ANY  of these conditions true: 
            Category  is  30  

Actions:

Update prices using the following information
    Apply: Percent of product price discount
    Discount amount: 100
    Maximum Qty Discount is Applied to:0
    Discount Qty Step (Buy X): 0
    Apply to Shipping Amount: No
    Free shipping: No
    Stop further rules processing: No

Apply the rule only to cart items matching the following conditions (leave blank for all items)
    If ANY  of these conditions are TRUE :
        Category  is  9  
        Category  is  30  

EDITED...

ADDED CODE

// Get the product_id from product from SKU
$product_id = Mage::getModel("catalog/product")->getIdBySku("$sku");

// Load the product object by obtained productID 
$product = Mage::getModel("catalog/product")->load($product_id);

// get the current cart  
$session = Mage::getSingleton('core/session', array('name' => 'frontend'));
$cart = Mage::helper('checkout/cart')->getCart();

// if price is set, the use the passed price otehrwise use product's price
if(isset($_GET['price'])) {
    $price = $_GET['price'];
} else {
    $price = $product->getPrice();
}

// set params for product to be added to cart.
$params = array(
    'product' => $product_id,
    'qty'     => $qty, // $qty is also passed in the $_GET
    'price'   => $price
);

/*
    I have code here that loads a custom option with JSON data about the user, then sets the option like this:
    $params['options'] = array($option_id => json_encode($item_json));
*/  

// Now add the product to the cart.
$cart->addProduct($product, $params);
$session->setLastAddedProductId($product_id);
$session->setCartWasUpdated(true);
$cart->save();
  • Try Maximum Qty Discount is Applied to:0 setting to more than 0 value. – Adarsh Khatri Aug 11 '15 at 23:31
  • But I don't know before-hand what the cost of the category 30 product is going to be. – MB34 Aug 12 '15 at 15:01
  • The code that updates the prices is probably using a hook that is called after the discounts have already been calculated. Have you tried using a different hook, or can you tell us the one you are using? – Dylan Orr Aug 12 '15 at 22:03
  • Different hook? I'm not programatically applying the discount, it is using the BUILT-IN functionality when you click the Apply Promotion Code button. – MB34 Aug 12 '15 at 22:10
  • This means how many qty you are applying to? At the moment your coupon is applied to 0 qty I believe, which is why it is not working. – Adarsh Khatri Aug 13 '15 at 0:41
0

Instead of using the shopping cart rules, I would extend Mage_Checkout_CartController to check for the presence of the coupon code and then perform logic to check if the associated product sku is also in the cart.

If the product exists, you can get the value (and quantity) of it from the cart and then discount it, or as you are discounting it 100% simply set it's value to zero. You can then also notify the customer of the action taken.

You would need the quantity to ensure you only discount it once, unless you are giving more than one away with the coupon. This is in principle very similar to a Coupon X Get Y free module I have developed.

0

you need to create a small extension for event handle for this task as below,in your config.xml.

   <frontend>
   <events>
        <controller_action_predispatch_checkout_cart_couponPost>
            <observers>  
                <package_extensionname>
                    <type>singleton</type>  
                    <class>package_extensionname_Model_observer</class>    
                    <method>addProduct</method>            
                </package_extensionname>              
            </observers> 
</events>
 </frontend>

create a observer for adding product with "addProduct" method and place there or code.

Let me know if you have any query

Thanks

  • Sorry, we already have the way to add the product to the cart and we are not changing it. – MB34 Aug 17 '15 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.