messages = []; $total_price = $purchaseState->getProductsTotalPrice(); $data['id'] = $orderDiscount->getId(); $name = $orderDiscount->getDisplayName(); if ($id_coupon = $data['trigger_data']['generated_coupon']['id'] ?? null) { $coupon = sqlQueryBuilder()->select('price, currency')->from('discounts_coupons') ->andWhere(Operator::equals(['id' => $id_coupon])) ->execute()->fetchAssociative(); if ($price = floatval($coupon['price'] ?? null)) { $data['discount'] = $price; $data['unit'] = $coupon['currency']; } } $note = $this->createItemNote($data, $name); $discountPrice = $this->discountUtil->calculateDiscountPrice($total_price->getPriceWithVat(), $data, $name); // using `value(2)` to keep price in note compatible with price applied to order item row see DiscountPurchaseItem.php:29 (getPriceWithVat) $note['coupon_price'] = $discountPrice->value(2); $this->addDiscountItem($discountPrice, $name, $data, $orderDiscount, $note, $purchaseState); } public function handleData($data) { $data['divideDiscountPrice'] = 'N'; return parent::handleData($data); } public function checkValidity(&$data) { return true; } public function createItemNote($data = [], &$name = ''): array { $note = parent::createItemNote($data, $name); $note['partial'] = (($data['partial'] ?? 'N') == 'Y'); return $note; } public function getDelayedExecution(): ?int { return 1; } }