/** * @param oxBasket $basket */ private function checkContents(\OxidEsales\EshopCommunity\Application\Model\Basket $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]], 'OxidEsales\\EshopCommunity\\Application\\Model\\Article')); $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]], 'OxidEsales\\EshopCommunity\\Application\\Model\\BasketItem')); $basketItem = $basketContents[$keys[0]]; $this->assertEquals($this->testArticleId, $basketItem->getProductId()); $this->assertEquals($expectedAmount, $basketItem->getAmount()); }
/** * compute difference of reserved amounts vs basket items * * @param Basket $oBasket basket object * * @return array */ protected function _basketDifference(\OxidEsales\EshopCommunity\Application\Model\Basket $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; }
/** * Validate loaded from session basket content. Check for language change. * * @param oxBasket $oBasket Basket object loaded from session. * * @return null */ protected function _validateBasket(\OxidEsales\EshopCommunity\Application\Model\Basket $oBasket) { $aCurrContent = $oBasket->getContents(); if (empty($aCurrContent)) { return; } $iCurrLang = oxRegistry::getLang()->getBaseLanguage(); foreach ($aCurrContent as $oContent) { if ($oContent->getLanguageId() != $iCurrLang) { $oContent->setLanguageId($iCurrLang); } } }
/** * Executes payment. Additionally loads oxPaymentGateway object, initiates * it by adding payment parameters (oxPaymentGateway::setPaymentParams()) * and finally executes it (oxPaymentGateway::executePayment()). On failure - * deletes order and returns * error code 2. * * @param Basket $oBasket basket object * @param object $oUserpayment user payment object * * @return integer 2 or an error code */ protected function _executePayment(Basket $oBasket, $oUserpayment) { $oPayTransaction = $this->_getGateway(); $oPayTransaction->setPaymentParams($oUserpayment); if (!$oPayTransaction->executePayment($oBasket->getPrice()->getBruttoPrice(), $this)) { $this->delete(); // checking for error messages if (method_exists($oPayTransaction, 'getLastError')) { if ($sLastError = $oPayTransaction->getLastError()) { return $sLastError; } } // checking for error codes if (method_exists($oPayTransaction, 'getLastErrorNo')) { if ($iLastErrorNo = $oPayTransaction->getLastErrorNo()) { return $iLastErrorNo; } } return self::ORDER_STATE_PAYMENTERROR; // means no authentication } return true; // everything fine }