Update order to add attribute

Hi,

I’m trying to update an order to add content to an attribute depending on user’s selection. It is working so far but the attribute value is saved in the ‘preorder’ row which I don’t know how to relate to the actual order row in the database:

Once the user clicks on the order now button it saves my value using the order id but this id it’s not the final one, so when the order is confirmed a new row is inserted but they have nothing in common. Maybe I’m subscribed to the wrong event? At the moment I’m using Enlight_Controller_Action_Frontend_Checkout_Finish but the order seems to be not created at this stage, any other idea on how can I add information to an order?

Thank you

Hey, there are some more events you can use. If you take a look into the engine/Shopware/Core/sOrder.php file, there is a method called sSaveOrder() which will be called when saving an order.

When the method is executed, there are some events dispatched which may be useful for your use-case. For example:

  • Shopware_Modules_Order_SaveOrder_FilterParams
  • Shopware_Modules_Order_SaveOrder_FilterAttributes
  • Shopware_Modules_Order_SaveOrder_FilterDetailAttributes
  • Shopware_Modules_Order_SaveOrder_ProcessDetails

They will be dispatched in order I’ve listed them.

 

Hi Jan,

Thank you for your answer, I’m going to try it :slight_smile:

I am going to create a plugin. This plugin will call external API once stock level updated (i.e. decrease qty). My plugin file consist following code. I can’t find var_dump or expected output not display. :

scheduleClearCache(ActivateContext::CACHE_LIST_DEFAULT);
    }
    public function deactivate(DeactivateContext $context)
    {
        $context->scheduleClearCache(DeactivateContext::CACHE_LIST_DEFAULT);
    }
    public function uninstall()
    {
        return true;
    }
    public function install()
    {
        # this event will be used after saving the order in the database
        return [
            'Shopware_Modules_Order_SaveOrder_ProcessDetails' => 'OnOrder_SaveOrderProcessDetails',
        ];
      
    }

    public function onOrder_SaveOrderProcessDetails(Enlight_Event_EventArgs $args)
	{
       // get SKU of Order items

       // Write here a qty you want to update on external 
       //CURL code will place here
	}
  
}

?>