/* Add or remove moneybuy 'products' from the hypothetical basket
175407
function dataLayer_updateBasket(thisID, thisBtnPos, type) {
      var thisParagraph = allRows[thisID];
      var thisAmount = '';
      var isBtn = true;

      // Construct generic ecommerce object for all use cases
      // TODO: handle currency changes
      var ecommerceObj = {
        'ecommerce': {'currencyCode': 'GBP',},
        'event': type ===  'add' ? 'addToBasket' : 'removeFromBasket'
      };

      lastBtnPos = thisBtnPos;

      // Change our 'amount' source depending on the input type
      if (thisBtnPos == 0) {
        isBtn = false;
        thisAmount = $('#' + thisID).data('current-amount');
      } else {
        thisAmount = allRows[thisID]['buttons'][thisBtnPos]['amount'];
      }

      submitNameID = isBtn ? 'moneybuy-' + thisAmount : 'manual-entry';

      // Parse this to a 2-decimal place float, need to re-parse after toFixed
      thisAmount = parseFloat(thisAmount).toFixed(2);
      thisAmount = parseFloat(thisAmount);

      // Switch the values based on the input type
      ecommerceObj['ecommerce'][type] = {
        'actionField': {'list': thisParagraph['client_id'] + '_' + thisID },
        'products': [{
          id: submitNameID,
          name: submitNameID,
          price: thisAmount,      
          brand: allRows[thisID]['giving_type'],  
          category: allRows[thisID]['cart_id'], 
          quantity: 1,
          dimenstion10: allRows[thisID]['giving_type']
        }],
      };

      dataLayer.push(ecommerceObj);

      // If this is our 'add' event triggered via submission, add the new cookie
      if ( type === 'add' ){
        updateCookie(thisID, thisBtnPos, 'add');
      }
    }
891498
function updatePrices()
    {
        $productCollection = $this->attribute( 'productcollection' );
        if ( $productCollection )
        {
            $currencyCode = '';
            $items = $this->items();

            $db = eZDB::instance();
            $db->begin();
            foreach( $items as $itemArray )
            {
                $item = $itemArray['item_object'];
                $productContentObject = $item->attribute( 'contentobject' );
                $priceObj = null;
                $price = 0.0;
                $attributes = $productContentObject->contentObjectAttributes();
                foreach ( $attributes as $attribute )
                {
                    $dataType = $attribute->dataType();
                    if ( eZShopFunctions::isProductDatatype( $dataType->isA() ) )
                    {
                        $priceObj = $attribute->content();
                        $price += $priceObj->attribute( 'price' );
                        break;
                    }
                }
                if ( !is_object( $priceObj ) )
                    break;

                $currency = $priceObj->attribute( 'currency' );
                $optionsPrice = $item->calculatePriceWithOptions( $currency );

                $price += $optionsPrice;
                $item->setAttribute( "price", $price );
                if ( $priceObj->attribute( 'is_vat_included' ) )
                {
                    $item->setAttribute( "is_vat_inc", '1' );
                }
                else
                {
                    $item->setAttribute( "is_vat_inc", '0' );
                }
                $item->setAttribute( "vat_value", $priceObj->VATPercent( $productContentObject ) );
                $item->setAttribute( "discount", $priceObj->attribute( 'discount_percent' ) );
                $item->store();

                $currencyCode = $priceObj->attribute( 'currency' );
            }

            $productCollection->setAttribute( 'currency_code', $currencyCode );
            $productCollection->store();
            $db->commit();

            // update prices that are related to shipping values.
            eZShippingManager::updateShippingInfo( $productCollection->attribute( 'id' ) );
        }
    }
399213
function removeItem( $itemID )
    {
        $item = eZProductCollectionItem::fetch( $itemID );
        if ( is_object( $item ) && $this->attribute( 'productcollection_id' ) == $item->attribute( 'productcollection_id' ) )
        {
            $item->remove();
        }
    }
530446
private function addProductZero(Basket $basket)
    {
        $zero = $this->products->zero();

        $basket->add($zero->sku, $zero->name, $zero->price);

        return $basket;
    }
1095509
def add_to_cart(item_id):
    
    cart = Cart(session['cart'])
    if cart.change_item(item_id, 'add'):
        session['cart'] = cart.to_dict()
    return list_products()
101056
public function updateTransaction()
    {        
        $cart = $this->cartProvider->getCart();

        if (0 === $cart->countItems() || $this->isTransactionUpdated($cart)) {
            return;
        }

        /** @var TransactionRepository $transactionRepository */
        $transactionRepository = $this->manager->getRepository('EcommerceBundle:Transaction');

        if ($this->session->has('transaction-id')) {
            /** @var Transaction $transaction */
            $transaction = $transactionRepository->find($this->session->get('transaction-id'));

            $transactionRepository->removeItems($transaction);
        } else {
            $transactionKey = $transactionRepository->getNextNumber();

            // create a new transaction
            $transaction = new Transaction();
            $transaction->setTransactionKey($transactionKey);
            $transaction->setStatus(Transaction::STATUS_CREATED);
            $transaction->setActor($this->securityContext->getToken()->getUser());
            $cartItem = $cart->getItems()->first();
            $product = $cartItem->getProduct();
        }

        $orderTotalPrice = 0;

        foreach ($cart->getItems() as $cartItem) {
            /** @var Product $product */
            $product = $cartItem->getProduct();

            $productPurchase = new ProductPurchase();
            $productPurchase->setProduct($product);
            $productPurchase->setBasePrice($cartItem->getUnitPrice());
            $productPurchase->setQuantity($cartItem->getQuantity());
            $productPurchase->setDiscount($product->getDiscount());
            $productPurchase->setTotalPrice($cartItem->getTotal());
            $productPurchase->setTransaction($transaction);
            $productPurchase->setReturned(false);
            //free transport
            if($cartItem->isFreeTransport()){
                $productPurchase->setDeliveryExpenses(0);
            }else{ 
                $productPurchase->setDeliveryExpenses($cartItem->getShippingCost());
            }
            $orderTotalPrice += $cartItem->getProduct()->getPrice() * $cartItem->getQuantity();

            $this->manager->persist($productPurchase);
        }

        $transaction->setTotalPrice($orderTotalPrice);

        $this->manager->persist($transaction);
        $this->manager->flush();

        $this->session->set('transaction-id', $transaction->getId());
        $this->session->save();
        
    }
283626
function addProductToCart(url, productID, formID, formBuildID, formToken) {
	let formdata = {
		product_id: productID,
		form_id: formID,
		form_build_id: formBuildID,
		form_token: formToken,
		quantity: 1,
		op: "Add to cart",
	};
	let headers = { "Content-Type": "application/x-www-form-urlencoded" };
	let res = http.post(url, formdata, { headers: headers });
	// verify add to cart succeeded
	check(res, {
		"add to cart succeeded": (res) => res.body.includes('Item successfully added to your cart')
	}) || fail("add to cart failed");
}
412985
public function setIsNewBasket()
    {
        $this->_blNewBasket = true;
        $iTime = \OxidEsales\Eshop\Core\Registry::getUtilsDate()->getTime();
        $this->oxuserbaskets__oxupdate = new \OxidEsales\Eshop\Core\Field($iTime);
    }
1017276
@Override
	public void removeByCommerceDiscountId(long commerceDiscountId) {
		for (CommerceDiscountRel commerceDiscountRel : findByCommerceDiscountId(
				commerceDiscountId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
			remove(commerceDiscountRel);
		}
	}
1115091
public function addBasketItemParams()
    {
        $basket = $this->getBasket();
        $lang = $this->getLang();
        $request = $this->getPayPalRequest();

        $pos = 0;
        foreach ($basket->getContents() as $basketItem) {
            $request->setParameter("L_PAYMENTREQUEST_0_NAME{$pos}", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($basketItem->getTitle()));
            $request->setParameter("L_PAYMENTREQUEST_0_AMT{$pos}", $this->formatFloat($basketItem->getUnitPrice()->getPrice()));
            $request->setParameter("L_PAYMENTREQUEST_0_QTY{$pos}", (int) $basketItem->getAmount());
            $request->setParameter("L_PAYMENTREQUEST_0_ITEMURL{$pos}", $basketItem->getLink());

            $basketProduct = $basketItem->getArticle();
            $request->setParameter("L_PAYMENTREQUEST_0_NUMBER{$pos}", $basketProduct->oxarticles__oxartnum->value);

            $pos++;
        }

        //adding payment costs as product
        if ($basket->getPayPalPaymentCosts() > 0) {
            $paymentTitle = $lang->translateString("OEPAYPAL_SURCHARGE") . " " . $lang->translateString("OEPAYPAL_TYPE_OF_PAYMENT");
            $request->setParameter("L_PAYMENTREQUEST_0_NAME{$pos}", $paymentTitle);
            $request->setParameter("L_PAYMENTREQUEST_0_AMT{$pos}", $this->formatFloat($basket->getPayPalPaymentCosts()));
            $request->setParameter("L_PAYMENTREQUEST_0_QTY{$pos}", 1);

            $pos++;
        }

        //adding wrapping as product
        if ($basket->getPayPalWrappingCosts() > 0) {
            $request->setParameter("L_PAYMENTREQUEST_0_NAME{$pos}", $lang->translateString("OEPAYPAL_GIFTWRAPPER"));
            $request->setParameter("L_PAYMENTREQUEST_0_AMT{$pos}", $this->formatFloat($basket->getPayPalWrappingCosts()));
            $request->setParameter("L_PAYMENTREQUEST_0_QTY{$pos}", 1);

            $pos++;
        }

        //adding greeting card as product
        if ($basket->getPayPalGiftCardCosts() > 0) {
            $request->setParameter("L_PAYMENTREQUEST_0_NAME{$pos}", $lang->translateString("OEPAYPAL_GREETING_CARD"));
            $request->setParameter("L_PAYMENTREQUEST_0_AMT{$pos}", $this->formatFloat($basket->getPayPalGiftCardCosts()));
            $request->setParameter("L_PAYMENTREQUEST_0_QTY{$pos}", 1);

            $pos++;
        }
    }
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;
    }
166924
@Override
	public void removeByCommercePriceListId(long commercePriceListId) {
		for (CommercePriceEntry commercePriceEntry : findByCommercePriceListId(
				commercePriceListId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
			remove(commercePriceEntry);
		}
	}
456942
public function cancelCoupon($basketId, string $couponCode, $userId)  // !! DEPRECATED moved to basket
    {
        $params = [
          "basketId" => $basketId,
          "couponCode" => $couponCode,
          "userId" => $userId
        ];

        $response = $this->handler->handle('POST', $params, 'discard');

        //TODO: refactor to make method
        return $response;
        //        return $this->make($response, false);
    }
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;
    }
1092074
@Override
	public void removeByCommerceDiscountId(long commerceDiscountId) {
		for (CommerceDiscountRule commerceDiscountRule : findByCommerceDiscountId(
				commerceDiscountId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
			remove(commerceDiscountRule);
		}
	}
1170498
function enhancedEcommerceProductAction(track, action, data) {
  enhancedEcommerceTrackProduct(track);
  window.ga('ec:setAction', action, data || {});
}
1341891
function updatePriceInfo( $productCollectionID, &$basketInfo )
    {
        $shippingInfo = eZShippingManager::getShippingInfo( $productCollectionID );
        $additionalShippingValues = eZShippingManager::vatPriceInfo( $shippingInfo );
        $returnValue = false;
        foreach ( $additionalShippingValues['shipping_vat_list'] as $vatValue => $additionalShippingValueArray )
        {
            $shippingExVAT = $additionalShippingValueArray['shipping_ex_vat'];
            $shippingIncVAT = $additionalShippingValueArray['shipping_inc_vat'];
            $shippingVat = $additionalShippingValueArray['shipping_vat'];

            if ( !isset( $basketInfo['price_info'][$vatValue]['total_price_ex_vat'] ) )
            {
                $basketInfo['price_info'][$vatValue]['total_price_ex_vat'] = $shippingExVAT;
                $basketInfo['price_info'][$vatValue]['total_price_inc_vat'] = $shippingIncVAT;
                $basketInfo['price_info'][$vatValue]['total_price_vat'] = $shippingVat;

                $basketInfo['total_price_info']['total_price_ex_vat'] = $shippingExVAT;
                $basketInfo['total_price_info']['total_price_inc_vat'] = $shippingIncVAT;
                $basketInfo['total_price_info']['total_price_vat'] = $shippingVat;
            }
            else
            {
                $basketInfo['price_info'][$vatValue]['total_price_ex_vat'] += $shippingExVAT;
                $basketInfo['price_info'][$vatValue]['total_price_inc_vat'] += $shippingIncVAT;
                $basketInfo['price_info'][$vatValue]['total_price_vat'] += $shippingVat;

                $basketInfo['total_price_info']['total_price_ex_vat'] += $shippingExVAT;
                $basketInfo['total_price_info']['total_price_inc_vat'] += $shippingIncVAT;
                $basketInfo['total_price_info']['total_price_vat'] += $shippingVat;
            }

            if ( !isset( $basketInfo['additional_info']['shipping_items'][$vatValue]['total_price_ex_vat'] ) )
            {
                $basketInfo['additional_info']['shipping_items'][$vatValue]['total_price_ex_vat'] = $shippingExVAT;
                $basketInfo['additional_info']['shipping_items'][$vatValue]['total_price_inc_vat'] = $shippingIncVAT;
                $basketInfo['additional_info']['shipping_items'][$vatValue]['total_price_vat'] = ( $shippingIncVAT - $shippingExVAT );
            }
            else
            {
                $basketInfo['additional_info']['shipping_items'][$vatValue]['total_price_ex_vat'] += $shippingExVAT;
                $basketInfo['additional_info']['shipping_items'][$vatValue]['total_price_inc_vat'] += $shippingIncVAT;
                $basketInfo['additional_info']['shipping_items'][$vatValue]['total_price_vat'] += ( $shippingIncVAT - $shippingExVAT );
            }

            if ( !isset( $basketInfo['additional_info']['shipping_total']['total_price_ex_vat'] ) )
            {
                $basketInfo['additional_info']['shipping_total']['total_price_ex_vat'] = $shippingExVAT;
                $basketInfo['additional_info']['shipping_total']['total_price_inc_vat'] = $shippingIncVAT;
                $basketInfo['additional_info']['shipping_total']['total_price_vat'] = ( $shippingIncVAT - $shippingExVAT );
            }
            else
            {
                $basketInfo['additional_info']['shipping_total']['total_price_ex_vat'] += $shippingExVAT;
                $basketInfo['additional_info']['shipping_total']['total_price_inc_vat'] += $shippingIncVAT;
                $basketInfo['additional_info']['shipping_total']['total_price_vat'] += ( $shippingIncVAT - $shippingExVAT );
            }
        }

        if ( count( $additionalShippingValues['shipping_vat_list'] ) > 0 )
        {
            $returnValue = true;
        }

        return $returnValue;
    }