I am trying to implement the card only payment option for specific products (configurable products) in this magento (1.9.1) store. The problem i am having with the code that i am using is that i need to go to each simple product and update the attribute value to take effect. What I would like to know if i can make changes to the code so instead of using the value of the simple product can the value of the parent product be used, regardless of what value the simple product is using. So i would just have to update the configurable product to say if this product is Card Only.
My Observer.php for this module
<?php
class JMAWD_CardOnly_Model_Observer
{
public function cardOnly(Varien_Event_Observer $observer)
{
$event = $observer->getEvent();
$method = $event->getMethodInstance();
$result = $event->getResult();
$cardonly = false;
foreach (Mage::getSingleton('checkout/cart')->getQuote()->getAllVisibleItems() as $item)
{
if($item->getProduct()->getCardOnly()){
$cardonly = true;
}
}
if($method->getCode() == "cashondelivery" && $cardonly){
$result->isAvailable = false;
}
}
}
My config.xml for this module
<?xml version="1.0"?>
<config>
<modules>
<JMAWD_CardOnly>
<version>0.1.0</version>
</JMAWD_CardOnly>
</modules>
<global>
<events>
<payment_method_is_active>
<observers>
<card_only>
<type>singleton</type>
<class>cardonly/observer</class>
<method>cardOnly</method>
</card_only>
</observers>
</payment_method_is_active>
</events>
<models>
<cardonly>
<class>JMAWD_CardOnly_Model</class>
<resourceModel>cardonly_mysql4</resourceModel>
</cardonly>
</models>
<sales>
<quote>
<item>
<product_attributes>
<card_only/>
</product_attributes>
</item>
</quote>
</sales>
</global>
</config>
Help & advice appreciated. Thanks