0

I am new to Magento. I am facing problem while using Customweb subscription extension. so there is an error in file causing by this extension. what I want to know is, what is this code doing?

$quote = Mage::getSingleton('checkout/cart')->getQuote();
...
$subscriptionPlan = Mage::getModel('customweb_subscription/cartPlan')->loadByIndex($index);
...
$quote->setSubscriptionPlan($subscriptionPlan)->collectTotals()->save();

I am trying to search "setSubscriptionPlan" in every files in the Customweb Subscription folder, but can't find this method defined. What exactly this method do, and where can I find this method in a file?

Thanks in advance.

EDIT: add complete code.

class Customweb_Subscription_IndexController extends Customweb_Subscription_Controller_Abstract {

    /**
     * Apply subscription plan to cart
     */
    public function applyPlanAction(){
        $quote = Mage::getSingleton('checkout/cart')->getQuote();

        /**
         * No reason continue with empty shopping cart
         */
        if (!$quote->getItemsCount()) {
            $this->_redirect('checkout/cart');
            return;
        }

        $index = $this->getRequest()->getParam('subscription_plan');
        if ($index != '') {
            $subscriptionPlan = Mage::getModel('customweb_subscription/cartPlan')->loadByIndex($index);
        }
        else {
            $subscriptionPlan = null;
        }

        $oldSubscriptionPlan = $quote->getSubscriptionPlan();

        if ($subscriptionPlan == null && $oldSubscriptionPlan == null) {
            $this->_redirect('checkout/cart');
            return;
        }

        try {
            $quote->setSubscriptionPlan($subscriptionPlan)->collectTotals()->save();

            if ($subscriptionPlan != null) {
                Mage::getSingleton('checkout/session')->addSuccess(
                        $this->__('You subscribed to the plan <em>%s</em>.', Mage::helper('core')->htmlEscape($subscriptionPlan->getDescription())));
            }
            else {
                Mage::getSingleton('checkout/session')->addSuccess($this->__('The subscription plan was removed.'));
            }
        }
        catch (Mage_Core_Exception $e) {
            Mage::getSingleton('checkout/session')->addError($e->getMessage());
        }
        catch (Exception $e) {
            Mage::getSingleton('checkout/session')->addError($this->__('Cannot apply the subscription plan.'));
            Mage::logException($e);
        }

        $this->_redirect('checkout/cart');
    }
}

1 Answer 1

1
$quote = Mage::getSingleton('checkout/cart')->getQuote();

Gets the quote from the current user

$subscriptionPlan = Mage::getModel('customweb_subscription/cartPlan')->loadByIndex($index);

I have no clue what index is, but it loads some kind of cartPlan (whatever this is), based on an index.

$quote->setSubscriptionPlan($subscriptionPlan)->collectTotals()->save();

I would say, this applies the loaded plan on the quote, then it collectTotals which means it calculate all prices, taxes, shipping, etc. and saves the quote

4
  • thank you for the answer. i got the following error Recoverable Error: Object of class Customweb_Subscription_Model_CartPlan could not be converted to string. therefor I want to know what setSubscriptionPlan. I tried to pass serialized data to setSubscriptionPlan but it throw error as well, different error though. Commented Jun 7, 2015 at 15:04
  • setSubscriptionplan is a standard setter in Magento check \Varien_Object::__call for more infos. Nowhere in your code is a conversion to string, so either you post your complete code or we can't help Commented Jun 7, 2015 at 15:17
  • 1
    There can be a conversion to string. In fact, it's very likely. \Mage_Core_Model_Resource_Abstract::_prepareTableValueForSave only has provisions for numeric types. Since we know it goes via the magic setter and is passed an object, it should be marked serializable or implemented in the resource model to handle the link.
    – user4351
    Commented Jun 7, 2015 at 16:23
  • @FabianBlechschmidt: I updated the question with complete code. thanks Commented Jun 8, 2015 at 1:57

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.