protected function setItems()
    {
        foreach ($this->sgBase->getItems() as $item) {
            if ($item->isSgCoupon()) {
                continue;
            }

            $info        = $item->getInternalOrderInfo();
            $amountNet   = $item->getUnitAmount();
            $amountGross = $item->getUnitAmountWithTax();

            try {
                $product = $this->productHelper->loadById($info->getProductId());
            } catch (\Exception $e) {
                $product = null;
            }

            if (!is_object($product) || !$product->getId() || $product->getStatus() != MageStatus::STATUS_ENABLED) {
                $this->log->error('Product with ID ' . $info->getProductId() . ' could not be loaded.');
                $this->log->error('SG item number: ' . $item->getItemNumber());
                $item->setUnhandledError(\ShopgateLibraryException::CART_ITEM_PRODUCT_NOT_FOUND, 'product not found');
                continue;
            }

            try {
                $quoteItem = $this->getQuoteItem($item, $product);
                if ($this->useShopgatePrices()) {
                    if ($this->taxData->priceIncludesTax($this->storeManager->getStore())) {
                        $quoteItem->setCustomPrice($amountGross);
                        $quoteItem->setOriginalCustomPrice($amountGross);
                    } else {
                        $quoteItem->setCustomPrice($amountNet);
                        $quoteItem->setOriginalCustomPrice($amountNet);
                    }
                }
                $quoteItem->setTaxPercent($item->getTaxPercent());

                if (!$item->isSimple()) {
                    $productWeight = $product->getTypeInstance()->getWeight($product);
                    $quoteItem->setWeight($productWeight);
                }

                $quoteItem->setRowWeight($quoteItem->getWeight() * $quoteItem->getQty());
                $this->quote->setItemsCount($this->quote->getItemsCount() + 1);
            } catch (\Exception $e) {
                $this->log->error(
                    "Error importing product to quote by id: {$product->getId()}, error: {$e->getMessage()}"
                );
                $this->log->error('SG item number: ' . $item->getItemNumber());
                $item->setMagentoError($e->getMessage());
            }
        }

        /**
         * Magento's flow is to save Quote on addItem, then on saveOrder load quote again. We mimic this here.
         */
        $this->quoteRepository->save($this->quote);
        $this->quote = $this->quoteRepository->get($this->quote->getId());
    }
protected function setItems()
    {
        foreach ($this->sgBase->getItems() as $item) {
            if ($item->isSgCoupon()) {
                continue;
            }

            $info        = $item->getInternalOrderInfo();
            $amountNet   = $item->getUnitAmount();
            $amountGross = $item->getUnitAmountWithTax();

            try {
                $product = $this->productHelper->loadById($info->getProductId());
            } catch (\Exception $e) {
                $product = null;
            }

            if (!is_object($product) || !$product->getId() || $product->getStatus() != MageStatus::STATUS_ENABLED) {
                $this->log->error('Product with ID ' . $info->getProductId() . ' could not be loaded.');
                $this->log->error('SG item number: ' . $item->getItemNumber());
                $item->setUnhandledError(\ShopgateLibraryException::CART_ITEM_PRODUCT_NOT_FOUND, 'product not found');
                continue;
            }

            try {
                $quoteItem = $this->getQuoteItem($item, $product);
                if ($this->useShopgatePrices()) {
                    if ($this->taxData->priceIncludesTax($this->storeManager->getStore())) {
                        $quoteItem->setCustomPrice($amountGross);
                        $quoteItem->setOriginalCustomPrice($amountGross);
                    } else {
                        $quoteItem->setCustomPrice($amountNet);
                        $quoteItem->setOriginalCustomPrice($amountNet);
                    }
                }
                $quoteItem->setTaxPercent($item->getTaxPercent());

                if (!$item->isSimple()) {
                    $productWeight = $product->getTypeInstance()->getWeight($product);
                    $quoteItem->setWeight($productWeight);
                }

                $quoteItem->setRowWeight($quoteItem->getWeight() * $quoteItem->getQty());
                $this->quote->setItemsCount($this->quote->getItemsCount() + 1);
            } catch (\Exception $e) {
                $this->log->error(
                    "Error importing product to quote by id: {$product->getId()}, error: {$e->getMessage()}"
                );
                $this->log->error('SG item number: ' . $item->getItemNumber());
                $item->setMagentoError($e->getMessage());
            }
        }

        /**
         * Magento's flow is to save Quote on addItem, then on saveOrder load quote again. We mimic this here.
         */
        $this->quoteRepository->save($this->quote);
        $this->quote = $this->quoteRepository->get($this->quote->getId());
    }
protected function setItems ( ) { foreach ( $ this -> sgBase -> getItems ( ) as $ item ) { if ( $ item -> isSgCoupon ( ) ) { continue ; } $ info = $ item -> getInternalOrderInfo ( ) ; $ amountNet = $ item -> getUnitAmount ( ) ; $ amountGross = $ item -> getUnitAmountWithTax ( ) ; try { $ product = $ this -> productHelper -> loadById ( $ info -> getProductId ( ) ) ; } catch ( \ Exception $ e ) { $ product = null ; } if ( ! is_object ( $ product ) || ! $ product -> getId ( ) || $ product -> getStatus ( ) != MageStatus :: STATUS_ENABLED ) { $ this -> log -> error ( 'Product with ID ' . $ info -> getProductId ( ) . ' could not be loaded.' ) ; $ this -> log -> error ( 'SG item number: ' . $ item -> getItemNumber ( ) ) ; $ item -> setUnhandledError ( \ ShopgateLibraryException :: CART_ITEM_PRODUCT_NOT_FOUND , 'product not found' ) ; continue ; } try { $ quoteItem = $ this -> getQuoteItem ( $ item , $ product ) ; if ( $ this -> useShopgatePrices ( ) ) { if ( $ this -> taxData -> priceIncludesTax ( $ this -> storeManager -> getStore ( ) ) ) { $ quoteItem -> setCustomPrice ( $ amountGross ) ; $ quoteItem -> setOriginalCustomPrice ( $ amountGross ) ; } else { $ quoteItem -> setCustomPrice ( $ amountNet ) ; $ quoteItem -> setOriginalCustomPrice ( $ amountNet ) ; } } $ quoteItem -> setTaxPercent ( $ item -> getTaxPercent ( ) ) ; if ( ! $ item -> isSimple ( ) ) { $ productWeight = $ product -> getTypeInstance ( ) -> getWeight ( $ product ) ; $ quoteItem -> setWeight ( $ productWeight ) ; } $ quoteItem -> setRowWeight ( $ quoteItem -> getWeight ( ) * $ quoteItem -> getQty ( ) ) ; $ this -> quote -> setItemsCount ( $ this -> quote -> getItemsCount ( ) + 1 ) ; } catch ( \ Exception $ e ) { $ this -> log -> error ( "Error importing product to quote by id: {$product->getId()}, error: {$e->getMessage()}" ) ; $ this -> log -> error ( 'SG item number: ' . $ item -> getItemNumber ( ) ) ; $ item -> setMagentoError ( $ e -> getMessage ( ) ) ; } } /**
         * Magento's flow is to save Quote on addItem, then on saveOrder load quote again. We mimic this here.
         */ $ this -> quoteRepository -> save ( $ this -> quote ) ; $ this -> quote = $ this -> quoteRepository -> get ( $ this -> quote -> getId ( ) ) ; }
Assigns Shopgate cart items to quote
Assigns Shopgate cart items to quote