Basket Attribut oder Order Attribut im Frontend in der checkout/confirm anzeigen

Ich versuche schon den ganzen Morgen ein Custom-Field (zuerst in der s_order_attributes, dann in der s_order_basket_attributes angelegt) auf der checkout/confirm einzubinden. Das letztendliche Ziel ist, dass auf der Confirm mehrere Eingabefelder (oder ähnliches) dem User präsentiert werden die dann letztendlich in der Order in Freitextfeldern gespeichert werden. 

Ich bekomme aber im Frontend unter sBasket keine Attribute angezeigt. Und wie kann ich dann die User-Eingabe per post mitsenden damit sie von confirmAction und finishAction verarbeitet werden? Ich habs nach dem Prinzip von Attribute system probiert aber dier checkout benutzt keinen FormBuilder und als Input-Name **attribute[attributeName] **hat auch nicht geklappt :confused:

Ich hatte in der Anfangszeit ein ähnliches Problem und habe dann das [form] der AGBs um Felder erweitert und anschließend über das Event „Shopware_Modules_Order_SaveOrder_FilterParams“ die POST-Parameter abgefangen und zumindest die sechs Standard-Attribute befüllt bekommen…

Ich bin wie folgt vorgegangen. Ich registriere mich direkt auf die confirmAction des Checkout Controllers per Enligh_Controller_Action_Frontend_Checkout_Confirm und manipulier das Order object ganz banal.

  public function onFrontendCheckoutConfirm(\Enlight_Event_EventArgs $args) {
        $controller = $args->getSubject();
        $order = Shopware()->Modules()->Order();
        if (!empty($order)) {
            $order->orderAttributes['my_test_field_a'] = 'hooray!';
            $order->orderAttributes['my_test_field_b'] = 'hooray!';
        }
    }

my_test_field_a wurde per Plugin als custom field in der s_orders_attributes registrierrt und my_test_field_b nicht. Auf den ersten Blick sieht es gut aus, ich hab in der Datenbank in der s_orders_attributes in my_test_field_a hooray stehen. Sollte auch mit der finishAction funktionieren.

Nachtrag: das ist nun meine “vorläufiger” Lösungsweg:

// erweitern von frontend/checkout/confirm.tpl

{extends file='parent:frontend/checkout/confirm.tpl'}
{block name="frontend_checkout_confirm_additional_free_text_display"}
    {$smarty.block.parent}

...

                        

...

{/block}

Auf Checkout::finishAction und dem normalen PostDispatchSecure von Checkout registrieren und die passenden Aktionen implementieren

    public static function getSubscribedEvents()
    {
        return [
            // ...
            'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout'
            => 'onPostDispatchFrontendCheckout',

            'Enlight_Controller_Action_Frontend_Checkout_Finish'
            => 'onFrontendCheckoutFinish',
            // ...
        ]
    }

    public function onFrontendCheckoutFinish(\Enlight_Event_EventArgs $args) {
        // handle custom fields in checkout confirmation
        $controller = $args->getSubject();
        $efData = $controller->Request()->getParam('myExampleField', '');
        $order = Shopware()->Modules()->Order();
        if (!empty($order)) {
            $order->orderAttributes['my_example_field'] = $efData ;
        }
    }

    public function onPostDispatchFrontendCheckout(\Enlight_Event_EventArgs $args) {
        $checkoutController = $args->getSubject();
        $view = $checkoutController->View();
               
        // ...

        // add user input from post back to checkout/confirm template
        // in case the users clicks finish button, but gets redirect back
        // to confirm due to missing stuff and so he doesnt need to retype 
        // the value back into the field
        $efData = ($checkoutController->Request()->getParam('myExampleField', ''));
        $view->assign('my_example_field', $efData);
    }

Und dann halt nurnoch ddas custom field auf s_orders installieren

public function install(InstallContext $context)
    {
        $service = $this->container->get('shopware_attribute.crud_service');
        $service->update(
            's_order_attributes',
            'my_example_field',
            TypeMapping::TYPE_STRING,
            [
                'displayInBackend' => true,
                'label' => 'Beispiel',
                'supportText' => 'Wird bei der Bestellung prominent ausgewiesen'
            ]
        );
    }

 

3 „Gefällt mir“

Nice! Thank you  Thumb-Up

1 „Gefällt mir“

Hallo,

dafür gibt es aber ansich auch ein Beispiel von Shopware selbst auf github, siehe: Advanced Example how to create 2 custom fields, fill them in order process, display them in backend order list as new columns and make them editable in order detail view · GitHub . Ist zwar noch auf dem alten Pluginsystem basierend, aber funktioniert ja trotzdem noch.

Grüße

Sebastian

1 „Gefällt mir“

Vielen dank für den Code!