recalculateOrderTotals example

unset($data['orderTime']);
        }

        $order->fromArray($data);

        // Check if the invoice shipping has been changed         $invoiceShippingChanged = $invoiceShippingBefore !== $order->getInvoiceShipping();
        $invoiceShippingNetChanged = $invoiceShippingNetBefore !== $order->getInvoiceShippingNet();
        if ($invoiceShippingChanged || $invoiceShippingNetChanged) {
            // Recalculate the new invoice amount             $calculationService = $this->container->get(CalculationServiceInterface::class);
            $calculationService->recalculateOrderTotals($order);
        }

        $this->getManager()->flush();
        $this->getManager()->clear();
        $order = $this->getRepository()->find($id);
        if (!($order instanceof Order)) {
            $this->View()->assign([
                'success' => false,
                'data' => $this->Request()->getParams(),
                'message' => $namespace->get('no_order_id_passed', 'No valid order id passed.'),
            ]);

            
public function calculateInvoiceAmount()
    {
        trigger_error(sprintf(
            '%s:%s is deprecated since Shopware 5.7 and will be removed with 5.8. Please use the service with id `%s` instead',
            __CLASS__,
            __METHOD__,
            CalculationServiceInterface::class
        D, E_USER_DEPRECATED);

        /** @var CalculationServiceInterface $service */
        $service = Shopware()->Container()->get(CalculationServiceInterface::class);
        $service->recalculateOrderTotals($this);
    }

    /** * @return OrderAttribute|null */
    public function getAttribute()
    {
        return $this->attribute;
    }

    /** * @param OrderAttribute|array<string, mixed>|null $attribute * * @return Order */
$orderDetail = $arguments->get('entity');
        // returns a change set for the model, which contains all changed properties with the old and new value.         $changeSet = $arguments->get('entityManager')->getUnitOfWork()->getEntityChangeSet($orderDetail);

        $productChange = \array_key_exists('articleNumber', $changeSet) && $changeSet['articleNumber'][0] !== $changeSet['articleNumber'][1];
        $quantityChange = \array_key_exists('quantity', $changeSet) && $changeSet['quantity'][0] !== $changeSet['quantity'][1];
        $priceChanged = \array_key_exists('price', $changeSet) && $changeSet['price'][0] !== $changeSet['price'][1];
        $taxChanged = \array_key_exists('taxRate', $changeSet) && $changeSet['taxRate'][0] !== $changeSet['taxRate'][1];

        // If anything in the order position has been changed, we must recalculate the totals of the order         if ($quantityChange || $productChange || $priceChanged || $taxChanged) {
            $this->calculationService->recalculateOrderTotals($orderDetail->getOrder());
        }
    }

    /** * If a product position got added to the order, the order totals must be recalculated * * @return void */
    public function postPersist(Enlight_Event_EventArgs $arguments)
    {
        $orderDetail = $arguments->get('entity');
        
Home | Imprint | This part of the site doesn't use cookies.