/** * Iterates through basket items and calculates its prices and discounts * * @return null */ protected function _calcItemsPrice() { // resetting $this->setSkipDiscounts(false); $this->_iProductsCnt = 0; // count different types $this->_dItemsCnt = 0; // count of item units $this->_dWeight = 0; // basket weight // resetting $this->_aItemDiscounts = array(); $this->_oProductsPriceList = oxNew('oxpricelist'); $this->_oDiscountProductsPriceList = oxNew('oxpricelist'); $this->_oNotDiscountedProductsPriceList = oxNew('oxpricelist'); $oDiscountList = oxDiscountList::getInstance(); foreach ($this->_aBasketContents as $oBasketItem) { $this->_iProductsCnt++; $this->_dItemsCnt += $oBasketItem->getAmount(); $this->_dWeight += $oBasketItem->getWeight(); if (!$oBasketItem->isDiscountArticle() && ($oArticle = $oBasketItem->getArticle())) { $oBasketPrice = $oArticle->getBasketPrice($oBasketItem->getAmount(), $oBasketItem->getSelList(), $this); $oBasketItem->setPrice($oBasketPrice); //P adding product price $this->_oProductsPriceList->addToPriceList($oBasketItem->getPrice()); $oBasketPrice->setBruttoPriceMode(); if (!$oArticle->skipDiscounts() && $this->canCalcDiscounts()) { // apply basket type discounts $aItemDiscounts = $oDiscountList->applyBasketDiscounts($oBasketPrice, $oDiscountList->getBasketItemDiscounts($oArticle, $this, $this->getBasketUser()), $oBasketItem->getAmount()); if (is_array($this->_aItemDiscounts) && is_array($aItemDiscounts)) { $this->_aItemDiscounts = $this->_mergeDiscounts($this->_aItemDiscounts, $aItemDiscounts); } } else { $oBasketItem->setSkipDiscounts(true); $this->setSkipDiscounts(true); } $oBasketPrice->multiply($oBasketItem->getAmount()); //P collect discount values for basket items which are discountable if (!$oArticle->skipDiscounts()) { $this->_oDiscountProductsPriceList->addToPriceList($oBasketPrice); } else { $this->_oNotDiscountedProductsPriceList->addToPriceList($oBasketPrice); $oBasketItem->setSkipDiscounts(true); $this->setSkipDiscounts(true); } } elseif ($oBasketItem->isBundle()) { // if bundles price is set to zero $oPrice = oxNew("oxprice"); $oBasketItem->setPrice($oPrice); } } }
/** * Iterates through basket items and calculates its prices and discounts */ protected function _calcItemsPrice() { // resetting $this->setSkipDiscounts(false); $this->_iProductsCnt = 0; // count different types $this->_dItemsCnt = 0; // count of item units $this->_dWeight = 0; // basket weight $this->_oProductsPriceList = oxNew('oxpricelist'); $this->_oDiscountProductsPriceList = oxNew('oxpricelist'); $this->_oNotDiscountedProductsPriceList = oxNew('oxpricelist'); $oDiscountList = oxRegistry::get("oxDiscountList"); /** @var \oxBasketItem $oBasketItem */ foreach ($this->_aBasketContents as $oBasketItem) { $this->_iProductsCnt++; $this->_dItemsCnt += $oBasketItem->getAmount(); $this->_dWeight += $oBasketItem->getWeight(); if (!$oBasketItem->isDiscountArticle() && ($oArticle = $oBasketItem->getArticle(true))) { $oBasketPrice = $oArticle->getBasketPrice($oBasketItem->getAmount(), $oBasketItem->getSelList(), $this); $oBasketItem->setRegularUnitPrice(clone $oBasketPrice); if (!$oArticle->skipDiscounts() && $this->canCalcDiscounts()) { // apply basket type discounts for item $aDiscounts = $oDiscountList->getBasketItemDiscounts($oArticle, $this, $this->getBasketUser()); reset($aDiscounts); /** @var \oxDiscount $oDiscount */ foreach ($aDiscounts as $oDiscount) { $oBasketPrice->setDiscount($oDiscount->getAddSum(), $oDiscount->getAddSumType()); } $oBasketPrice->calculateDiscount(); } else { $oBasketItem->setSkipDiscounts(true); $this->setSkipDiscounts(true); } $oBasketItem->setPrice($oBasketPrice); $this->_oProductsPriceList->addToPriceList($oBasketItem->getPrice()); //P collect discount values for basket items which are discountable if (!$oArticle->skipDiscounts()) { $this->_oDiscountProductsPriceList->addToPriceList($oBasketItem->getPrice()); } else { $this->_oNotDiscountedProductsPriceList->addToPriceList($oBasketItem->getPrice()); $oBasketItem->setSkipDiscounts(true); $this->setSkipDiscounts(true); } } elseif ($oBasketItem->isBundle()) { // if bundles price is set to zero $oPrice = oxNew("oxprice"); $oBasketItem->setPrice($oPrice); } } }
/** * Test data provider * * @return array */ public function getSumOfCostOfAllItemsPayPalBasketDataProvider() { // discounts $oProductsPrice = new oxPriceList(); $oProductsPrice->addToPriceList(new oxPrice(15)); $dPaymentCost = 3; $dWrappingCost = 5; return array(array($oProductsPrice, 0, 0, 0, 15), array($oProductsPrice, $dPaymentCost, $dWrappingCost, 1, 24), array($oProductsPrice, -1 * $dPaymentCost, $dWrappingCost, 9.449999999999999, 29.45)); }