Skip to main content
replaced http://magento.stackexchange.com/ with https://magento.stackexchange.com/
Source Link

We implemented once a API which just creates a code and stores it with the order-item, so you know inside of the order, what code for which gift card.

So I recommend to implement an observer for order_item_save_before which checks for the product and whether there is NO id, if it is the case, than generate a new code and add it as product option, so it is automatically visible everywhere

You want to implement an observer, listening to sales_order_item_safe_before: Fatal error: Call to a member function getData() on a non-objectFatal error: Call to a member function getData() on a non-object

Then you want to check for the settings:

protected $_eventObject = 'item';

to know how the parameter is named.

Then you implement your observer:

public function salesOrderItemSafeBefore(Varien_Event_Observer $observer) {
$item = $observer->getItem();

    // checke whether product is of the type you want and item has no id
    if($item->isObjectNew() && $item->getProduct()->getSku() == 'whatever_the_sku_is') {
        // get one code or generate one and attach as option
        ->getProductOption()
        // add option
        ->setProductOption()
    }
}

We implemented once a API which just creates a code and stores it with the order-item, so you know inside of the order, what code for which gift card.

So I recommend to implement an observer for order_item_save_before which checks for the product and whether there is NO id, if it is the case, than generate a new code and add it as product option, so it is automatically visible everywhere

You want to implement an observer, listening to sales_order_item_safe_before: Fatal error: Call to a member function getData() on a non-object

Then you want to check for the settings:

protected $_eventObject = 'item';

to know how the parameter is named.

Then you implement your observer:

public function salesOrderItemSafeBefore(Varien_Event_Observer $observer) {
$item = $observer->getItem();

    // checke whether product is of the type you want and item has no id
    if($item->isObjectNew() && $item->getProduct()->getSku() == 'whatever_the_sku_is') {
        // get one code or generate one and attach as option
        ->getProductOption()
        // add option
        ->setProductOption()
    }
}

We implemented once a API which just creates a code and stores it with the order-item, so you know inside of the order, what code for which gift card.

So I recommend to implement an observer for order_item_save_before which checks for the product and whether there is NO id, if it is the case, than generate a new code and add it as product option, so it is automatically visible everywhere

You want to implement an observer, listening to sales_order_item_safe_before: Fatal error: Call to a member function getData() on a non-object

Then you want to check for the settings:

protected $_eventObject = 'item';

to know how the parameter is named.

Then you implement your observer:

public function salesOrderItemSafeBefore(Varien_Event_Observer $observer) {
$item = $observer->getItem();

    // checke whether product is of the type you want and item has no id
    if($item->isObjectNew() && $item->getProduct()->getSku() == 'whatever_the_sku_is') {
        // get one code or generate one and attach as option
        ->getProductOption()
        // add option
        ->setProductOption()
    }
}
added 766 characters in body
Source Link
Fabian Blechschmidt
  • 35.4k
  • 8
  • 75
  • 182

We implemented once a API which just creates a code and stores it with the order-item, so you know inside of the order, what code for which gift card.

So I recommend to implement an observer for order_item_save_before which checks for the product and whether there is NO id, if it is the case, than generate a new code and add it as product option, so it is automatically visible everywhere

You want to implement an observer, listening to sales_order_item_safe_before: Fatal error: Call to a member function getData() on a non-object

Then you want to check for the settings:

protected $_eventObject = 'item';

to know how the parameter is named.

Then you implement your observer:

public function salesOrderItemSafeBefore(Varien_Event_Observer $observer) {
$item = $observer->getItem();

    // checke whether product is of the type you want and item has no id
    if($item->isObjectNew() && $item->getProduct()->getSku() == 'whatever_the_sku_is') {
        // get one code or generate one and attach as option
        ->getProductOption()
        // add option
        ->setProductOption()
    }
}

We implemented once a API which just creates a code and stores it with the order-item, so you know inside of the order, what code for which gift card.

So I recommend to implement an observer for order_item_save_before which checks for the product and whether there is NO id, if it is the case, than generate a new code and add it as product option, so it is automatically visible everywhere

We implemented once a API which just creates a code and stores it with the order-item, so you know inside of the order, what code for which gift card.

So I recommend to implement an observer for order_item_save_before which checks for the product and whether there is NO id, if it is the case, than generate a new code and add it as product option, so it is automatically visible everywhere

You want to implement an observer, listening to sales_order_item_safe_before: Fatal error: Call to a member function getData() on a non-object

Then you want to check for the settings:

protected $_eventObject = 'item';

to know how the parameter is named.

Then you implement your observer:

public function salesOrderItemSafeBefore(Varien_Event_Observer $observer) {
$item = $observer->getItem();

    // checke whether product is of the type you want and item has no id
    if($item->isObjectNew() && $item->getProduct()->getSku() == 'whatever_the_sku_is') {
        // get one code or generate one and attach as option
        ->getProductOption()
        // add option
        ->setProductOption()
    }
}
Source Link
Fabian Blechschmidt
  • 35.4k
  • 8
  • 75
  • 182

We implemented once a API which just creates a code and stores it with the order-item, so you know inside of the order, what code for which gift card.

So I recommend to implement an observer for order_item_save_before which checks for the product and whether there is NO id, if it is the case, than generate a new code and add it as product option, so it is automatically visible everywhere