_orderSummary = $orderSummary; } /** * @return array */ public function getOrderSummary() { return $this->_orderSummary; } /** * @var Zend_Config */ protected $_checkoutConfig = null; /** * форма не валідується аяксом * @var bool */ protected $_ajaxValidation = false; /** * Return checkout config * * @return Zend_Config */ protected function _getCheckoutConfig() { if (null === $this->_checkoutConfig) { $this->_checkoutConfig = Qs_Application::getConfig('ECommerce_Checkout'); } return $this->_checkoutConfig; } protected function _initElements() { $this->_initBaseFields(); $this->_initShippingFields(); $this->_initPaymentFields(); $this->_initSummaryInfo(); return $this; } /** * Init fields for shipping info * * @return App_ECommerce_Checkout_Form_New */ protected function _initShippingFields() { if ($this->_getCheckoutConfig()->get('shipping')) { $subForm = $this->_getCheckoutSubform('shipping'); if ($subForm) { $subForm->setAttrib('class', 'hidden'); $this->addSubForm($subForm, App_ECommerce_Checkout_View::SHIPPING_SECTION_DATA); } } return $this; } /** * Init base checkout fields * * @return App_ECommerce_Checkout_Form_New */ protected function _initBaseFields() { parent::_initElements(); foreach ($this->getDisplayGroup('personalInfo')->getElements() as $element) { /** @var $element Zend_Form_Element */ $this->removeElement($element->getName()); } $this->removeDisplayGroup('personalInfo'); return $this; } /** * Init fields for payment info * * @return App_ECommerce_Checkout_Form_New */ protected function _initPaymentFields() { if ($this->_getCheckoutConfig()->get('payment')) { $subForm = $this->_getCheckoutSubform('payment'); if ($subForm) { $this->addSubForm($subForm, App_ECommerce_Checkout_View::PAYMENT_SECTION_DATA); $this->_initDiscountFields(); } } return $this; } /** * Init fields for discount * * @return App_ECommerce_Checkout_Form_New */ protected function _initDiscountFields() { $groupElements = array(); $cart = $this->_getCart(); $subForm = $this->getSubForm(App_ECommerce_Checkout_View::PAYMENT_SECTION_DATA); if (Qs_SiteMap::getAliasByItem('ECommerce_Promo_Admin_')) { if (!$cart->getData('promoCode')) { $subForm->addElement( 'checkbox', 'usePromoCode', array('label' => 'I want to use a Client Code', 'decoration' => 'simple') ); $subForm->addElement('text', 'usePromoCodeValue'); $subForm->getElement('usePromoCodeValue')->getDecorator('HtmlTag')->setOption('style', 'display: none;'); $applyButton = $this->getView()->formButton( 'usePromoCodeApply', 'Apply', array( 'onclick' => 'App_ECommerce_Checkout_OtherServices.applyPromoCode(this)', 'class' => 'btn btn-small' ) ); $subForm->getElement('usePromoCodeValue') ->getDecorator('ViewHelper') ->setAdditionalHtmlAfterElement($applyButton); $groupElements[] = 'usePromoCode'; $groupElements[] = 'usePromoCodeValue'; } else { $subForm->addElement('static', 'promoCode', array('value' => $cart->renderPromoCodeDescription())); $groupElements[] = 'promoCode'; } } /** @var App_Doc_Site $doc */ $doc = Zend_Registry::get('doc'); if ($this->getConfig('enableUseGiftCard') && Qs_SiteMap::getAliasByItem('ECommerce_GiftCard_Admin_') && $doc->getAuth()->isLoggedIn() ) { if (!$cart->getData('giftCardCode')) { $subForm->addElement( 'checkbox', 'useGiftCard', array('label' => 'I want to use a Gift Card', 'decoration' => 'simple') ); $subForm->addElement('text', 'useGiftCardValue'); $subForm->getElement('useGiftCardValue')->getDecorator('HtmlTag')->setOption('style', 'display: none;'); $redeemButton = $this->getView()->formButton( 'useGiftCardApply', 'Redeem', array( 'onclick' => 'App_ECommerce_Checkout_OtherServices.applyGiftCard(this)', 'class' => 'btn btn-small' ) ); $subForm->getElement('useGiftCardValue') ->getDecorator('ViewHelper') ->setAdditionalHtmlAfterElement($redeemButton); $groupElements[] = 'useGiftCard'; $groupElements[] = 'useGiftCardValue'; } else { $subForm->addElement('static', 'giftCardCode', array('value' => $cart->renderGiftCardDescription())); $groupElements[] = 'giftCardCode'; } } if (!empty($groupElements)) { $subForm->addDisplayGroup($groupElements, 'additionalGroup'); } return $this; } public function setDefaults(array $defaults = array()) { parent::setDefaults($defaults); if (null !== ($serviceShippingSubForm = $this->getSubForm(App_ECommerce_Checkout_View::SHIPPING_SECTION_DATA))) { /** @var $serviceShippingSubForm App_ECommerce_Checkout_Form_Service_Shipping */ $serviceShippingSubForm->reinitData($this->_getData()); } if (null !== ($servicePaymentSubForm = $this->getSubForm(App_ECommerce_Checkout_View::PAYMENT_SECTION_DATA))) { /** @var $servicePaymentSubForm App_ECommerce_Checkout_Form_Service_Payment */ $servicePaymentSubForm->reinitData($this->_getData()); } return $this; } protected function _initButtons() { parent::_initButtons(); $this->getElement('btnSubmit')->setLabel('Continue Checkout'); $this->removeElement('btnCancel'); return $this; } /** * Return subform for checkout * * @param string $type * @return Qs_Form_SubForm */ protected function _getCheckoutSubform($type) { $subFormClass = 'App_ECommerce_Checkout_Form_Service_' . ucfirst($type); $form = false; if (class_exists($subFormClass)) { $form = new $subFormClass(); } return $form; } protected function _initSummaryInfo() { $item = new Qs_Doc_Item($this->getOrderSummary()); Qs_Smarty_Text::setTemplate(file_get_contents($item->tpl)); $summary = Qs_Smarty_Text::render(array('item' => $item)); $this->addElement('static', 'orderTotal', array('value' => $summary)); $this->getElement('orderTotal')->getDecorator('Label')->setTagOption('class', 'hidden'); $this->addDisplayGroup(array('orderTotal'), 'orderSummary', array('legend' => 'Order Summary')); return $this; } public function render(Zend_View_Interface $view = null) { /** @var $doc App_Doc_Admin */ $doc = Zend_Registry::get('doc'); $doc->addScript('js/app/ECommerce/checkout.js'); $params = array($this->getId()); $doc->addInitFunction('App_ECommerce_Checkout.init', $params); $params = array(App_ECommerce_Checkout_View::PAYMENT_SECTION_DATA . '-additionalGroup-element'); $doc->addInitFunction('App_ECommerce_Checkout_OtherServices.init', $params); return parent::render($view); } }