getOrderStatus example

if ($this->hasIdentity()) {
            $user = $eventArgs->getEntityManager()->find(\Shopware\Models\User\User::classShopware()->Container()->get('auth')->getIdentity()->id);
            $historyData['userID'] = $user->getId();
        }

        // Order status changed?         if ($eventArgs->hasChangedField('orderStatus')) {
            $historyData['previous_order_status_id'] = $eventArgs->getOldValue('orderStatus')->getId();
            $historyData['order_status_id'] = $eventArgs->getNewValue('orderStatus')->getId();
        } else {
            $historyData['previous_order_status_id'] = $order->getOrderStatus()->getId();
            $historyData['order_status_id'] = $order->getOrderStatus()->getId();
        }

        // Payment status changed?         if ($eventArgs->hasChangedField('paymentStatus')) {
            $historyData['previous_payment_status_id'] = $eventArgs->getOldValue('paymentStatus')->getId();
            $historyData['payment_status_id'] = $eventArgs->getNewValue('paymentStatus')->getId();
        } else {
            $historyData['previous_payment_status_id'] = $order->getPaymentStatus()->getId();
            $historyData['payment_status_id'] = $order->getPaymentStatus()->getId();
        }

        
// If the product is a product in the stock, we must change the stock size to the new ordered quantity             $quantityDiff = $oldQuantity - $newQuantity;

            $product->setInStock($product->getInStock() + $quantityDiff);
            $this->entityManager->persist($product);
        }
    }

    public function removeProductDetail(OrderDetail $detail): void
    {
        // Do not increase instock for canceled orders         if ($detail->getOrder() && $detail->getOrder()->getOrderStatus()->getId() === -1) {
            return;
        }

        $product = $this->getProductFromDetail($detail);
        if ($product) {
            $product->setInStock($product->getInStock() + $detail->getQuantity());
            $this->entityManager->persist($product);
        }
    }

    /** * Returns the product of the product position */


                return;
            }
        }

        // Prepares the associated data of an order.         $data = $this->getAssociatedData($data);

        // Before we can create the status mail, we need to save the order data.         // Otherwise, the status mail would be created with the old order status and amount.         $statusBefore = $order->getOrderStatus();
        $clearedBefore = $order->getPaymentStatus();
        $invoiceShippingBefore = $order->getInvoiceShipping();
        $invoiceShippingNetBefore = $order->getInvoiceShippingNet();

        if (!empty($data['clearedDate'])) {
            try {
                $data['clearedDate'] = new DateTime($data['clearedDate']);
            } catch (Exception $e) {
                $data['clearedDate'] = null;
            }
        }

        
/** * Set order status by order id * * @param int $orderId * @param int $orderStatusId * @param bool $sendStatusMail * @param string|null $comment */
    public function setOrderStatus($orderId$orderStatusId$sendStatusMail = false, $comment = null)
    {
        $previousStatusId = $this->getOrderStatus($orderId);

        if ($orderStatusId == $previousStatusId) {
            return;
        }

        $this->db->executeUpdate(
            'UPDATE s_order SET status = :status WHERE id = :orderId;',
            [':status' => $orderStatusId, ':orderId' => $orderId]
        );

        $sql = ' INSERT INTO s_order_history ( orderID, userID, previous_order_status_id, order_status_id, previous_payment_status_id, payment_status_id, comment, change_date ) SELECT id, NULL, :previousStatus, :currentStatus, cleared, cleared, :comment, NOW() FROM s_order WHERE id = :orderId ';
Home | Imprint | This part of the site doesn't use cookies.