I am trying to get a customfield in an order inside of the price->calculatedTaxes object which I added to the tax entity. I dont know what association I have to use to add the customfield to the object. The object is looking like this:
[price:protected] => Shopware\Core\Checkout\Cart\Price\Struct\CartPrice Object
(
[netPrice:protected] => 125.47
[totalPrice:protected] => 128.9
[calculatedTaxes:protected] => Shopware\Core\Checkout\Cart\Tax\Struct\CalculatedTaxCollection Object
(
[elements:protected] => Array
(
[0] => Shopware\Core\Checkout\Cart\Tax\Struct\CalculatedTax Object
(
[tax:protected] => 0
[taxRate:protected] => 0
[price:protected] => 107.41666666667
[extensions:protected] => Array
(
)
)
[19] => Shopware\Core\Checkout\Cart\Tax\Struct\CalculatedTax Object
(
[tax:protected] => 3.43
[taxRate:protected] => 19
[price:protected] => 21.483333333333
[extensions:protected] => Array
(
)
)
)
This is my criteria for the orderdata:
$criteria->addFilter(new EqualsFilter('id', $orderId))
->addAssociation('deliveries')
->addAssociation('addresses')
->addAssociation('addresses.country')
->addAssociation('deliveries.shippingOrderAddress.country')
->addAssociation('orderCustomer.salutation')
->addAssociation('transactions.paymentMethod')
->addAssociation('lineItems')
->addAssociation('currency');
Is this even possible or am I completely wrong and this needs to be done completely different to add the customfield to that element?
Thanks
Danny
The CalculatedTax
objects your are referring to are not at all direct descendants of the TaxEntity
you added your custom fields to. These objects are constructed during runtime through a series of calls where only at the very beginning of the stack an instance of TaxEntity
would be present.
There are quite a few levels in the stack between these two instances in fact. Without going into too much details, maybe have a look at the SalesChannelContextFactory
where a TaxRuleCollection
is stored in the current sales channel context. It has to happen this early on in the stack, since depending on the current user/customer different taxes may be applied, be it net/gross or different tax rates all together.
After all it depends on what you want to do with the data stored in the custom fields. If you need the data for altering the calculation of taxes you might want to store them early on with the creation of the sales channel context as an extension.