'Please set other delivery service or try again later.', self::ERROR_TRANSACTION => 'Bad transaction id', self::ERROR_VALIDATE_ITEMS => 'The Product in the Shopping Cart is deleted or not available at the moment. Please remove it and add another one.', self::ERROR_PROMO_INCORRECT => 'The client code entered is incorrect, please try again.', self::ERROR_PROMO_HAS_OTHER => 'Other Client Code already applied.', self::ERROR_PROMO_LOW_AMOUNT => 'The Client Code cannot be applied. The order total must be greater than ${amount}.', self::ERROR_PROMO_NO_PRODUCT => 'This Client Code is tied to products within categories: {categories} Please add it to the Shopping Cart if you want to apply discount.', self::ERROR_PROMO_UNKNOWN_PRODUCT => 'The Client Code is tied to the product that is already removed from the website. Please try another one.', self::ERROR_GIFT_CARD_INCORRECT => 'The gift card code entered is incorrect, please try again.', self::ERROR_OTHER => 'Unknown error.' ); protected $_successMap = array( self::SUCCESS_PROMO => 'Promo code has been applied.', self::SUCCESS_GIFT_CARD => 'Gift Card has been accepted.' ); /** * @var Qs_Session_Namespace */ protected $_session = null; /** * @var App_ECommerce_Cart_Obj */ protected $_cart; /** * Return cart object * * @return App_ECommerce_Cart_Obj */ protected function _getCart() { if (null === $this->_cart) { $this->_cart = new App_ECommerce_Cart_Obj(); $this->_cart->setPrimaryKey($this->_cart->getCartId()); } return $this->_cart; } protected function _getSummaryItem($defaults = array()) { if ($defaults) { /** * пхати тані в сесію, бо багато методів працюють з даними з сесії */ $this->_saveUserDataToSession($defaults); } if (Qs_Request::isXmlHttpRequest()) { /** * при аяксових запитах треба чисити дані, бо при додаванні помо коду * чи гіфт карти вони не попадають в сесію */ $this->_getCart()->clearData(); } $summary = $this->_getCart()->getData(); $userData = $this->_getUserDataFromSession(); $summary = array_merge($summary, $this->_prepareOrderData($userData, false)); /** * що б не виводилась назва шіпінгу на першому кроці чекауту */ unset($summary['shippingNameTitle']); $summary['tpl'] = $this->getTemplate('summary.tpl'); return $summary; } protected function _doGetShippingRate() { $this->_doc->display404(); } protected function _addSippingData(&$data) { $data[self::SHIPPING_SECTION_DATA] = array( 'type' => 'manual', ); return $this; } protected function _doGetShippingRateAjax() { $data = Qs_Request::getPost(); $this->_addSippingData($data); $config = Qs_Application::getConfig('ECommerce_Checkout_')->get('shipping'); $result = array( 'success' => false, 'message' => '', 'total' => 0 ); if (false !== $config && !empty($data[self::SHIPPING_SECTION_DATA])) { $this->_prepareRateAjaxData($data); $rate = $this->_calculateShippingRate($data); if ($rate) { $rateData = $rate->getData(); $result = array( 'success' => $rate->isSuccess(), 'message' => (!$rate->isSuccess() ? $rateData['errorText'] : ''), 'total' => ($rate->isSuccess() ? $rateData['rate']['total'] : 0), 'cartSummary' => $this->_getSummaryItem($data) ); } } $this->_displayJson($result); } protected function _prepareRateAjaxData(&$data) { $type = Qs_Array::get($data[self::SHIPPING_SECTION_DATA], 'type'); if (!empty($type)) { $methodKey = $type . 'Method'; $addressKey = $type . 'AddressType'; $data[self::SHIPPING_SECTION_DATA][$type][$methodKey] = Qs_Array::get($data[self::SHIPPING_SECTION_DATA], $methodKey); if (!empty($data[self::SHIPPING_SECTION_DATA][$addressKey])) { $data[self::SHIPPING_SECTION_DATA][$type][$addressKey] = $data[self::SHIPPING_SECTION_DATA][$addressKey]; } } return $this; } /** * Calculate shipping rate * * @param array $data * @return App_Service_Shipping_ResponseAbstract|bool */ protected function _calculateShippingRate($data) { $shippingMethod = 'manual'; $serviceCode = ''; if (array_key_exists($shippingMethod, $data[self::SHIPPING_SECTION_DATA])) { $serviceCode = $data[self::SHIPPING_SECTION_DATA][$shippingMethod][$shippingMethod . 'Method']; } $shipToSection = ($data['shipping']['asBilling'] == 'y' ? 'billing' : 'shipping'); $shippingOptions = array( 'serviceCode' => $serviceCode, 'shipperState' => App_Settings_Obj::get('senderStateCode'), 'shipperPostalCode' => App_Settings_Obj::get('senderZipCode'), 'shipToState' => $data[$shipToSection]['state'], 'shipToPostalCode' => $data[$shipToSection]['zip'], 'items' => $this->_getCart()->getList(), 'quantity' => $this->_getCart()->getItemsCount() ); $addressKey = $shippingMethod . 'AddressType'; if (!empty($data[self::SHIPPING_SECTION_DATA][$shippingMethod][$addressKey])) { $shippingOptions['addressType'] = $data[self::SHIPPING_SECTION_DATA][$shippingMethod][$addressKey]; } if ($shippingMethod) { /** @var $shipping App_Service_Shipping_Abstract */ $shipping = App_Service_Shipping::factory($shippingMethod, $shippingOptions); $this->_addAdditionalShippingCost($shipping); return $shipping->getRate(); } return false; } protected function _addAdditionalShippingCost($shipping) { /** @var $shipping App_Service_Shipping_Abstract */ $rateData = $shipping->getRate()->getData(); $rateData['rate']['total'] = Zend_Locale_Math::Add( $rateData['rate']['total'], $this->_getShippingPercentageValue($shipping ), 4); $shipping->getRate()->setData($rateData); return $this; } protected function _getTotalForShipping($shipping) { $cart = new App_ECommerce_Cart_Obj(); /** @var $shipping App_Service_Shipping_Abstract */ $cartId = reset($shipping->getOption('items'))['cartId']; $cart->setPrimaryKey($cartId); $cart->setFilter(array('doNotApplyShipping' => 'n')); return (float) $cart->getTotal(); } protected function _getShippingPercentageValue($shipping) { /** @var $shipping App_Service_Shipping_Abstract */ $rateData = $shipping->getRate()->getData(); $shippingPriceObj = new App_ECommerce_ShippingPrice_Admin_Obj(); $percentageValue = Zend_Locale_Math::Mul( $shippingPriceObj->getPercentByPrice($rateData['rate']['total']), $this->_getTotalForShipping($shipping), 4); return Zend_Locale_Math::Div($percentageValue, 100, 4); } /** * Calculate tax for shipping rate. * * @param float $rate * @return float */ protected function _calculateShippingRateTax($rate) { $taxTotal = 0; $taxPercent = (float) App_Settings_Obj::get('orderPriceTax'); if ($this->_hasApplyTax() && $this->_getCart()->getTax(true) > 0) { $taxTotal = Zend_Locale_Math::Div(Zend_Locale_Math::Mul($rate, $taxPercent, 4), 100, 4); } return $taxTotal; } /** * Return has apply tax to cart * * @return bool */ protected function _hasApplyTax() { $userData = $this->_getUserDataFromSession(); $shippingSection = (Qs_Array::get($userData['shipping'], 'asBilling') == 'y' ? 'billing' : 'shipping'); return (bool) ($userData[$shippingSection]['state'] == App_Settings_Obj::get('senderStateCode')); } protected function _prepareSubtotalTax() { $userData = $this->_getUserDataFromSession(); $shippingSection = (Qs_Array::get($userData['shipping'], 'asBilling') == 'y' ? 'billing' : 'shipping'); $recipientZip = $userData[$shippingSection]['zip']; $items = (array) $this->_getCart()->getList(); $subtotalTax = 0; foreach ($items as $item) { $rowSalesTax = 0; if ('y' == $item['applyTax']) { $rowSalesTax = Zend_Locale_Math::Add( $item['rowTax'], $this->_processAdvancedSalesTax($recipientZip, $item['rowTotal']), 4); } $subtotalTax = Zend_Locale_Math::Add($subtotalTax, $rowSalesTax, 4); } return $subtotalTax; } protected function _calculateTax($rowTotal, $taxPercent) { return Zend_Locale_Math::Div(Zend_Locale_Math::Mul($rowTotal, $taxPercent, 4), 100, 4); } protected function _processAdvancedSalesTax($recipientZip, $rowTotal) { $resultTax = 0; $configAdvancedSalesTax = Qs_Application::getConfig('ECommerce_Checkout')->get('advancedSalesTax')->toArray(); foreach ($configAdvancedSalesTax as $type => $taxTypeItem) { if (in_array($recipientZip, $taxTypeItem['zip'])) { $typeTax = $this->_calculateTax($rowTotal, $taxTypeItem['taxPercent']); } else { $typeTax = 0; } $resultTax = Zend_Locale_Math::Add($resultTax, $typeTax, 4); } return $resultTax; } /** * Return prepared order data * * @return array */ protected function _getOrderData() { $preparedOrderData = $this->_prepareOrderData($this->_getUserDataFromSession()); if ($this->_doc->getAuth()->hasIdentity()) { $preparedOrderData['userId'] = $this->_doc->getAuth()->getData('id'); } return $preparedOrderData; } /** * Prepare data for order * * @param array $orderData * @param bool $validate * @return array */ protected function _prepareOrderData($orderData, $validate = true) { $this->_addSippingData($orderData); $preparedData = array(); $preparedData['invoice'] = $this->_getCart()->getPrimaryKey(); $preparedData['tax'] = (!empty($preparedData['tax']) ? $preparedData['tax'] : 0); if (false !== ($shippingPaymentData = $this->_prepareShippingPaymentData($orderData))) { $preparedData = array_merge($preparedData, $shippingPaymentData); } $preparedData['subtotal'] = $this->_getCart()->getTotal(); $preparedData['subtotalTax'] = ($this->_hasApplyTax() ? $this->_prepareSubtotalTax() : 0); $preparedData['total'] = $preparedData['subtotal']; $preparedData['tax'] = 0; /* if subtotalReal < orderMinimumAmount, add to tax subtotalDiffTax */ $orderMinimumAmount = (int) App_Settings_Obj::get('orderMinimumAmount'); $taxPercent = (float) App_Settings_Obj::get('orderPriceTax'); $subtotalReal = $this->_getCart()->getTotal(true); if ($orderMinimumAmount && $subtotalReal < $orderMinimumAmount) { $subtotalDiff = $preparedData['subtotal'] - $subtotalReal; if ($subtotalDiff > 0 && $preparedData['subtotalTax'] > 0 && $taxPercent > 0) { $subtotalDiffTax = Zend_Locale_Math::Div(Zend_Locale_Math::Mul($subtotalDiff, $taxPercent, 4), 100, 4); $preparedData['subtotalTax'] = Zend_Locale_Math::Add($preparedData['subtotalTax'], $subtotalDiffTax, 4); } } if (Qs_Application::getConfig('ECommerce_Checkout_')->get('shipping')) { $preparedData = array_merge($preparedData, $this->_prepareShippingData($orderData, $validate)); } if (Qs_Application::getConfig('ECommerce_Checkout_')->get('payment')) { $preparedData = array_merge($preparedData, $this->_preparePaymentData($orderData)); } $preparedData = array_merge($preparedData, $this->_getCart()->getDiscounts()); if ($preparedData['promo'] > 0) { $preparedData['total'] = Zend_Locale_Math::Sub($preparedData['total'], $preparedData['promo'], 4); } if ($preparedData['giftCard'] > 0) { $preparedData['total'] = Zend_Locale_Math::Sub($preparedData['total'], $preparedData['giftCard'], 4); } $preparedData['tax'] = Zend_Locale_Math::Add($preparedData['tax'], $preparedData['subtotalTax'], 4); if (array_key_exists('shippingTax', $preparedData)) { $preparedData['tax'] = Zend_Locale_Math::Add($preparedData['tax'], $preparedData['shippingTax'], 4); } if (array_key_exists('shippingHandlingTax', $preparedData)) { $preparedData['tax'] = Zend_Locale_Math::Add($preparedData['tax'], $preparedData['shippingHandlingTax'], 4); } $preparedData['tax'] = Zend_Locale_Math::round($preparedData['tax'], 2); if (array_key_exists('shippingHandling', $preparedData)) { $preparedData['total'] = Zend_Locale_Math::Add($preparedData['total'], $preparedData['shippingHandling'], 4); } if (array_key_exists('shippingRate', $preparedData)) { $preparedData['total'] = Zend_Locale_Math::Add($preparedData['total'], $preparedData['shippingRate'], 4); } $preparedData['total'] = Zend_Locale_Math::Add($preparedData['total'], $preparedData['tax'], 4); $preparedData['total'] = Zend_Locale_Math::round($preparedData['total'], 2); return $preparedData; } /** * Prepare shipping and payment customer data * * @param array $orderData * @return array|bool */ protected function _prepareShippingPaymentData($orderData) { if (!is_array($orderData)) { return false; } $preparedData = array(); foreach($orderData as $section => $sectionData) { if ($section == self::SHIPPING_SECTION_DATA || $section == self::PAYMENT_SECTION_DATA) { continue; } if (!is_array($sectionData)) { continue; } foreach ($sectionData as $field => $data) { $orderDataField = $section . ucfirst($field); if ($section == 'shipping') { if ($field != 'asBilling' && Qs_Array::get($orderData['shipping'], 'asBilling') == 'y') { $data = $orderData['billing'][$field]; } } $preparedData[$orderDataField] = $data; } } return (!empty($preparedData) ? $preparedData : false); } /** * Prepare data and calculate shipping * * @param array $orderData * @param bool $validate * @return array */ protected function _prepareShippingData($orderData, $validate = true) { $preparedData = array(); if (empty($orderData) || empty($orderData[self::SHIPPING_SECTION_DATA])) { return $preparedData; } /** @var App_Service_Shipping_ResponseAbstract $shippingRate */ $shippingRate = $this->_calculateShippingRate($orderData); if ($validate && !$shippingRate->isSuccess()) { $this->_setBackError($this->_errorMap[self::ERROR_RATE_CALCULATION]); $this->_setBackError($shippingRate->getDataField('errorText')); $this->_doBack(); } $shippingDetails = $shippingRate->getDataField('serviceDetails'); if ($shippingDetails) { foreach ($shippingDetails as $type => $typeData) { $preparedData['shipping' . ucfirst($type)] = $typeData; } } $shippingForm = new App_ECommerce_Checkout_Form_Service_Shipping(); $shippingTypes = $shippingForm->getShippingType(); $shippingType = $orderData[self::SHIPPING_SECTION_DATA]['type']; $preparedData['shippingNameTitle'] = $shippingTypes[$shippingType]; $preparedData['shippingServiceCodeTitle'] = ''; if (!array_key_exists('shippingServiceCode', $preparedData)) { $preparedData['shippingServiceCode'] = ''; } $shippingServiceCodes = App_Service_Shipping::factory($shippingType)->getServiceCodes(); if (!empty($shippingServiceCodes)) { $serviceCode = Qs_Array::get($preparedData, 'shippingServiceCode', ''); $preparedData['shippingServiceCodeTitle'] = Qs_Array::get($shippingServiceCodes, $serviceCode, ''); } $addressType = null; if (!empty($orderData[self::SHIPPING_SECTION_DATA][$shippingType][$shippingType . 'AddressType'])) { $addressType = $orderData[self::SHIPPING_SECTION_DATA][$shippingType][$shippingType . 'AddressType']; } if (!empty($addressType)) { $preparedData['shippingAddressType'] = $addressType; } $rate = $shippingRate->getDataField('rate'); $rateTax = $this->_calculateShippingRateTax($rate['total']); $preparedData['shippingTax'] = Zend_Locale_Math::round($rateTax, 2); $handling = 0.0; $shippingName = Qs_Array::get($preparedData, 'shippingName'); if ($shippingName) { $handling = (float) App_Settings_Obj::get('deliveryHandling' . $shippingName); } $preparedData['shippingHandling'] = Zend_Locale_Math::round($handling, 2); $handlingTax = $this->_calculateShippingRateTax($handling); $preparedData['shippingHandlingTax'] = Zend_Locale_Math::round($handlingTax, 2); $preparedData['shippingRate'] = $rate['total']; return $preparedData; } /** * Prepare data for payment * * @param array $orderData * @return array */ protected function _preparePaymentData($orderData) { $preparedData = array(); if (!is_array($orderData) || !array_key_exists(self::PAYMENT_SECTION_DATA, $orderData)) { return $preparedData; } $section = 'payment'; $preparedData[$section . 'Type'] = Qs_Array::get($orderData[self::PAYMENT_SECTION_DATA], 'type'); $paymentForm = new App_ECommerce_Checkout_Form_Service_Payment(); $paymentTypes = $paymentForm->getPaymentType(); $paymentType = Qs_Array::get($preparedData, $section . 'Type', ''); $preparedData[$section . 'TypeTitle'] = Qs_Array::get($paymentTypes, $paymentType, ''); if (array_key_exists(self::PAYMENT_SECTION_DATA, $orderData) && array_key_exists('type', $orderData[self::PAYMENT_SECTION_DATA]) && !empty($orderData[self::PAYMENT_SECTION_DATA][$orderData[self::PAYMENT_SECTION_DATA]['type']]) ) { $paymentType = $orderData[self::PAYMENT_SECTION_DATA]['type']; foreach ($orderData[self::PAYMENT_SECTION_DATA][$paymentType] as $field => $value) { if ($field == 'cardNumber') { $value = '**** **** **** *' . substr($value, -3); } $preparedData[$section . ucfirst($field)] = $value; } } return $preparedData; } /** * Return session object * * @param string $sessionName * @return Qs_Session_Namespace */ protected function _getSession($sessionName = null) { if ($sessionName === null) { $sessionName = get_class($this); } if ($this->_session && $this->_session->getNamespace() != $sessionName) { $this->_session = null; } if (null === $this->_session) { $this->_session = new Qs_Session_Namespace($sessionName); } return $this->_session; } /** * Save user data to session * * @param array $data * @return App_ECommerce_Checkout_View */ protected function _saveUserDataToSession($data) { if ($data) { foreach (array('__idItem', 'action', 'id') as $field) { if (array_key_exists($field, $data)) { unset($data[$field]); } } $this->_getSession()->userData = $data; } return $this; } /** * Return user data from session * * @return array */ protected function _getUserDataFromSession() { return $this->_getSession()->userData; } public function unsetUserDataFromSession() { $this->_getSession()->userData = null; return $this; } public function completeOrder() { $transactionId = $this->_getDataObj()->getTransactionId(); if (!empty($transactionId)) { $this->_getDataObj()->saveTransactionId($transactionId); $this->_getCart()->updateTransactionId($transactionId); $this->_getCart()->setAccessCode($transactionId); $this->_setBackUrl(Qs_SiteMap::findFirst( null, array('type' => 'HtmlBlock_'), array('placeholders' => 'ECommerce_Checkout_'), 'url' )); //send mail $this->_getDataObj()->setPrimaryKey($transactionId)->clearData(); $mailData = $this->_getMailData(); $this->sendAdminNotification($mailData, 'Submit'); $this->sendUserNotification($mailData, 'Submit'); //redeem gift cart $this->_redeemGiftCard(); //clear data $this->_getCart()->clearSessionCartObject(); $this->_unsetSession(); } else { $this->_setBackUrl($this->_getCartUrl()); $this->_setBackErrors($this->_errorMap[self::ERROR_TRANSACTION]); } return $this; } protected function _redeemGiftCard() { if ($this->_getCart()->hasGiftCard()) { $giftCode = $this->_getCart()->getData('giftCardCode'); $giftObj = new App_ECommerce_GiftCard_Admin_Obj(); $codeData = $giftObj->getDataByCode($giftCode); if ($codeData['statusId'] != App_ECommerce_GiftCard_Admin_View::CARD_STATUS_REDEEMED) { $giftObj->setPrimaryKey($codeData['id']); $giftObj->update(array('statusId' => App_ECommerce_GiftCard_Admin_View::CARD_STATUS_REDEEMED)); } } return $this; } protected function _getMailData() { $orderData = $this->_getDataObj()->clearData()->getData(); $orderData['orderId'] = $orderData['id']; $cartData = $this->_getCart()->clearData()->getData(); $cartData['cartId'] = $cartData['id']; $mailData = array_merge($cartData, $orderData); return $mailData; } protected function _prepareMailData(array $data) { $priceFields = array('subtotal', 'tax', 'total', 'shippingRate', 'shippingHandling'); foreach (array('giftCard', 'promo') as $field) { if (0 == $data[$field]) { $data[$field] = '-'; } else { $priceFields[] = $field; } } foreach ($priceFields as $field) { if (isset($data[$field])) { $data[$field] = '$' . number_format($data[$field], 2, '.', ','); } } if ($data['promoCodeValue'] && 'percent' == $data['promoCodeType'] && !$data['promoCodeProduct']) { require_once 'Smarty/app_plugins/modifier.money.php'; $data['promo'] .= ' (' . smarty_modifier_money($data['promoCodeValue'], 2, true) . '% off)'; } $data['added'] = date('m/d/Y g:i A', strtotime($data['added'])); unset( $data['giftCardValue'], $data['giftCardCode'], $data['promoCodeMinOrderValue'], $data['promoCodeType'], $data['promoCodeValue'], $data['promoCode'], $data['promoCodeProduct'], $data['changed'], $data['enabled'], $data['id'] ); $orderObj = new App_ECommerce_Order_Obj(); $data['paid'] = $orderObj->getPaidStatusTitle($data['paid']); $data['status'] = $orderObj->getOrderStatusTitle($data['status']); $data['adminAdditionalNote'] = nl2br(htmlspecialchars(Qs_Array::get($data, 'adminAdditionalNote', ''))); $data['userAdditionalNote'] = nl2br(htmlspecialchars(Qs_Array::get($data, 'userAdditionalNote', ''))); $cartView = new App_ECommerce_Order_View(array('doc' => $this->_doc)); $isAdminEmail = (isset($data['isAdminEmail']) && $data['isAdminEmail']); $data['cartItems'] = $cartView->renderOrderCart($data['orderId'], $isAdminEmail); $data['shippingTitle'] = $data['shippingNameTitle']; if ($data['shippingServiceCodeTitle']) { $data['shippingTitle'] .= ' / ' . $data['shippingServiceCodeTitle']; } $data['clientCode'] = $data['promo']; return $data; } /** * Process payment * * @param array $orderData * @param string|null $errorBackUrl * @return App_ECommerce_Checkout_View */ protected function _processPayment($orderData, $errorBackUrl = null) { $data = $this->_getUserDataFromSession(); $additionalData = Qs_Array::get($data[self::PAYMENT_SECTION_DATA], $data[self::PAYMENT_SECTION_DATA]['type']); if (!empty($additionalData)) { $orderData = array_merge($additionalData, $orderData); } $paymentAdapter = $this->_getPaymentAdapter( $data[self::PAYMENT_SECTION_DATA]['type'], $orderData, $this->_getCart()->getList() ); $this->_clearSessionPaymentData(); $paymentAdapter->process(); if (!$paymentAdapter->getProcessResponse()->isSuccess()) { $this->_getDataObj()->cancelTransaction(); if ($errorBackUrl === null) { $errorBackUrl = Qs_SiteMap::findFirst( null, array('type' => 'ECommerce_Checkout_'), array('type' => 'default'), 'url' ); } if ($errorBackUrl) { $this->_setBackUrl($errorBackUrl); } $this->_setBackError($paymentAdapter->getErrors()); $this->_doBack(); } else { $paymentTransactionId = $paymentAdapter->getResponseTransactionId(); if ($paymentTransactionId) { $this->_getDataObj()->update([ 'transactionId' => $paymentAdapter->getResponseTransactionId() ]); } } return $this; } /** * Return adapted for process payment * * @param string $type * @param array $orderData * @param array $cartData * @return App_ECommerce_Checkout_Adapter_Payment_Abstract * @throws Zend_Exception */ protected function _getPaymentAdapter($type, $orderData = array(), $cartData = array()) { $adapterClass = 'App_ECommerce_Checkout_Adapter_Payment_' . ucfirst($type); if (!class_exists($adapterClass)) { $this->_getDataObj()->cancelTransaction(); $this->_setBackUrl($this->_getCartUrl()); $this->_setBackError($this->_errorMap[self::ERROR_OTHER]); $this->_doBack(); } return new $adapterClass($orderData, $cartData); } /** * Clear payment data from session * * @return App_ECommerce_Checkout_View */ protected function _clearSessionPaymentData() { $data = $this->_getUserDataFromSession(); unset($data[self::PAYMENT_SECTION_DATA]); $this->_saveUserDataToSession($data); return $this; } protected function _getCartUrl($type = 'default') { $itemConfig = array(); if (!empty($type)) { $itemConfig['type'] = $type; } return Qs_SiteMap::findFirst(null, array('type' => static::SITEMAP_CART_TYPE), $itemConfig, 'url'); } /** * Clear user session * * @return App_ECommerce_Checkout_View */ protected function _unsetSession() { $this->_getSession()->unsetAll(); return $this; } protected function _doApplyPromoCode() { $this->_doc->display404(); } protected function _doApplyPromoCodeAjax() { $response = array(); $code = Qs_Request::getRequestValue('code'); $result = $this->_getCart()->applyPromoCode($code); if (true === $result) { $response['success'] = true; $response['message'] = $this->_successMap[self::SUCCESS_PROMO]; $response['elementValue'] = $this->_getDiscountDescription('promoCode'); $response['cartSummary'] = $this->_getSummaryItem(); $this->_log(); } else { $response['success'] = false; $response['message'] = (array_key_exists($result, $this->_errorMap)) ? $this->_errorMap[$result] : $this->_errorMap[static::ERROR_OTHER]; if (in_array($result, array(static::ERROR_PROMO_LOW_AMOUNT, static::ERROR_PROMO_NO_PRODUCT))) { $promoObj = new App_ECommerce_Promo_Admin_Obj(); $promo = $promoObj->getDataByCode($code); $placeholders = array( '{amount}' => number_format($promo['minOrderValue'], 2), '{categories}' => $this->_renderProductCategoriesLinks($promo['productCategoryIds']), ); if ($promo['productCategoryIds'] && 'UNKNOWN' == $placeholders['{categories}']) { $response['message'] = $this->_errorMap[static::ERROR_PROMO_UNKNOWN_PRODUCT]; } else { $response['message'] = str_replace( array_keys($placeholders), array_values($placeholders), $response['message'] ); } } } $this->_displayJson($response); } public function _renderProductCategoriesLinks($categoryIds) { $links = null; if (is_array($categoryIds) && count($categoryIds)) { $categories = $this->_getDataObj()->getProductCategory4Select( array('alias', 'title'), array( 'enabled' => 'y', 'typeId' => App_ECommerce_Product_Category_Abstract_Obj::PRODUCT_IN_STOCK_TYPE_ID, 'id IN (?)' => $categoryIds ), array('title') ); if (!$categories) { return 'UNKNOWN'; } $url = Qs_SiteMap::findFirst( null, array('type' => 'ECommerce_Product_Category_'), array('industryType' => ''), 'url' ); $links = '