taxClassNameRepository = $taxClassNameRepository; $this->factory = $factory; } /** * Build a {@see LineItemInterface} from a {@see QuoteDetailsItemInterface} * * @param QuoteDetailsItemInterface $item * @param int|null $qtyOverride * @return LineItemInterface */ public function buildFromQuoteDetailsItem(QuoteDetailsItemInterface $item, $qtyOverride = null) { $lineItem = $this->createLineItem(); $sku = $item->getExtensionAttributes() !== null ? $item->getExtensionAttributes()->getVertexProductCode() : null; if ($sku !== null) { $lineItem->setProductCode(substr($sku, 0, Config::MAX_CHAR_PRODUCT_CODE_ALLOWED)); } $taxClassId = $item->getTaxClassKey() && $item->getTaxClassKey()->getType() === TaxClassKeyInterface::TYPE_ID ? $item->getTaxClassKey()->getValue() : $item->getTaxClassId(); $lineItem->setProductClass( $this->taxClassNameRepository->getById($taxClassId) ); $quantity = (float)($qtyOverride ?: $item->getQuantity()); $lineItem->setQuantity($quantity); $lineItem->setUnitPrice($item->getUnitPrice()); $rowTotal = $item->getUnitPrice() * $quantity; $lineItem->setExtendedPrice($rowTotal - $item->getDiscountAmount()); $lineItem->setLineItemId($item->getCode()); return $lineItem; } /** * Create a {@see LineItemInterface} * * @return LineItemInterface */ private function createLineItem() { return $this->factory->create(); } }