What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

We are building a B2B shop. For our warehousetool we have to create a XML file when an order is pla

UM64TJS69
UM64TJS69 Posts: 9 🧑🏻‍🚀 - Cadet
edited December 2019 in Help

We are building a B2B shop.

For our warehousetool we have to create a XML file when an order is placed. That works well.

Now I have to replace the billing address from the $orderEntity with the address from the company business unit. How can I achieve that? How to get the address of the company businesst unit from the orderEntity?

Any help is appreciated and code examples would be awesome.

Comments

  • Unknown
    edited December 2019

    You should add an order-saver plugin (in the checkout module) that persists the relevant business unit information with the sales order. Have a look at \Pyz\Zed\Checkout\CheckoutDependencyProvider it contains a lot of plugins already.

  • UM64TJS69
    UM64TJS69 Posts: 9 🧑🏻‍🚀 - Cadet

    I already create the XML with an OMS Plugin.

    But I don't know how to get the company business unit address from the orderEntity there.

    I have the companyId and the customerReference to get the company business unit.

    I tried

    $customer = CustomerReader::findCustomerByReference($orderEntity->getCustomerReference());
                    $companyBusinessUnitAddress = $customer->getCustomerTransfer()->getCompanyUserTransfer()->getCompanyBusinessUnit()->getAddressCollection()[0];
                    if($companyBusinessUnitAddress){
                        $billingAddress = $companyBusinessUnitAddress;
                    }
    

    with no luck getting the address.

  • Unknown
    edited December 2019

    I would not suggest relying on the data still being available in the regular database tables. Everything sales order related should be stored (as a copy) with the sales order. If you need address information of a business unit during order export I would suggest to persist the address in a dedicated tabele (e.g. pyz_sales_order_business_unit_address )

  • UM64TJS69
    UM64TJS69 Posts: 9 🧑🏻‍🚀 - Cadet

    There is no easy and quick way to get the address of the business unit from the orderEntity?

  • Why would there? As fas as I know Spryker discourages accessing data outside the scope of a sales order. A business unit address might change during the transition of a sales order through the state machine. A sales order should always be a snapshop at the time the order was placed. It could cause a lot of confusion for customers if things change after a sales order has been placed.

  • UM64TJS69
    UM64TJS69 Posts: 9 🧑🏻‍🚀 - Cadet

    The XML file is the snapshot of the order at this moment. Even if the address is changed, the XML file doesn't.

  • I see ... 🤔 . This would rule out an order hydrater since that would be executed every time you obtain a sales order. I guess there's no way around a custom query to get to that information