/** * Return form attributes * * @return array */ protected function getFormAttributes() { $list = parent::getFormAttributes(); $deferred = $this->shouldDeferLoad(); $list['data-deferred'] = $deferred ? 'true' : 'false'; return $list; }
/** * Get validator * * @return \XLite\Core\Validator\HashArray */ protected function getValidator() { $validator = parent::getValidator(); $validator->addPair('email', new \XLite\Core\Validator\String\Email(), \XLite\Core\Validator\Pair\APair::SOFT); $validator->addPair('create_profile', new \XLite\Core\Validator\String\Switcher(), \XLite\Core\Validator\Pair\APair::SOFT); $validator->addPair('same_address', new \XLite\Core\Validator\String\Switcher(), \XLite\Core\Validator\Pair\APair::SOFT); $onlyCalculate = (bool) \XLite\Core\Request::getInstance()->only_calculate; $mode = $onlyCalculate ? \XLite\Core\Validator\Pair\APair::SOFT : \XLite\Core\Validator\Pair\APair::STRICT; $nonEmpty = !$onlyCalculate; // Shipping address $shippingAddress = $validator->addPair('shippingAddress', new \XLite\Core\Validator\HashArray(), \XLite\Core\Validator\Pair\APair::SOFT); $shippingAddress->addPair('name', new \XLite\Core\Validator\String($nonEmpty), $mode); $shippingAddress->addPair('street', new \XLite\Core\Validator\String($nonEmpty), $mode); $shippingAddress->addPair('city', new \XLite\Core\Validator\String($nonEmpty), $mode); $shippingAddress->addPair('zipcode', new \XLite\Core\Validator\String(true)); $shippingAddress->addPair('phone', new \XLite\Core\Validator\String(), $mode); $shippingAddress->addPair(new \XLite\Core\Validator\Pair\CountryState()); $shippingAddress->addPair('save_as_new', new \XLite\Core\Validator\String\Switcher(), \XLite\Core\Validator\Pair\APair::SOFT); // Billing address if (!\XLite\Core\Request::getInstance()->same_address) { $billingAddress = $validator->addPair('billingAddress', new \XLite\Core\Validator\HashArray(), \XLite\Core\Validator\Pair\APair::SOFT); $billingAddress->addPair('name', new \XLite\Core\Validator\String(true)); $billingAddress->addPair('street', new \XLite\Core\Validator\String(true)); $billingAddress->addPair('city', new \XLite\Core\Validator\String(true)); $billingAddress->addPair('zipcode', new \XLite\Core\Validator\String(true)); $billingAddress->addPair('phone', new \XLite\Core\Validator\String()); $billingAddress->addPair(new \XLite\Core\Validator\Pair\CountryState()); $billingAddress->addPair('save_as_new', new \XLite\Core\Validator\String\Switcher(), \XLite\Core\Validator\Pair\APair::SOFT); } return $validator; }
/** * Get validator * * @return \XLite\Core\Validator\HashArray */ protected function getValidator() { $validator = parent::getValidator(); $validator->addPair('email', new \XLite\Core\Validator\String\Email(), \XLite\Core\Validator\Pair\APair::SOFT); $validator->addPair('password', new \XLite\Core\Validator\String(), \XLite\Core\Validator\Pair\APair::SOFT); $validator->addPair('create_profile', new \XLite\Core\Validator\String\Switcher(), \XLite\Core\Validator\Pair\APair::SOFT); $validator->addPair('guest_agree', new \XLite\Core\Validator\String\Switcher(), \XLite\Core\Validator\Pair\APair::SOFT); $validator->addPair('same_address', new \XLite\Core\Validator\String\Switcher(), \XLite\Core\Validator\Pair\APair::SOFT); $onlyCalculate = (bool) \XLite\Core\Request::getInstance()->only_calculate; $mode = $onlyCalculate ? \XLite\Core\Validator\Pair\APair::SOFT : \XLite\Core\Validator\Pair\APair::STRICT; $nonEmpty = !$onlyCalculate; // Shipping address $shippingAddress = $validator->addPair('shippingAddress', new \XLite\Core\Validator\HashArray(), \XLite\Core\Validator\Pair\APair::SOFT); $addressFields = \XLite::getController()->getAddressFields(); $isCountryStateAdded = false; foreach ($addressFields as $fieldName => $fieldData) { if (in_array($fieldName, array('country_code', 'state_id'))) { if (!$isCountryStateAdded) { $shippingAddress->addPair(new \XLite\Core\Validator\Pair\CountryState()); $isCountryStateAdded = true; } } else { $mode = $onlyCalculate || !$fieldData[\XLite\View\Model\Address\Address::SCHEMA_REQUIRED] ? \XLite\Core\Validator\Pair\APair::SOFT : \XLite\Core\Validator\Pair\APair::STRICT; $shippingAddress->addPair($fieldName, new \XLite\Core\Validator\String($nonEmpty && $fieldData[\XLite\View\Model\Address\Address::SCHEMA_REQUIRED]), $mode); } } $shippingAddress->addPair('save_in_book', new \XLite\Core\Validator\String\Switcher(), \XLite\Core\Validator\Pair\APair::SOFT); // Billing address if (!\XLite\Core\Request::getInstance()->same_address) { $billingAddress = $validator->addPair('billingAddress', new \XLite\Core\Validator\HashArray(), \XLite\Core\Validator\Pair\APair::SOFT); $isCountryStateAdded = false; foreach ($addressFields as $fieldName => $fieldData) { if (in_array($fieldName, array('country_code', 'state_id'))) { if (!$isCountryStateAdded) { $billingAddress->addPair(new \XLite\Core\Validator\Pair\CountryState()); $isCountryStateAdded = true; } } else { $billingAddress->addPair($fieldName, new \XLite\Core\Validator\String($nonEmpty && $fieldData[\XLite\View\Model\Address\Address::SCHEMA_REQUIRED]), $mode); } } $billingAddress->addPair('save_in_book', new \XLite\Core\Validator\String\Switcher(), \XLite\Core\Validator\Pair\APair::SOFT); } return $validator; }