Adds all articles user wants to add to basket. Returns
last added to basket item.

@param array $products products to add array

@return  object  $oBasketItem    last added basket item
971689
protected function _addItems($products)
    {
        $activeView = \OxidEsales\Eshop\Core\Registry::getConfig()->getActiveView();
        $errorDestination = $activeView->getErrorDestination();

        $basket = $this->getSession()->getBasket();
        $basketInfo = $basket->getBasketSummary();

        $basketItemAmounts = [];

        foreach ($products as $addProductId => $productInfo) {
            $data = $this->prepareProductInformation($addProductId, $productInfo);
            $productAmount = 0;
            if (isset($basketInfo->aArticles[$data['id']])) {
                $productAmount = $basketInfo->aArticles[$data['id']];
            }
            $products[$addProductId]['oldam'] = $productAmount;

            //If we already changed articles so they now exactly match existing ones,
            //we need to make sure we get the amounts correct
            if (isset($basketItemAmounts[$data['oldBasketItemId']])) {
                $data['amount'] = $data['amount'] + $basketItemAmounts[$data['oldBasketItemId']];
            }

            $basketItem = $this->addItemToBasket($basket, $data, $errorDestination);

            if (($basketItem instanceof \OxidEsales\Eshop\Application\Model\BasketItem)) {
                $basketItemKey = $basketItem->getBasketItemKey();
                if ($basketItemKey) {
                    if (! isset($basketItemAmounts[$basketItemKey])) {
                        $basketItemAmounts[$basketItemKey] = 0;
                    }
                    $basketItemAmounts[$basketItemKey] += $data['amount'];
                }
            }

            if (!$basketItem) {
                $info = $basket->getBasketSummary();
                $productAmount = $info->aArticles[$data['id']];
                $products[$addProductId]['am'] = isset($productAmount) ? $productAmount : 0;
            }
        }

        //if basket empty remove possible gift card
        if ($basket->getProductsCount() == 0) {
            $basket->setCardId(null);
        }

        // information that last call was tobasket
        $this->_setLastCall($this->_getLastCallFnc(), $products, $basketInfo);

        return $basketItem;
    }
319325
public function addProduct(Icepay_Order_Product $obj) {
        if (!isset($this->_data["products"]))
            $this->_data["products"] = Array();
        array_push($this->_data["products"], $obj);
        return $this;
    }
448478
public function add(array $params)
    {
        if (is_null($this->getId())) {
            $this->createBasket();
        }

        $this->callResourceAction(function ($params) {
            return $this->client->basketResource($this->version)
                                ->create($params);
        }, $params);
    }
518804
protected function _addBundles()
    {
        $aBundles = [];
        // iterating through articles and binding bundles
        foreach ($this->_aBasketContents as $key => $oBasketItem) {
            try {
                // adding discount type bundles
                if (!$oBasketItem->isDiscountArticle() && !$oBasketItem->isBundle()) {
                    $aBundles = $this->_getItemBundles($oBasketItem, $aBundles);
                } else {
                    continue;
                }

                // adding item type bundles
                $aArtBundles = $this->_getArticleBundles($oBasketItem);
                // adding bundles to basket
                $this->_addBundlesToBasket($aArtBundles);
            } catch (\OxidEsales\Eshop\Core\Exception\NoArticleException $oEx) {
                $this->removeItem($key);
                \OxidEsales\Eshop\Core\Registry::getUtilsView()->addErrorToDisplay($oEx);
            } catch (\OxidEsales\Eshop\Core\Exception\ArticleInputException $oEx) {
                $this->removeItem($key);
                \OxidEsales\Eshop\Core\Registry::getUtilsView()->addErrorToDisplay($oEx);
            }
        }

        // adding global basket bundles
        $aBundles = $this->_getBasketBundles($aBundles);

        // adding all bundles to basket
        if ($aBundles) {
            $this->_addBundlesToBasket($aBundles);
        }
    }
490946
public function setProducts( array $products )
	{
		MW_Common_Abstract::checkClassList( 'MShop_Order_Item_Base_Product_Interface', $products );
		$this->_products = $products;
		$this->setModified();
	}
477929
public function load( $product ) {
		$this->product = $product;
		$this->show_link();
		$this->add_hooks();

		return $this;
	}
111589
protected function completeWithRandomProducts(Collection $products) : Collection
	{
		$currentLimit = $this->limit - $products->count();

		return Product::whereNotIn('id', $this->excluding->all())
			->orderBy('rate_val', 'desc')
			->take($currentLimit)
			->get();
	}
339282
public function replies($filters = array())
	{
		if (!isset($filters['item_id']))
		{
			$filters['item_id'] = $this->get('item_id');
		}

		if (!isset($filters['item_type']))
		{
			$filters['item_type'] = $this->get('item_type');
		}

		$entries = self::all()
			->whereEquals('parent', (int) $this->get('id'))
			->whereEquals('item_type', $filters['item_type'])
			->whereEquals('item_id', (int) $filters['item_id']);

		if (isset($filters['state']))
		{
			$entries->whereIn('state', (array) $filters['state']);
		}

		return $entries;
	}
144312
protected function prepareProductsForFrontend($products)
    {
        $this->Product = TableRegistry::getTableLocator()->get('Products');
        $this->Manufacturer = TableRegistry::getTableLocator()->get('Manufacturers');
        $this->ProductAttribute = TableRegistry::getTableLocator()->get('ProductAttributes');

        foreach ($products as &$product) {
            $grossPrice = $this->Product->getGrossPrice($product['id_product'], $product['price']);
            $product['gross_price'] = $grossPrice;
            $product['tax'] = $grossPrice - $product['price'];
            $product['is_new'] = $this->Product->isNew($product['created']);
            
            if ($this->getRequest()->getSession()->check('Auth.instantOrderCustomer')) {
                $product['next_delivery_day'] = Configure::read('app.timeHelper')->getCurrentDateForDatabase();
            } else {
                $product['next_delivery_day'] = $this->Product->calculatePickupDayRespectingDeliveryRhythm(
                    $this->Product->newEntity([
                        'delivery_rhythm_order_possible_until' => $product['delivery_rhythm_order_possible_until'] == '' ? null : new FrozenDate($product['delivery_rhythm_order_possible_until']),
                        'delivery_rhythm_first_delivery_day' => $product['delivery_rhythm_first_delivery_day'] == '' ? null : new FrozenDate($product['delivery_rhythm_first_delivery_day']),
                        'delivery_rhythm_type' => $product['delivery_rhythm_type'],
                        'delivery_rhythm_count' => $product['delivery_rhythm_count'],
                        'delivery_rhythm_send_order_list_weekday' => $product['delivery_rhythm_send_order_list_weekday'],
                        'delivery_rhythm_send_order_list_day' => $product['delivery_rhythm_send_order_list_day'],
                        'is_stock_product' => $product['is_stock_product']
                    ]
                ));
            }
            $product['attributes'] = [];

            if ($this->AppAuth->isTimebasedCurrencyEnabledForCustomer()) {
                if ($this->Manufacturer->getOptionTimebasedCurrencyEnabled($product['timebased_currency_enabled'])) {
                    $product['timebased_currency_money_incl'] = $this->Manufacturer->getTimebasedCurrencyMoney($product['gross_price'], $product['timebased_currency_max_percentage']);
                    $product['timebased_currency_money_excl'] = $this->Manufacturer->getTimebasedCurrencyMoney($product['price'], $product['timebased_currency_max_percentage']);
                    $product['timebased_currency_seconds'] = $this->Manufacturer->getCartTimebasedCurrencySeconds($product['gross_price'], $product['timebased_currency_max_percentage']);
                    $product['timebased_currency_manufacturer_limit_reached'] = $this->Manufacturer->hasManufacturerReachedTimebasedCurrencyLimit($product['id_manufacturer']);
                }
                
            }

            $attributes = $this->ProductAttribute->find('all', [
                'conditions' => [
                    'ProductAttributes.id_product' => $product['id_product']
                ],
                'contain' => [
                    'StockAvailables',
                    'ProductAttributeCombinations.Attributes',
                    'DepositProductAttributes',
                    'UnitProductAttributes'
                ]
            ]);
            $preparedAttributes = [];
            foreach ($attributes as $attribute) {
                $preparedAttributes['ProductAttributes'] = [
                    'id_product_attribute' => $attribute->id_product_attribute
                ];
                $grossPrice = $this->Product->getGrossPrice($attribute->id_product, $attribute->price);
                $preparedAttributes['ProductAttributes'] = [
                    'gross_price' => $grossPrice,
                    'tax' => $grossPrice - $attribute->price,
                    'default_on' => $attribute->default_on,
                    'id_product_attribute' => $attribute->id_product_attribute
                ];
                $preparedAttributes['StockAvailables'] = [
                    'quantity' => $attribute->stock_available->quantity,
                    'quantity_limit' => $attribute->stock_available->quantity_limit
                ];
                $preparedAttributes['DepositProductAttributes'] = [
                    'deposit' => !empty($attribute->deposit_product_attribute) ? $attribute->deposit_product_attribute->deposit : 0
                ];
                $preparedAttributes['ProductAttributeCombinations'] = [
                    'Attributes' => [
                        'name' => $attribute->product_attribute_combination->attribute->name,
                        'can_be_used_as_unit' => $attribute->product_attribute_combination->attribute->can_be_used_as_unit
                    ]
                ];
                $preparedAttributes['Units'] = [
                    'price_per_unit_enabled' => !empty($attribute->unit_product_attribute) ? $attribute->unit_product_attribute->price_per_unit_enabled : 0,
                    'price_incl_per_unit' => !empty($attribute->unit_product_attribute) ? $attribute->unit_product_attribute->price_incl_per_unit : 0,
                    'unit_name' => !empty($attribute->unit_product_attribute) ? $attribute->unit_product_attribute->name : '',
                    'unit_amount' => !empty($attribute->unit_product_attribute) ? $attribute->unit_product_attribute->amount : 0,
                    'quantity_in_units' => !empty($attribute->unit_product_attribute) ? $attribute->unit_product_attribute->quantity_in_units : 0
                ];

                if ($this->AppAuth->isTimebasedCurrencyEnabledForCustomer()) {
                    if ($this->Manufacturer->getOptionTimebasedCurrencyEnabled($product['timebased_currency_enabled'])) {
                        $preparedAttributes['timebased_currency_money_incl'] = $this->Manufacturer->getTimebasedCurrencyMoney($grossPrice, $product['timebased_currency_max_percentage']);
                        $preparedAttributes['timebased_currency_money_excl'] = $this->Manufacturer->getTimebasedCurrencyMoney($attribute->price, $product['timebased_currency_max_percentage']);
                        $preparedAttributes['timebased_currency_seconds'] = $this->Manufacturer->getCartTimebasedCurrencySeconds($grossPrice, $product['timebased_currency_max_percentage']);
                        $preparedAttributes['timebased_currency_manufacturer_limit_reached'] = $this->Manufacturer->hasManufacturerReachedTimebasedCurrencyLimit($product['id_manufacturer']);
                    }
                }

                $product['attributes'][] = $preparedAttributes;
            }
        }
        return $products;
    }
636963
public function getBasketArticles()
    {
        $aBasketArticles = [];
        /** @var \oxBasketItem $oBasketItem */
        foreach ($this->_aBasketContents as $sItemKey => $oBasketItem) {
            try {
                $oProduct = $oBasketItem->getArticle(true);

                if (\OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('bl_perfLoadSelectLists')) {
                    // marking chosen select list
                    $aSelList = $oBasketItem->getSelList();
                    if (is_array($aSelList) && ($aSelectlist = $oProduct->getSelectLists($sItemKey))) {
                        reset($aSelList);
                        foreach ($aSelList as $conkey => $iSel) {
                            $aSelectlist[$conkey][$iSel]->selected = 1;
                        }
                        $oProduct->setSelectlist($aSelectlist);
                    }
                }
            } catch (\OxidEsales\Eshop\Core\Exception\NoArticleException $oEx) {
                \OxidEsales\Eshop\Core\Registry::getUtilsView()->addErrorToDisplay($oEx);
                $this->removeItem($sItemKey);
                $this->calculateBasket(true);
                continue;
            } catch (\OxidEsales\Eshop\Core\Exception\ArticleInputException $oEx) {
                \OxidEsales\Eshop\Core\Registry::getUtilsView()->addErrorToDisplay($oEx);
                $this->removeItem($sItemKey);
                $this->calculateBasket(true);
                continue;
            }

            $aBasketArticles[$sItemKey] = $oProduct;
        }

        return $aBasketArticles;
    }
94349
public function create(Product $product)
    {
        $this->getEm()->persist($product);
        $this->getEm()->flush();

        return $product;
    }
83894
public function add( ...$items )
	{
		foreach ( $items as &$item ) $item = (array)$item;
		$this->items = array_merge( $this->items , ...$items );
		return $this;
	}
1216228
public function add($items)
    {
        if (is_array($items)) {
            $this->collection[] = new RecordField($items);
        } elseif (is_object($items) && $items instanceof RecordField) {
            $this->collection[] = $items;
        }

        return $this;
    }
462126
private function addProductOne(Basket $basket)
    {
        $one = $this->products->one();

        $basket->add($one->sku, $one->name, $one->price, function ($product) use ($one) {
            $product->category($one->category);
        });

        return $basket;
    }
406592
public function add($items)
    {
        if ($items && $items instanceof \Purekid\Mongodm\Model) {
            $id = (string) $items->getId();
            $this->_items[$id] = $items;
        } elseif (is_array($items)) {
            foreach ($items as $obj) {
                if ($obj instanceof \Purekid\Mongodm\Model) {
                    $this->add($obj);
                }
            }
        } elseif ($items instanceof self) {
            $this->add($items->toArray());
        }

        return $this;

    }
1013542
public function addSelectColumns(array $columns)
    {
        foreach ($columns as $column) {
            is_array($column)
                ? count($column) != count($column, true)
                ? $this->addSelectColumns(...$column) : $this->addSelectColumn(...$column) : $this->addSelectColumn($column);
        }
        
        return $this;
    }
485320
public function &GetAffectedBasketArticles()
    {
        if (is_null($this->oAffectedBasketArticles)) {
            $this->oAffectedBasketArticles = null;
            $oBasket = TShopBasket::GetInstance();
            $this->oAffectedBasketArticles = &$oBasket->GetArticlesAffectedByShippingType($this);
        }

        return $this->oAffectedBasketArticles;
    }