_isSponsorAtCart = $isSponsorAtCart; return $this; } /** * 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->_initPersonalInfoFields(); $this->_initPaymentFields(); return $this; } /** * Init base checkout fields * * @return App_ECommerce_Checkout_Form_New */ protected function _initBaseFields() { $this->_initPersonalInfoFields(); return $this; } protected function _initPersonalInfoFields() { $form = new Qs_Form_SubForm(array('legend' => 'Billing Information')); $form->addElement('text', 'firstName', array('label' => 'First Name', 'required' => true)); $form->addElement('text', 'lastName', array('label' => 'Last Name', 'required' => true)); $form->addElement('text', 'address', array('label' => 'Address', 'required' => true)); $form->addElement('text', 'city', array('label' => 'City', 'required' => true)); /** @var \App_Doc_Site $doc */ $doc = \Zend_Registry::get('doc'); if (!$doc->getAuth()->isLoggedIn()) { $form->addElement( 'text', 'email', array( 'label' => 'Email', 'required' => true, 'validators' => array('EmailAddress') ) ); } else{ $form->addElement('hidden', 'email'); } $form->addElement( 'text', 'state', array( 'label' => 'State (code)', 'required' => true, ) ); $form->addElement( 'select', 'countryId', array( 'label' => 'Country', 'required' => true, 'multiOptions' => $this->_getCountries4Select() ) ); $form->addElement('text', 'zip', array('label' => 'Zip Code', 'required' => true)); $this->addSubForm($form, 'billing'); return $this; } protected function _getCountries4Select() { $table = new Qs_Db_Table('DCountry'); return $table->get4Select(array('id', 'title')); } /** * Init fields for payment info * * @return App_ECommerce_Checkout_Form_New */ protected function _initPaymentFields() { $paymentTypes = App_ECommerce_Checkout_Abstract_View::getAvailablePaymentTypesByCart($this->_getCart()); if ($paymentTypes) { $subForm = $this->_getCheckoutSubform('payment', array('paymentTypes' => $paymentTypes)); 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 Promo Code', 'decoration' => 'simple') ); $subForm->addElement('text', 'usePromoCodeValue'); $subForm->getElement('usePromoCodeValue')->getDecorator('HtmlTag')->setOption('class', 'hidden'); $applyButton = $this->getView()->formButton( 'usePromoCodeApply', 'Apply', array('onclick' => 'App_ECommerce_Cart_OtherServices.applyPromoCode(this)') ); $subForm->getElement('usePromoCodeValue') ->getDecorator('ViewHelper') ->setAdditionalHtmlAfterElement($applyButton); $groupElements[] = 'usePromoCode'; $groupElements[] = 'usePromoCodeValue'; } else { $subForm->addElement('static', 'promoCode', array('value' => $cart->renderPromoCodeDescription())); $groupElements[] = 'promoCode'; } } if (Qs_SiteMap::getAliasByItem('ECommerce_GiftCard_Admin_')) { 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('class', 'hidden'); $redeemButton = $this->getView()->formButton( 'useGiftCardApply', 'Redeem Card', array('onclick' => 'App_ECommerce_Cart_OtherServices.applyGiftCard(this)') ); $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 !== ($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 * @param array $options * * @return Qs_Form_SubForm */ protected function _getCheckoutSubform($type, array $options = array()) { $subFormClass = 'App_ECommerce_Checkout_Form_Service_' . ucfirst($type); $form = false; if (class_exists($subFormClass)) { $options['isSponsorAtCart'] = $this->_isSponsorAtCart; $form = new $subFormClass($options); } return $form; } 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'); $doc->addScript('js/noty/jquery.noty.js'); $doc->addScript('js/noty/layouts/top.js'); $doc->addScript('js/noty/themes/default.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); } }