_orderSummary = $orderSummary; } /** * @return array */ public function getOrderSummary() { return $this->_orderSummary; } /** * 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->_initPaymentFields(); $this->_initSummaryInfo(); return $this; } protected function _getCart() { return App_ECommerce_Cart_Obj::getInstance(); } /** * "Address" fields for "simple" mode * @param string $type * @param bool $isRequired * @return $this */ protected function _initAddressFields($type, $isRequired = true) { $form = new AddressForm(['legend' => ucfirst($type) . ' Address', 'type' => $type]); if (Entity::ADDRESS_SHIPPING == $type && !$this->_getCart()->hasShippableItems()) { $form->addElement( 'static', 'noShippingAddress', ['value' => $this->getDoc()->getSmarty()->fetch('ECommerce/Checkout/noShippingMessage.tpl')] ); $this->addSubForm($form, $type); return $this; } if ($type != Entity::ADDRESS_BILLING) { $form->addElement( 'checkbox', 'asBilling', array('label' => 'My shipping address is the same as my billing address', 'decoration' => 'simple') ); } $form->addElement('text', 'firstName', array('label' => 'First Name')); $form->addElement('text', 'lastName', array('label' => 'Last Name')); $form->addElement('text', 'address', array('label' => 'Address')); $form->addElement('text', 'address2', array('label' => 'Address 2')); $form->addElement('text', 'city', array('label' => 'City', 'class' => 'city')); $form->addElement( 'select', 'state', array( 'label' => 'State', 'class' => 'state', 'multiOptions' => array('' => 'Select One') + State::getGrouped4Select() ) ); $form->addElement('zip', 'zip', array('label' => 'Zip Code', 'class' => 'zip')); //Remove PostCode validator to allow USA and CAN states $form->getElement('zip')->removeValidator('PostCode'); if ($isRequired) { /** @var $element \Zend_Form_Element */ $element = null; if ($type == Entity::ADDRESS_BILLING) { foreach ($form as $element) { if ('address2' != $element->getName()) { $element->setRequired(); } } } else { $asBilling = $this->_getData($type . '[asBilling]'); foreach ($form as $element) { if ('asBilling' == $element->getName()) { continue; } if ($asBilling && 'n' == $asBilling) { $element->setRequired(); } else { $element->getDecorator('Label')->setOption('class', 'required'); } } } } $this->addSubForm($form, $type); return $this; } /** * Init base checkout fields * * @return App_ECommerce_Checkout_Form_New */ protected function _initBaseFields() { $this->_initAddressFields(Entity::ADDRESS_BILLING); // additional billing email field $billingForm = $this->getSubForm('billing'); $billingForm->addElement( 'email', 'email', array('label' => 'Email Address', 'required' => true, 'attribs' => array('autocomplete' => 'off')) ); $billingForm->addElement( 'phone', 'phone', array('label' => 'Phone Number', 'attribs' => array('autocomplete' => 'off')) ); 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) { $this->addSubForm($subForm, App_ECommerce_Checkout_View::SHIPPING_SECTION_DATA); } } return $this; } /** * Init fields for payment info * * @return App_ECommerce_Checkout_Form_New */ protected function _initPaymentFields() { if (\App\ECommerce\Checkout\Model::getPaymentTypes()) { $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_')) { $hasPromo = (bool) $cart->getData('promoCode'); $subForm->addElement( 'checkbox', 'usePromoCode', array('label' => 'I want to use a Promo Code', 'decoration' => 'simple') ); $groupElements[] = 'usePromoCode'; if ($hasPromo) { /** @var Qs_Form_Decorator_DtDdWrapper $dtDdWrapper */ $dtDdWrapper = $subForm->getElement('usePromoCode')->getDecorator('DtDdWrapper'); $dtDdWrapper->setDdAttrib('style', 'display: none;'); } $subForm->addElement('text', 'usePromoCodeValue'); $groupElements[] = '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); $subForm->addElement('static', 'usePromoCodeStatic', array('value' => '')); $groupElements[] = 'usePromoCodeStatic'; if ($hasPromo) { $staticValue = $cart->renderPromoCodeDescription(); $staticValue .= 'remove'; $subForm->getElement('usePromoCodeStatic')->setValue($staticValue); } else { /** @var Qs_Form_Decorator_HtmlTag $dtDdWrapper */ $dtDdWrapper = $subForm->getElement('usePromoCodeStatic')->getDecorator('HtmlTag'); $dtDdWrapper->setOption('style', 'display: none;'); } } /** @var App_Doc_Site $doc */ $doc = Zend_Registry::get('doc'); if (Qs_SiteMap::getAliasByItem('ECommerce_GiftCard_Admin_') && $doc->getAuth()->isLoggedIn()) { $hasGift = (bool) $cart->getData('giftCardCode'); $subForm->addElement( 'checkbox', 'useGiftCard', array('label' => 'I want to use a Gift Card', 'decoration' => 'simple') ); $groupElements[] = 'useGiftCard'; if ($hasGift) { /** @var Qs_Form_Decorator_DtDdWrapper $dtDdWrapper */ $dtDdWrapper = $subForm->getElement('useGiftCard')->getDecorator('DtDdWrapper'); $dtDdWrapper->setDdAttrib('style', 'display: none;'); } $subForm->addElement('text', 'useGiftCardValue'); $groupElements[] = 'useGiftCardValue'; $subForm->getElement('useGiftCardValue')->getDecorator('HtmlTag')->setOption('style', 'display: none;'); $redeemButton = $this->getView()->formButton( 'useGiftCardApply', 'Redeem Card', array( 'onclick' => 'App_ECommerce_Checkout_OtherServices.applyGiftCard(this)', 'class' => 'btn btn-small' ) ); $subForm->getElement('useGiftCardValue') ->getDecorator('ViewHelper') ->setAdditionalHtmlAfterElement($redeemButton); $subForm->addElement('static', 'useGiftCardStatic', array('value' => '')); $groupElements[] = 'useGiftCardStatic'; /** @var Qs_Form_Decorator_HtmlTag $dtDdWrapper */ $dtDdWrapper = $subForm->getElement('useGiftCardStatic')->getDecorator('HtmlTag'); $dtDdWrapper->setOption('style', 'display: none;'); } 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(['orderSummary' => $this->getOrderSummary()]); } return $form; } protected function _initSummaryInfo() { $summary = $this->getOrderSummary(); $item = new Qs_Doc_Item($summary); if (!empty($summary['taxCloudErrors'])) { $this->getSubForm('billing')->addErrors($summary['taxCloudErrors']); } 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/lib/form.js'); $doc->addScript('js/app/ECommerce/checkout.js'); $options = $this->getScriptOptions() + array('orderTotal' => $this->getOrderSummary()['total']) + ['noPaymentMessage' => $this->getDoc()->getSmarty()->fetch('ECommerce/Checkout/noPaymentMessage.tpl')]; $params = array( $this->getId(), $options ); $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); } /** * @return AddressForm */ public function getDestinationAddressForm() { return $this->getSubForm('billing'); } }