/** * Returns true if this user wishes the delivery on an german island. * @param oxBasket $oBasket * @return bool */ protected function isForB3NIsland(oxBasket $oBasket) { $oUser = $oBasket->getBasketUser(); $sZip = $oUser->oxuser__oxzip->value; if ($oUser->getSelectedAddressId() && ($oAddr = $oUser->getSelectedAddress())) { $sZip = $oAddr->oxaddress__oxzip->value; } // if return $sZip && in_array($sZip, $this->getConfig()->getConfigParam('aB3NGermanIslandZips') ?: array()); }
/** * Detects if current payment was already successfully processed by PayPal * * @param oxBasket $oBasket basket object * * @return bool */ public function isConfirmedByPayPal($oBasket) { $dOldBasketAmount = $this->getSession()->getVariable("oepaypal-basketAmount"); if (!$dOldBasketAmount) { return false; } $oPayPalCheckValidator = oxNew("oePayPalCheckValidator"); $oPayPalCheckValidator->setNewBasketAmount($oBasket->getPrice()->getBruttoPrice()); $oPayPalCheckValidator->setOldBasketAmount($dOldBasketAmount); return $oPayPalCheckValidator->isPayPalCheckValid(); }
/** * @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()); }
/** * 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; }
/** * Check is valid Paymorrow payment method was used in the checkout ir not. * * @param oxBasket $oBasket * * @return bool */ protected function _wasPaymorrowPaymentUsed(oxBasket $oBasket) { /** @var OxpsPaymorrowOxPayment|oxPayment $oPayment */ $oPayment = oxNew('OxpsPaymorrowOxPayment'); if ($oPayment->load($oBasket->getPaymentId()) and $oPayment->isPaymorrowActiveAndMapped()) { return true; } return false; }
/** * 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); }
/** * Finalizes PayPal order. * * @param oePayPalResponseDoExpressCheckoutPayment $oResult PayPal results array. * @param oxBasket $oBasket Basket object. * @param string $sTransactionMode Transaction mode Sale|Authorization. */ public function finalizePayPalOrder($oResult, $oBasket, $sTransactionMode) { $sDate = date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime()); // set order status, transaction ID and payment date to order $this->_setPaymentInfoPayPalOrder($oResult->getTransactionId()); $sCurrency = $oResult->getCurrencyCode(); if (!$sCurrency) { $sCurrency = $this->getOrderCurrency()->name; } //PayPal order info $oPayPalOrder = $this->getPayPalOrder(); $oPayPalOrder->setOrderId($this->getId()); $oPayPalOrder->setPaymentStatus('pending'); $oPayPalOrder->setTransactionMode($sTransactionMode); $oPayPalOrder->setCurrency($sCurrency); $oPayPalOrder->setTotalOrderSum($oBasket->getPrice()->getBruttoPrice()); if ($sTransactionMode == 'Sale') { $oPayPalOrder->setCapturedAmount($oBasket->getPrice()->getBruttoPrice()); } $oPayPalOrder->save(); $oOrderPayment = oxNew('oePayPalOrderPayment'); $oOrderPayment->setTransactionId($oResult->getTransactionId()); $oOrderPayment->setCorrelationId($oResult->getCorrelationId()); $oOrderPayment->setDate($sDate); $oOrderPayment->setAction($sTransactionMode == 'Sale' ? 'capture' : 'authorization'); $oOrderPayment->setStatus($oResult->getPaymentStatus()); $oOrderPayment->setAmount($oResult->getAmount()); $oOrderPayment->setCurrency($oResult->getCurrencyCode()); //Adding payment information $oPaymentList = $this->getPayPalOrder()->getPaymentList(); $oPaymentList->addPayment($oOrderPayment); //setting order payment status after $oPaymentStatusCalculator = oxNew('oePayPalOrderPaymentStatusCalculator'); $oPaymentStatusCalculator->setOrder($this->getPayPalOrder()); $this->getPayPalOrder()->setPaymentStatus($oPaymentStatusCalculator->getStatus()); $this->getPayPalOrder()->save(); //clear PayPal identification $this->getSession()->deleteVariable('oepaypal'); $this->getSession()->deleteVariable("oepaypal-payerId"); $this->getSession()->deleteVariable("oepaypal-userId"); $this->getSession()->deleteVariable('oepaypal-basketAmount'); }
/** * Executes Trusted shops protection order. On failure - * deletes order and returns error code or 6. * * @param oxBasket $oBasket basket object * * @return mixed */ protected function _executeTsProtection(oxBasket $oBasket) { $aValues['tsProductId'] = $this->oxorder__oxtsprotectid->value; $aValues['amount'] = $oBasket->getPrice()->getBruttoPrice(); $oCur = $this->getConfig()->getActShopCurrencyObject(); $aValues['currency'] = $oCur->name; $aValues['buyerEmail'] = $this->oxorder__oxbillemail->value; $aValues['shopCustomerID'] = $this->oxorder__oxuserid->value; $aValues['shopOrderID'] = $this->oxorder__oxordernr->value; $aValues['orderDate'] = $this->oxorder__oxorderdate->value; $sPaymentId = $oBasket->getPaymentId(); $oTsProtection = oxNew('oxtsprotection'); $blRes = $oTsProtection->requestForTsProtection($aValues, $sPaymentId); /*if ( !$blRes ) { $this->delete(); return self::ORDER_STATE_INVALIDTSPROTECTION; }*/ return true; // everything fine }
/** * Sets delivery sets parameters to PayPal callback * * @param oePayPalService $oPayPalService PayPal service. * @param oxDeliverySetList $aDeliverySetList Delivery list. * @param oxUser $oUser User object. * @param oxBasket $oBasket Basket object. * * @return int Total amount of deliveries */ protected function _setDeliverySetListForCallbackResponse($oPayPalService, $aDeliverySetList, $oUser, $oBasket) { $dMaxDeliveryAmount = $this->getPayPalConfig()->getMaxPayPalDeliveryAmount(); $oCur = $this->getConfig()->getActShopCurrencyObject(); $dBasketPrice = $oBasket->getPriceForPayment() / $oCur->rate; $sActShipSet = $oBasket->getShippingId(); $blHasActShipSet = false; $iCnt = 0; // VAT for delivery will be calculated always $fDelVATPercent = $oBasket->getAdditionalServicesVatPercent(); foreach ($aDeliverySetList as $sDelSetId => $sDelSetName) { // checking if PayPal is valid payment for selected delivery set if (!$this->_isPayPalInDeliverySet($sDelSetId, $dBasketPrice, $oUser)) { continue; } $oDeliveryList = oxNew('oxDeliveryList'); $aDeliveryList = array(); // list of active delivery costs if ($oDeliveryList->hasDeliveries($oBasket, $oUser, $this->_getUserShippingCountryId($oUser), $sDelSetId)) { $aDeliveryList = $oDeliveryList->getDeliveryList($oBasket, $oUser, $this->_getUserShippingCountryId($oUser), $sDelSetId); } if (count($aDeliveryList) > 0) { $dPrice = 0; if ($this->getConfig()->getConfigParam('bl_perfLoadDelivery')) { foreach ($aDeliveryList as $oDelivery) { $dPrice += $oDelivery->getDeliveryPrice($fDelVATPercent)->getBruttoPrice(); } } if ($dPrice <= $dMaxDeliveryAmount) { $oPayPalService->setParameter("L_SHIPPINGOPTIONNAME{$iCnt}", getStr()->html_entity_decode($sDelSetName)); $oPayPalService->setParameter("L_SHIPPINGOPTIONLABEL{$iCnt}", oxRegistry::getLang()->translateString("OEPAYPAL_PRICE")); $oPayPalService->setParameter("L_SHIPPINGOPTIONAMOUNT{$iCnt}", $this->_formatFloat($dPrice)); //setting active delivery set if ($sDelSetId == $sActShipSet) { $blHasActShipSet = true; $oPayPalService->setParameter("L_SHIPPINGOPTIONISDEFAULT{$iCnt}", "true"); } else { $oPayPalService->setParameter("L_SHIPPINGOPTIONISDEFAULT{$iCnt}", "false"); } if ($oBasket->isCalculationModeNetto()) { $oPayPalService->setParameter("L_TAXAMT{$iCnt}", $this->_formatFloat($oBasket->getPayPalBasketVatValue())); } else { $oPayPalService->setParameter("L_TAXAMT{$iCnt}", $this->_formatFloat(0)); } } $iCnt++; } } //checking if active delivery set was set - if not, setting first in the list if ($iCnt > 0 && !$blHasActShipSet) { $oPayPalService->setParameter("L_SHIPPINGOPTIONISDEFAULT0", "true"); } return $iCnt; }
/** * 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]); } } } }
/** * Add one item to basket. Handle eventual errors. * * @param oxBasket $basket * @param array $itemData * @param string $errorDestination * * @return null|oxBasketItem */ protected function addItemToBasket($basket, $itemData, $errorDestination) { $basketItem = null; try { $basketItem = $basket->addToBasket($itemData['id'], $itemData['amount'], $itemData['selectList'], $itemData['persistentParameters'], $itemData['override'], $itemData['bundle'], $itemData['oldBasketItemId']); } catch (\OxidEsales\EshopCommunity\Core\Exception\OutOfStockException $exception) { $exception->setDestination($errorDestination); // #950 Change error destination to basket popup if (!$errorDestination && $this->getConfig()->getConfigParam('iNewBasketItemMessage') == 2) { $errorDestination = 'popup'; } oxRegistry::get("oxUtilsView")->addErrorToDisplay($exception, false, (bool) $errorDestination, $errorDestination); } catch (\OxidEsales\EshopCommunity\Core\Exception\ArticleInputException $exception) { //add to display at specific position $exception->setDestination($errorDestination); oxRegistry::get("oxUtilsView")->addErrorToDisplay($exception, false, (bool) $errorDestination, $errorDestination); } catch (\OxidEsales\EshopCommunity\Core\Exception\NoArticleException $exception) { //ignored, best solution F ? } return $basketItem; }
/** * Validates basket. Currently checks if minimum order price > basket price * * @param oxBasket $oBasket basket object * * @return bool */ public function validateBasket($oBasket) { return $oBasket->isBelowMinOrderPrice() ? self::ORDER_STATE_BELOWMINPRICE : null; }
/** * Executes Trusted shops protection order. * * @param oxBasket $oBasket basket object * * @return bool */ protected function _executeTsProtection(oxBasket $oBasket) { $aValues['tsProductId'] = $this->oxorder__oxtsprotectid->value; $aValues['amount'] = $oBasket->getTsInsuredSum(); $oCur = $this->getConfig()->getActShopCurrencyObject(); $aValues['currency'] = $oCur->name; $aValues['buyerEmail'] = $this->oxorder__oxbillemail->value; $aValues['shopCustomerID'] = $this->oxorder__oxuserid->value; $aValues['shopOrderID'] = $this->oxorder__oxordernr->value; $aValues['orderDate'] = $this->oxorder__oxorderdate->value; $sPaymentId = $oBasket->getPaymentId(); /** @var oxTsProtection $oTsProtection */ $oTsProtection = oxNew('oxtsprotection'); $oTsProtection->requestForTsProtection($aValues, $sPaymentId); return true; }
/** * Returns base basket price for payment cost calculations. Price depends on * payment setup (payment administration) * * @param oxBasket $oBasket oxBasket object * * @return double */ public function getBaseBasketPriceForPaymentCostCalc($oBasket) { $dBasketPrice = 0; $iRules = $this->oxpayments__oxaddsumrules->value; // products brutto price if (!$iRules || $iRules & self::PAYMENT_ADDSUMRULE_ALLGOODS) { $dBasketPrice += $oBasket->getProductsPrice()->getSum($oBasket->isCalculationModeNetto()); } // discounts if ((!$iRules || $iRules & self::PAYMENT_ADDSUMRULE_DISCOUNTS) && ($oCosts = $oBasket->getTotalDiscount())) { $dBasketPrice -= $oCosts->getPrice(); } // vouchers if (!$iRules || $iRules & self::PAYMENT_ADDSUMRULE_VOUCHERS) { $dBasketPrice -= $oBasket->getVoucherDiscValue(); } // delivery if ((!$iRules || $iRules & self::PAYMENT_ADDSUMRULE_SHIPCOSTS) && ($oCosts = $oBasket->getCosts('oxdelivery'))) { if ($oBasket->isCalculationModeNetto()) { $dBasketPrice += $oCosts->getNettoPrice(); } else { $dBasketPrice += $oCosts->getBruttoPrice(); } } // wrapping if ($iRules & self::PAYMENT_ADDSUMRULE_GIFTS && ($oCosts = $oBasket->getCosts('oxwrapping'))) { if ($oBasket->isCalculationModeNetto()) { $dBasketPrice += $oCosts->getNettoPrice(); } else { $dBasketPrice += $oCosts->getBruttoPrice(); } } // gift card if ($iRules & self::PAYMENT_ADDSUMRULE_GIFTS && ($oCosts = $oBasket->getCosts('oxgiftcard'))) { if ($oBasket->isCalculationModeNetto()) { $dBasketPrice += $oCosts->getNettoPrice(); } else { $dBasketPrice += $oCosts->getBruttoPrice(); } } return $dBasketPrice; }
/** * 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; }
/** * Deletes user basket object from session and saved one from DB if needed. * * @param oxBasket $oBasket */ protected function emptyBasket($oBasket) { $oBasket->deleteBasket(); }