3

When using Magento's recurring profile if you add custom options to the product it brings through the custom options to the customers profile however it doesn't add them to the actual order.

app/code/core/Mage/Sales/Model/Recurring/Profile.php

In the function it adds the item info

public function createOrder()
  {
    $items = array();
    $itemInfoObjects = func_get_args();

    $billingAmount = 0;
    $shippingAmount = 0;
    $taxAmount = 0;
    $isVirtual = 1;
    $weight = 0;
    foreach ($itemInfoObjects as $itemInfo) {
        $item = $this->_getItem($itemInfo);
        $billingAmount += $item->getPrice();
        $shippingAmount += $item->getShippingAmount();
        $taxAmount += $item->getTaxAmount();
        $weight += $item->getWeight();
        if (!$item->getIsVirtual()) {
            $isVirtual = 0;
        }
        $items[] = $item;
    }

There is also this function that seems to get the custom options

protected function _addAdditionalOptionToItem($item, $option)
{
    $options = $item->getProductOptions();
    $additionalOptions = $item->getProductOptionByCode('additional_options');
    if (is_array($additionalOptions)) {
        $additionalOptions[] = $option;
    } else {
        $additionalOptions = array($option);
    }
    $options['additional_options'] = $additionalOptions;
    $item->setProductOptions($options);
}

Also this function in which I have already added one extra field.

    $transferDataKays = array(
        'store_id',             'store_name',           'customer_id',          'customer_email',
        'customer_firstname',   'customer_lastname',    'customer_middlename',  'customer_prefix',
        'customer_suffix',      'customer_taxvat',      'customer_gender',      'customer_is_guest',
        'customer_note_notify', 'customer_group_id',    'customer_note',        'shipping_method',
        'shipping_description', 'base_currency_code',   'global_currency_code', 'order_currency_code',
        'store_currency_code',  'base_to_global_rate',  'base_to_order_rate',   'store_to_base_rate',
        'store_to_order_rate',  'tm_field1'
    );

But I'm not sure what I need to add to the createOrder function so that the custom options come through on the order.

2

Came across the same situation and found this in another module. Hope it helps!

Override the following methods in Mage_Sales_Model_Recurring_Profile:

public function importQuoteItem(Mage_Sales_Model_Quote_Item_Abstract $item)
{
    $result = parent::importQuoteItem( $item );

    $orderItemInfo = $this->getOrderItemInfo();
    $orderItemInfo['options'] = serialize($item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct()));

    $this->setOrderItemInfo($orderItemInfo);

    return $result;
}


protected function _getRegularItem($itemInfo)
{
    $item = parent::_getRegularItem($itemInfo);

    $options = $this->getInfoValue('order_item_info', 'options');
    if (is_string($options)) {
        $options = unserialize($options);
    }

    $item->setProductOptions($options);

    return $item;
}

protected function _getInitialItem($itemInfo)
{
    $item = parent::_getInitialItem($itemInfo);

    $options = $this->getInfoValue('order_item_info', 'options');
    if (is_string($options)) {
        $options = unserialize($options);
    }

    $item->setProductOptions($options);

    $option = array(
        'label' => Mage::helper('sales')->__('Payment type'),
        'value' => Mage::helper('sales')->__('Initial period payment')
    );

    $this->_addAdditionalOptionToItem($item, $option);

    return $item;
}
3
  • that seems to strip out a lot of code, when I try overriding the methods as you say I just get a white screen unfortunately May 14 '15 at 18:01
  • The methods above are what you need in an override model; the code above is not the entire class.
    – Laura
    May 14 '15 at 18:15
  • How are you overriding the class? Are you doing a standard Magento model override?
    – Laura
    May 14 '15 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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