robertoroberto MemberComments: 39 Received thanks: 1 Member since: April 2017

Hi,

I have created a plugin for Shopware 5.5 that adds a free text field to my store. It saves on s_order_attributes a reference value for internal payment reference. The input is fillable from the frontend and visible from the backend. Now I'm trying to display this information on the sOrder email template, according to the right sample variables section it should appear when adding {$attributes.name_of_the_attribute} to the email template but it's not displaying anything and it shows null on this right side sample variables section (which makes sense as the value doesn't exist yet because no order has been placed)

On my plugin I got:

if (!$crudService->get("s_order_attributes", "name_of_the_attribute")) {
	$crudService->update("s_order_attributes", "name_of_the_attribute", "string", [
		"displayInBackend" => true,
		"label" => "Purchase reference number",
		"translatable" => true,
	]);
}

$this->rebuildAttributeModels();

I am subscribed to Shopware_Modules_Order_SaveOrder_ProcessDetails, Enlight_Controller_Action_PostDispatch_Frontend_Checkout and sAdmin::sUpdatePayment::after to manage plugin display on the store, do I need to do anything else to get this working on the email templates? Reading the documentation I can see they use Enlight_Controller_Action_PostDispatchSecure_Frontend on https://developers.shopware.com/developers-guide/attribute-system/

Thanks!

Answers

  • robertoroberto MemberComments: 39 Received thanks: 1 Member since: April 2017

    Finally got this working. In case someone get here here's how I did it.

    Kept the previous function that updates the attributes when an order is saved using  "Shopware_Modules_Order_SaveOrder_ProcessDetails" , the problem is that at that point the attributes are already fetched so you need to subscribe to the filter to pass the attriubute value, I have used  'Shopware_Modules_Order_SaveOrder_FilterAttributes'. In that function you need to retrieve the attributeData and attach your value. Once this is done you can return it.

    Hope this helps

  • KiruKiru MemberComments: 1 Received thanks: 0 Member since: September 10

    Hi Roberto, 

    I am tryign out the exact same thing and am unsuccessful so far. 

    For me the attributes are created in the backed but I do not get the value from the frontend at all int he database. 

    Could you please post a short code snippet of what worked for you?

    Thanks a lot in advance.

    Regards,

    Kiru

Sign In or Register to comment.