/** * @param oxBasket $basket */ private function checkContents(oxBasket $basket, $expectedAmount) { $basketArticles = $basket->getBasketArticles(); $keys = array_keys($basketArticles); $this->assertTrue(is_array($basketArticles)); $this->assertEquals(1, count($basketArticles)); $this->assertTrue(is_a($basketArticles[$keys[0]], 'oxArticle')); $this->assertEquals($this->testArticleId, $basketArticles[$keys[0]]->getId()); $basketContents = $basket->getContents(); $keys = array_keys($basketContents); $this->assertTrue(is_array($basketContents)); $this->assertEquals(1, count($basketArticles)); $this->assertTrue(is_a($basketContents[$keys[0]], 'oxBasketItem')); $basketItem = $basketContents[$keys[0]]; $this->assertEquals($this->testArticleId, $basketItem->getProductId()); $this->assertEquals($expectedAmount, $basketItem->getAmount()); }
/** * Checks if delivery fits for current basket * * @param oxBasket $oBasket shop basket * * @return bool */ public function isForBasket($oBasket) { // amount for conditional check $blHasArticles = $this->hasArticles(); $blHasCategories = $this->hasCategories(); $blUse = true; $iAmount = 0; $blForBasket = false; // category & article check if ($blHasCategories || $blHasArticles) { $blUse = false; $aDeliveryArticles = $this->getArticles(); $aDeliveryCategories = $this->getCategories(); foreach ($oBasket->getContents() as $oContent) { //V FS#1954 - load delivery for variants from parent article $oArticle = $oContent->getArticle(false); $sProductId = $oArticle->getProductId(); $sParentId = $oArticle->getParentId(); if ($blHasArticles && (in_array($sProductId, $aDeliveryArticles) || $sParentId && in_array($sParentId, $aDeliveryArticles))) { $blUse = true; $iArtAmount = $this->getDeliveryAmount($oContent); if ($this->getCalculationRule() != self::CALCULATION_RULE_ONCE_PER_CART) { if ($this->_isForArticle($oContent, $iArtAmount)) { $blForBasket = true; } } if (!$blForBasket) { $iAmount += $iArtAmount; } } elseif ($blHasCategories) { if (isset(self::$_aProductList[$sProductId])) { $oProduct = self::$_aProductList[$sProductId]; } else { $oProduct = oxNew('oxArticle'); $oProduct->setSkipAssign(true); if (!$oProduct->load($sProductId)) { continue; } $oProduct->setId($sProductId); self::$_aProductList[$sProductId] = $oProduct; } foreach ($aDeliveryCategories as $sCatId) { if ($oProduct->inCategory($sCatId)) { $blUse = true; $iArtAmount = $this->getDeliveryAmount($oContent); if ($this->getCalculationRule() != self::CALCULATION_RULE_ONCE_PER_CART) { if ($this->_isForArticle($oContent, $iArtAmount)) { $blForBasket = true; } } if (!$blForBasket) { $iAmount += $iArtAmount; } //HR#5650 product might be in multiple rule categories, counting it once is enough break; } } } } } else { // regular amounts check foreach ($oBasket->getContents() as $oContent) { $iArtAmount = $this->getDeliveryAmount($oContent); if ($this->getCalculationRule() != self::CALCULATION_RULE_ONCE_PER_CART) { if ($this->_isForArticle($oContent, $iArtAmount)) { $blForBasket = true; } } if (!$blForBasket) { $iAmount += $iArtAmount; } } } /* if ( $this->getConditionType() == self::CONDITION_TYPE_PRICE ) { $iAmount = $oBasket->_getDiscountedProductsSum(); }*/ //#M1130: Single article in Basket, checked as free shipping, is not buyable (step 3 no payments found) if (!$blForBasket && $blUse && ($this->_checkDeliveryAmount($iAmount) || $this->_blFreeShipping)) { $blForBasket = true; } return $blForBasket; }
/** * Validate loaded from session basket content. Check for language change. * * @param oxBasket $oBasket Basket object loaded from session. * * @return null */ protected function _validateBasket(oxBasket $oBasket) { $aCurrContent = $oBasket->getContents(); if (empty($aCurrContent)) { return; } $iCurrLang = oxRegistry::getLang()->getBaseLanguage(); foreach ($aCurrContent as $oContent) { if ($oContent->getLanguageId() != $iCurrLang) { $oContent->setLanguageId($iCurrLang); } } }
/** * compute difference of reserved amounts vs basket items * * @param oxBasket $oBasket basket object * * @return array */ protected function _basketDifference(oxBasket $oBasket) { $aDiff = $this->_getReservedItems(); // refreshing history foreach ($oBasket->getContents() as $oItem) { $sProdId = $oItem->getProductId(); if (!isset($aDiff[$sProdId])) { $aDiff[$sProdId] = -$oItem->getAmount(); } else { $aDiff[$sProdId] -= $oItem->getAmount(); } } return $aDiff; }
/** * Sets basket information to Emos. * Uses username (email address) instead of customer number. * * @param Emos $oEmos * @param oxUser $oUser * @param oxOrder $oOrder * @param oxBasket $oBasket */ private function _setBasketInformation($oEmos, $oUser, $oOrder, $oBasket) { $oConfig = $this->getConfig(); $oCur = $oConfig->getActShopCurrencyObject(); $oEmos->addEmosBillingPageArray($this->_convertToUtf($oOrder->oxorder__oxordernr->value), $this->_convertToUtf($oUser->oxuser__oxusername->value), $oBasket->getPrice()->getBruttoPrice() * (1 / $oCur->rate), $this->_convertToUtf($oOrder->oxorder__oxbillcountry->value), $this->_convertToUtf($oOrder->oxorder__oxbillzip->value), $this->_convertToUtf($oOrder->oxorder__oxbillcity->value)); // get Basket Page Array $aBasket = array(); $aBasketProducts = $oBasket->getContents(); foreach ($aBasketProducts as $oContent) { /** @var oxBasketItem $oContent */ $sId = $oContent->getProductId(); /** @var oxArticle $oProduct */ $oProduct = oxNew('oxArticle'); $oProduct->load($sId); $sPath = $this->_getBasketProductCatPath($oProduct); $aBasket[] = $this->_convProd2EmosItem($oProduct, $sPath, $oContent->getAmount()); } $oEmos->addEmosBasketPageArray($aBasket); }
/** * Sets basket wrapping * * @param oxBasket $oBasket * @param array $aWrapping */ protected function _setWrappingInfo($oBasket, $aWrapping) { if (is_array($aWrapping) && count($aWrapping)) { foreach ($oBasket->getContents() as $sKey => $oBasketItem) { if (isset($aWrapping[$sKey])) { $oBasketItem->setWrapping($aWrapping[$sKey]); } } } }
/** * Gathers and assigns to new oxOrder object customer data, payment, delivery * and shipping info, customer order remark, currency, voucher, language data. * Additionally stores general discount and wrapping. Sets order status to "error" * and creates oxOrderArticle objects and assigns to them basket articles. * * @param oxBasket $oBasket Shopping basket object */ protected function _loadFromBasket(oxBasket $oBasket) { $myConfig = $this->getConfig(); // store IP Address - default must be FALSE as it is illegal to store if ($myConfig->getConfigParam('blStoreIPs') && $this->oxorder__oxip->value === null) { $this->oxorder__oxip = new oxField(oxRegistry::get("oxUtilsServer")->getRemoteAddress(), oxField::T_RAW); } //setting view mode $this->oxorder__oxisnettomode = new oxField($oBasket->isCalculationModeNetto()); // copying main price info $this->oxorder__oxtotalnetsum = new oxField($oBasket->getNettoSum()); $this->oxorder__oxtotalbrutsum = new oxField($oBasket->getBruttoSum()); $this->oxorder__oxtotalordersum = new oxField($oBasket->getPrice()->getBruttoPrice(), oxField::T_RAW); // copying discounted VAT info $this->_resetVats(); $iVatIndex = 1; foreach ($oBasket->getProductVats(false) as $iVat => $dPrice) { $this->{"oxorder__oxartvat{$iVatIndex}"} = new oxField($this->_convertVat($iVat), oxField::T_RAW); $this->{"oxorder__oxartvatprice{$iVatIndex}"} = new oxField($dPrice, oxField::T_RAW); $iVatIndex++; } // payment costs if available if ($oPaymentCost = $oBasket->getCosts('oxpayment')) { $this->oxorder__oxpaycost = new oxField($oPaymentCost->getBruttoPrice(), oxField::T_RAW); $this->oxorder__oxpayvat = new oxField($oPaymentCost->getVAT(), oxField::T_RAW); } // delivery info if ($oDeliveryCost = $oBasket->getCosts('oxdelivery')) { $this->oxorder__oxdelcost = new oxField($oDeliveryCost->getBruttoPrice(), oxField::T_RAW); //V #M382: Save VAT, not VAT value for delivery costs $this->oxorder__oxdelvat = new oxField($oDeliveryCost->getVAT(), oxField::T_RAW); //V #M382 $this->oxorder__oxdeltype = new oxField($oBasket->getShippingId(), oxField::T_RAW); } // user remark if (!isset($this->oxorder__oxremark) || $this->oxorder__oxremark->value === null) { $this->oxorder__oxremark = new oxField(oxRegistry::getSession()->getVariable('ordrem'), oxField::T_RAW); } // currency $oCur = $myConfig->getActShopCurrencyObject(); $this->oxorder__oxcurrency = new oxField($oCur->name); $this->oxorder__oxcurrate = new oxField($oCur->rate, oxField::T_RAW); // store voucher discount if ($oVoucherDiscount = $oBasket->getVoucherDiscount()) { $this->oxorder__oxvoucherdiscount = new oxField($oVoucherDiscount->getBruttoPrice(), oxField::T_RAW); } // general discount if ($this->_blReloadDiscount) { $dDiscount = 0; $aDiscounts = $oBasket->getDiscounts(); if (count($aDiscounts) > 0) { foreach ($aDiscounts as $oDiscount) { $dDiscount += $oDiscount->dDiscount; } } $this->oxorder__oxdiscount = new oxField($dDiscount, oxField::T_RAW); } //order language $this->oxorder__oxlang = new oxField($this->getOrderLanguage()); // initial status - 'ERROR' $this->oxorder__oxtransstatus = new oxField('ERROR', oxField::T_RAW); // copies basket product info ... $this->_setOrderArticles($oBasket->getContents()); // copies wrapping info $this->_setWrapping($oBasket); // copies TS protection info $this->_setTsProtection($oBasket); }