I have done some custom work where I put a message on top of the cart and let people know they can get 20% discount when they add 1 more item to their cart.
This is a coupon code, let's say number 145. I call that within a custom block inside a CMS page:
{{block type="core/template" name="applieddiscount" CheckCoupon="145" template="customphp/getCartCouponApplied.phtml"}}
Then, I Create local.xml in /app/design/frontend/[package]/[theme]/layout/local.xml
<checkout_cart_index>
<reference name="checkout.cart.form.before">
<block type="cms/block" name="promotion_banner_cart" after="checkout.cart.top_methods" >
<action method="setBlockId"><block_id>promotion_top_of_cart</block_id></action>
</block>
</reference>
</checkout_cart_index>
This is the phtml file inside the directory /app/design/frontend/[package]/default/template/customphp/getCartCouponApplied.phtml:
<?php
$appliedRuleIds = Mage::getSingleton('checkout/session')->getQuote()->getAppliedRuleIds();
$checkCoupon = $this->getCheckCoupon();
/*
This will give you the ids of the rules applied to the quote separated by comma. You can turn them into an array like this:
*/
$appliedRuleIds = explode(',', $appliedRuleIds);
if (in_array($checkCoupon, $appliedRuleIds)) {
$myMessage = $this->__('GREAT, YOUR DISCOUNT IS AUTOMATICALLY APPLIED. WE ARE SURE YOU WILL ENJOY YOUR PURCHASE!');
echo $this->getLayout()->createBlock('core/messages')->addSuccess($myMessage)->toHtml();
}else{
$myMessage = $this->__('ADD AT LEAST ONE OTHER ITEM TO YOUR CART AND RECEIVE 20% DISCOUNT ON ALL OF THEM!');
echo $this->getLayout()->createBlock('core/messages')->addNotice($myMessage)->toHtml();
}
?>
This all works, this was my intro. I'm trying to better my life and make this into an extension. I'm just about done, but now i realize I have to know a method to actually mimic/copy this to a working extension.
{{block type="core/template" name="applieddiscount" CheckCoupon="145" template="customphp/getCartCouponApplied.phtml"}}
What i have now is:
<?xml version="1.0" ?>
<config>
<modules>
<MyExt_ShowCartBenefits>
<version>1.0.0</version>
</MyExt_ShowCartBenefits>
</modules>
<global>
<models>
<MyExt_ShowCartBenefits>
<class>MyExt_ShowCartBenefits_Model</class>
</MyExt_ShowCartBenefits>
</models>
<events>
<checkout_cart_product_add_after>
<observers>
<MyExt_ShowCartBenefits_Model_Observer>
<type>singleton</type>
<class>MyExt_ShowCartBenefits_Model_Observer</class>
<method>catchAddToCart</method>
</MyExt_ShowCartBenefits_Model_Observer>
</observers>
</checkout_cart_product_add_after>
</events>
</global>
<frontend>
<layout>
<updates>
<MyExt_ShowCartBenefits>
<file>MyExt/MyExt_ShowCartBenefits.xml</file>
</MyExt_ShowCartBenefits>
</updates>
</layout>
</frontend>
</config>
The Observer.php (app\code\local\MyExt\ShowCartBenefits\model\Observer.php) is a copy of the same php file I called in here (customphp/getCartCouponApplied.phtml):
{{block type="core/template" name="couponadded" CheckCoupon="145" template="customphp/getCartCouponApplied.phtml"}}
What I would like to know is, how can I get the coupon code number that i used to call with the variable inside the CMS block i showed earlier?
I really need a hand to help me get forward.
What is confusing me is the part what I should use? Do I leave out the Observer.php, or is there a way to leave out the entire CMS block, but then how and/or when do I pass the variable(s) CheckCoupon="145"?
Am I overthinking this and just stick with my old method?
Thank you.