Magento 1 Event: Before Create Subscription From Quote Item


Event Code: subscribepro_autoship_before_create_subscription_from_quote_item

Overview

The 'subscribepro_autoship_before_create_subscription_from_quote_item' event is dispatched just before the Subscribe Pro extension creates a new subscription from a quote item. This occurs when a subscription is being created from a successful checkout, just after the order is successfully placed.

Parameters

NameTypeDescription
subscriptionsubscribepro_Autoship_Model_SubscriptionThe subscription parameter holds a data structure which is a representation of the new subscription which will be created. The data in this object can be modified to change the details of the new subscription which is created on Subscribe Pro.
quote_itemMage_Sales_Model_Quote_ItemThe quote_item parameter holds a reference to the Magento quote item data structure from the just-placed quote / order. The quote_item holds the product details and the customer's "request" to create a subscription for the given product.

Example

config.xml

<config>
    <global>
        <events>
            <subscribepro_autoship_before_create_subscription_from_quote_item>
                <observers>
                    <my_module_subscribepro_autoship_before_create_subscription_from_quote_item>
                        <class>my_module/observer</class>
                        <method>onBeforeCreateSubscriptionFromQuoteItem</method>
                    </my_module_subscribepro_autoship_before_create_subscription_from_quote_item>
                </observers>
            </subscribepro_autoship_before_create_subscription_from_quote_item>
        </events>
    </global>
</config>

Observer.php

public function onBeforeCreateSubscriptionFromQuoteItem(Varien_Event_Observer $observer)
{
    // Get data from $observer
    /** @var SubscribePro_Autoship_Model_Subscription $subscription */
    $subscription = $observer->getData('subscription');
    /** @var Mage_Sales_Model_Quote_Item $quoteItem */
    $quoteItem = $observer->getData('quote_item');

    if ($quoteItem->getBaseRowTotal() > 10.0) {
        $subscription->setData('coupon_code', 'COUPON_OVER_10_DOLLARS');
    }
}