'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. See details below.', self::ERROR_PROMO_INCORRECT => 'The promo code entered is incorrect, please try again.', self::ERROR_PROMO_HAS_OTHER => 'Other Promo Code already applied.', self::ERROR_PROMO_LOW_AMOUNT => 'The Promo Code cannot be applied. The order subtotal must be greater than ${amount}.', self::ERROR_PROMO_NO_PRODUCT => 'This Promo Code is tied to {product} that\'s not in your Shopping Cart.', self::ERROR_PROMO_UNKNOWN_PRODUCT => 'The Promo Code is tied to the product that is already removed from the website. Please try another one.', self::ERROR_PROMO_NOT_DELETED => 'The Promo Code is no removed.', self::ERROR_GIFT_CARD_INCORRECT => 'The Gift Card code entered is incorrect, please try again.', self::ERROR_GIFT_CARD_NOT_DELETED => 'The Gift Card is no removed.', self::ERROR_OTHER => 'Unknown error.', ]; protected $_successMap = [ self::SUCCESS_PROMO => 'Promo code has been applied.', self::SUCCESS_GIFT_CARD => 'Gift Card has been accepted.', self::PROMO_REMOVED => 'Promo code has been removed.', self::GIFT_REMOVED => 'Gift Card has been removed.', ]; /** * @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 = []) { 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']); $this->_addTemplatePath('ECommerce/Checkout'); $summary['tpl'] = $this->getTemplate('summary.tpl'); return $summary; } protected function _doGetShippingRate() { $this->_doc->display404(); } protected function _doGetShippingRateAjax() { $data = Qs_Request::getPost(); $config = Qs_Application::getConfig('ECommerce_Checkout_')->get('shipping'); $result = [ '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 = [ '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 = Qs_Array::get($data[self::SHIPPING_SECTION_DATA], 'type'); if (!$shippingMethod) { return false; } $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 = [ '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]; } /** @var $shipping App_Service_Shipping_Abstract */ $shipping = App_Service_Shipping::factory($shippingMethod, $shippingOptions); return $shipping->getRate(); } /** * 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() > 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 = (empty($userData['shipping']) || 'y' == Qs_Array::get($userData['shipping'], 'asBilling')) ? 'billing' : 'shipping'; $sippingData = Qs_Array::get($userData, $shippingSection, []); return (Qs_Array::get($sippingData, 'state', '') == App_Settings_Obj::get('senderStateCode')); } /** * 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) { $preparedData = []; $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->_getCart()->getTax() : 0); $preparedData['total'] = $preparedData['subtotal']; $preparedData['tax'] = 0; 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 = []; 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 = []; if (empty($orderData) || empty($orderData[self::SHIPPING_SECTION_DATA])) { return $preparedData; } /** @var App_Service_Shipping_ResponseAbstract $shippingRate */ $shippingRate = $this->_calculateShippingRate($orderData); if (!$shippingRate) { return $preparedData; } 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 = []; 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', ''); if ($paymentType) { $preparedData[$section . 'TypeTitle'] = Qs_Array::get($paymentTypes, $paymentType, ''); } else { $preparedData[$section . 'TypeTitle'] = ''; } 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 (['__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); $itemList = $this->_getCart()->getList(); $groupedList = []; foreach ($itemList as $item) { $groupedList[$item['cartItemType']][] = $item; } foreach ($groupedList as $type => $list) { $itemObj = ItemObjFactory::factory($type); $itemObj->completeItemList($list); } $this->_setBackUrl(Qs_SiteMap::findFirst( null, ['type' => 'HtmlBlock_'], ['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(); // precess membership registrations $this->_processMemberships(); //clear data $this->_getCart()->clearSessionCartObject(); $this->_unsetSession(); } else { $this->_setBackUrl($this->_getCartUrl()); $this->_setBackErrors($this->_errorMap[self::ERROR_TRANSACTION]); } return $this; } protected function _processMemberships() { $items = $this->_getCart()->getList(); $registerObj = new UserRegisterObj(); $registerView = new UserRegisterView(); foreach ($items as $item) { if ('User\\Register\\' == $item['cartItemType']) { $registerObj->clearData(); $registerObj->setPrimaryKey($item['productId']); if ($data = $registerObj->getData()) { $registerObj->setBought(); $registerObj->prepareEmailData($data); $registerView->sendEmail2Admin($data); } } } 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(['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 = ['subtotal', 'tax', 'total', 'shippingRate', 'shippingHandling']; foreach (['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, '.', ','); } } $optionalFields = ['userAdditionalNote', 'adminAdditionalNote']; foreach ($optionalFields as $field) { $data[$field] = (!empty($data[$field])) ? $data[$field] : '-'; } 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(['doc' => $this->_doc]); $data['cartItems'] = $cartView->renderOrderCart($data['orderId']); $data['shippingTitle'] = $data['shippingNameTitle']; if ($data['shippingServiceCodeTitle']) { $data['shippingTitle'] .= ' / ' . $data['shippingServiceCodeTitle']; } $emptyValues = ['shippingFirstName', 'shippingLastName', 'shippingAddress', 'shippingCity']; foreach ($data as $key => &$item) { $item = ('' == $item) ? (in_array($key, $emptyValues) ? '' : '-') : $item; } unset($item); 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, ['type' => 'ECommerce_Checkout_'], ['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 = [], $cartData = []) { $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 = []; if (!empty($type)) { $itemConfig['type'] = $type; } return Qs_SiteMap::findFirst(null, ['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 = []; $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('usePromoCodeStatic'); $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, [static::ERROR_PROMO_LOW_AMOUNT, static::ERROR_PROMO_NO_PRODUCT])) { $promoObj = new App_ECommerce_Promo_Admin_Obj(); $promo = $promoObj->getDataByCode($code); $placeholders = [ '{amount}' => number_format($promo['minOrderValue'], 2), '{product}' => $this->_renderProductLink($promo['productId']), ]; if ('UNKNOWN' == $placeholders['{product}'] && false !== strpos($response['message'], '{product}')) { $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); } protected function _doRemovePromoCode() { $this->_doc->display404(); } protected function _doRemovePromoCodeAjax() { if ($this->_getCart()->removePromoCode()) { $response = [ 'success' => true, 'message' => $this->_successMap[self::PROMO_REMOVED], 'elementValue' => '', 'cartSummary' => $this->_getSummaryItem(), ]; $this->_log(); } else { $response = [ 'success' => false, 'message' => $this->_errorMap[static::ERROR_PROMO_NOT_DELETED], ]; } $this->_displayJson($response); } public function _renderProductLink($productId) { $productObj = new App_ECommerce_Product_Obj(); $productObj->setPrimaryKey($productId); $product = $productObj->getData(); if ($product && 'y' == $product['enabled']) { $url = App_ECommerce_Product_View::getViewUrl(); $link = '' . htmlspecialchars($product['title']) . ''; } else { $link = 'UNKNOWN'; } return $link; } protected function _doApplyGiftCard() { $this->_doc->display404(); } protected function _doApplyGiftCardAjax() { $response = []; $code = Qs_Request::getRequestValue('code'); $result = $this->_getCart()->applyGiftCard($code); $response['success'] = $result; $response['message'] = (!$result) ? $this->_errorMap[self::ERROR_GIFT_CARD_INCORRECT] : $this->_successMap[self::SUCCESS_GIFT_CARD]; if ($result) { $response['elementValue'] = $this->_getDiscountDescription('useGiftCardStatic'); $response['cartSummary'] = $this->_getSummaryItem(); $this->_log(); } $this->_displayJson($response); } protected function _doRemoveGiftCard() { $this->_doc->display404(); } protected function _doRemoveGiftCardAjax() { if ($this->_getCart()->removeGiftCard()) { $response = [ 'success' => true, 'message' => $this->_successMap[self::GIFT_REMOVED], 'elementValue' => '', 'cartSummary' => $this->_getSummaryItem(), ]; $this->_log(); } else { $response = [ 'success' => false, 'message' => $this->_errorMap[static::ERROR_GIFT_CARD_NOT_DELETED], ]; } $this->_displayJson($response); } protected function _getDiscountDescription($field) { $form = $this->_getNewForm(); $element = $form->getSubForm(static::PAYMENT_SECTION_DATA)->getElement($field); if ($element) { return $element->getValue(); } return ''; } protected function _prepareFormData(array &$data) { $paymentType = $data[self::PAYMENT_SECTION_DATA]['type']; if (in_array($paymentType, [self::PAYMENT_TYPE_AUTHORIZE_NET, self::PAYMENT_TYPE_LINK_POINT])) { $paymentData = []; foreach ($data[self::PAYMENT_SECTION_DATA][$paymentType] as $key => $value) { $key = lcfirst(substr($key, strlen($paymentType))); $paymentData[$key] = $value; } $data[self::PAYMENT_SECTION_DATA][$paymentType] = $paymentData; } return $this; } }