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


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)
            $cardonly = true;

    if($method->getCode() == "cashondelivery" && $cardonly){
        $result->isAvailable = false;


My config.xml for this module

<?xml version="1.0"?>

Help & advice appreciated. Thanks

1 Answer 1


You can test if the product type is "simple", and in this case, take the parent product, and check its cardonly attribute instead. The following should do the trick :

if($item->getProductType() == 'simple'){
    $parent = $item->getParentItem();
    $cardonly = $parent->getProduct()->getCardOnly();
} else {
    $cardonly = $item->getProduct()->getCardOnly();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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