Beispiel #1
0
 public function index()
 {
     $clientorder = App::getModel('finalization')->setClientOrder();
     if (App::getModel('cart')->getMinimumOrderValue() > 0 || empty($clientorder['cart'])) {
         App::redirectUrl($this->registry->router->generate('frontend.cart', true));
     }
     $this->registry->xajax->registerFunction(array('saveOrder', App::getModel('finalization'), 'saveOrder'));
     $formContact = new SimpleForm\Form(array('name' => 'contactForm', 'action' => '', 'method' => 'post'));
     $formContact->AddChild(new SimpleForm\Elements\TextField(array('name' => 'phone', 'label' => _('TXT_PHONE'))));
     $formContact->AddChild(new SimpleForm\Elements\TextField(array('name' => 'phone2', 'label' => _('TXT_ADDITIONAL_PHONE'))));
     $formContact->AddChild(new SimpleForm\Elements\TextField(array('name' => 'email', 'label' => _('TXT_EMAIL'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_EMAIL')), new SimpleForm\Rules\Email(_('ERR_WRONG_EMAIL'))))));
     $clientContact = Session::getActiveOrderContactData();
     $formContact->Populate(array('phone' => $clientContact['phone'], 'phone2' => $clientContact['phone2'], 'email' => $clientContact['email']));
     if ($formContact->Validate()) {
         $formData = $formContact->getSubmitValues();
         Session::setActiveOrderContactData($formData);
         App::redirectUrl($this->registry->router->generate('frontend.finalization', true));
     }
     $formBilling = new SimpleForm\Form(array('name' => 'billingForm', 'action' => '', 'method' => 'post'));
     $clientType = $formBilling->AddChild(new SimpleForm\Elements\Radio(array('name' => 'clienttype', 'label' => _('TXT_CLIENT_TYPE'), 'options' => array('1' => _('TXT_INDIVIDUAL_CLIENT'), '2' => _('TXT_COMPANY_CLIENT')))));
     $formBilling->AddChild(new SimpleForm\Elements\TextField(array('name' => 'firstname', 'label' => _('TXT_FIRSTNAME'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_FIRSTNAME'))))));
     $formBilling->AddChild(new SimpleForm\Elements\TextField(array('name' => 'surname', 'label' => _('TXT_SURNAME'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_SURNAME'))))));
     $formBilling->AddChild(new SimpleForm\Elements\TextField(array('name' => 'companyname', 'label' => _('TXT_COMPANYNAME'), 'rules' => array(new SimpleForm\Rules\RequiredDependency(_('ERR_EMPTY_COMPANYNAME'), $clientType, new SimpleForm\Conditions\Equals('2'))))));
     $formBilling->AddChild(new SimpleForm\Elements\TextField(array('name' => 'nip', 'label' => _('TXT_NIP'), 'rules' => array(new SimpleForm\Rules\RequiredDependency(_('ERR_EMPTY_NIP'), $clientType, new SimpleForm\Conditions\Equals('2'))))));
     $formBilling->AddChild(new SimpleForm\Elements\TextField(array('name' => 'street', 'label' => _('TXT_STREET'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_STREET'))))));
     $formBilling->AddChild(new SimpleForm\Elements\TextField(array('name' => 'streetno', 'label' => _('TXT_STREETNO'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_STREETNO'))))));
     $formBilling->AddChild(new SimpleForm\Elements\TextField(array('name' => 'placeno', 'label' => _('TXT_PLACENO'))));
     $formBilling->AddChild(new SimpleForm\Elements\TextField(array('name' => 'placename', 'label' => _('TXT_PLACE'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_PLACE'))))));
     $formBilling->AddChild(new SimpleForm\Elements\TextField(array('name' => 'postcode', 'label' => _('TXT_POSTCODE'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_POSTCODE')), new SimpleForm\Rules\Format(_('ERR_WRONG_FORMAT_POSTCODE'), '/^\\d{2}-\\d{3}?$/')))));
     $formBilling->AddChild(new SimpleForm\Elements\Select(array('name' => 'countryid', 'label' => _('TXT_NAME_OF_COUNTRY'), 'options' => App::getModel('lists')->getCountryForSelect(), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_NAME_OF_COUNTRY'))))));
     $clientBillingAddress = Session::getActiveOrderClientAddress();
     $formBilling->Populate(array('clienttype' => $clientBillingAddress['clienttype'], 'firstname' => $clientBillingAddress['firstname'], 'surname' => $clientBillingAddress['surname'], 'companyname' => $clientBillingAddress['companyname'], 'nip' => $clientBillingAddress['nip'], 'street' => $clientBillingAddress['street'], 'streetno' => $clientBillingAddress['streetno'], 'postcode' => $clientBillingAddress['postcode'], 'placename' => $clientBillingAddress['placename'], 'placeno' => $clientBillingAddress['placeno'], 'countryid' => $clientBillingAddress['countryid']));
     if ($formBilling->Validate()) {
         $formData = $formBilling->getSubmitValues();
         if ($formData['clienttype'] == 1) {
             $formData['companyname'] = '';
             $formData['nip'] = '';
         }
         Session::setActiveOrderClientAddress($formData);
         App::redirectUrl($this->registry->router->generate('frontend.finalization', true));
     }
     $formShipping = new SimpleForm\Form(array('name' => 'shippingForm', 'action' => '', 'method' => 'post'));
     $formShipping->AddChild(new SimpleForm\Elements\TextField(array('name' => 'firstname', 'label' => _('TXT_FIRSTNAME'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_FIRSTNAME'))))));
     $formShipping->AddChild(new SimpleForm\Elements\TextField(array('name' => 'surname', 'label' => _('TXT_SURNAME'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_SURNAME'))))));
     $formShipping->AddChild(new SimpleForm\Elements\TextField(array('name' => 'companyname', 'label' => _('TXT_COMPANYNAME'))));
     $formShipping->AddChild(new SimpleForm\Elements\TextField(array('name' => 'street', 'label' => _('TXT_STREET'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_STREET'))))));
     $formShipping->AddChild(new SimpleForm\Elements\TextField(array('name' => 'streetno', 'label' => _('TXT_STREETNO'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_STREETNO'))))));
     $formShipping->AddChild(new SimpleForm\Elements\TextField(array('name' => 'placeno', 'label' => _('TXT_PLACENO'))));
     $formShipping->AddChild(new SimpleForm\Elements\TextField(array('name' => 'placename', 'label' => _('TXT_PLACE'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_PLACE'))))));
     $formShipping->AddChild(new SimpleForm\Elements\TextField(array('name' => 'postcode', 'label' => _('TXT_POSTCODE'), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_POSTCODE')), new SimpleForm\Rules\Format(_('ERR_WRONG_FORMAT_POSTCODE'), '/^\\d{2}-\\d{3}?$/')))));
     $formShipping->AddChild(new SimpleForm\Elements\Select(array('name' => 'countryid', 'label' => _('TXT_NAME_OF_COUNTRY'), 'options' => App::getModel('lists')->getCountryForSelect(), 'rules' => array(new SimpleForm\Rules\Required(_('ERR_EMPTY_NAME_OF_COUNTRY'))))));
     $clientShippingAddress = Session::getActiveOrderDeliveryAddress();
     $formShipping->Populate(array('firstname' => $clientShippingAddress['firstname'], 'surname' => $clientShippingAddress['surname'], 'companyname' => $clientShippingAddress['companyname'], 'street' => $clientShippingAddress['street'], 'streetno' => $clientShippingAddress['streetno'], 'postcode' => $clientShippingAddress['postcode'], 'placename' => $clientShippingAddress['placename'], 'placeno' => $clientShippingAddress['placeno'], 'countryid' => $clientShippingAddress['countryid']));
     if ($formShipping->Validate()) {
         $formData = $formShipping->getSubmitValues();
         Session::setActiveOrderDeliveryAddress($formData);
         App::redirectUrl($this->registry->router->generate('frontend.finalization', true));
     }
     $this->registry->template->assign('formContact', $formContact->getForm());
     $this->registry->template->assign('formBilling', $formBilling->getForm());
     $this->registry->template->assign('formShipping', $formShipping->getForm());
     $this->registry->template->assign('clientOrder', Session::getActiveClientOrder());
     $this->registry->template->assign('summary', App::getModel('finalization')->getOrderSummary());
     return $this->registry->template->fetch($this->loadTemplate('index.tpl'));
 }
Beispiel #2
0
 public function setClientOrder($Data = array())
 {
     $customerOpinion = isset($Data['customeropinion']) ? App::getModel('formprotection')->cropDangerousCode($Data['customeropinion']) : '';
     Event::notify($this, 'frontend.finalization.setActiveClientOrder', array('dispatchmethod' => Session::getActiveDispatchmethodChecked(), 'cart' => Session::getActiveCart()));
     $clientOrder = array('cart' => Session::getActiveCart(), 'globalPrice' => App::getModel('cart')->getGlobalPrice(), 'globalPriceWithoutVat' => App::getModel('cart')->getGlobalPriceWithoutVat(), 'priceWithDispatchMethod' => Session::getActiveglobalPriceWithDispatchmethod(), 'priceWithDispatchMethodNetto' => Session::getActiveglobalPriceWithDispatchmethodNetto(), 'count' => App::getModel('cart/cart')->getProductAllCount(), 'clientdata' => App::getModel('client')->getClient(), 'clientaddress' => Session::getActiveOrderClientAddress(), 'deliveryAddress' => Session::getActiveOrderDeliveryAddress(), 'contactData' => Session::getActiveOrderContactData(), 'dispatchmethod' => Session::getActiveDispatchmethodChecked(), 'payment' => Session::getActivePaymentMethodChecked(), 'clientid' => Session::getActiveClientid(), 'customeropinion' => $customerOpinion);
     $rulesDiscount = $this->getRulesCart($clientOrder);
     if (is_array($rulesDiscount) && count($rulesDiscount) > 0 && $clientOrder['dispatchmethod'] > 0 && $clientOrder['payment'] > 0) {
         if ($rulesDiscount['freeshipping'] == 1) {
             $clientOrder['priceWithDispatchMethod'] = $clientOrder['priceWithDispatchMethod'] - $clientOrder['dispatchmethod']['dispatchmethodcost'];
             $clientOrder['priceWithDispatchMethodNetto'] = $clientOrder['priceWithDispatchMethodNetto'] - $clientOrder['dispatchmethod']['dispatchmethodcostnetto'];
             $clientOrder['dispatchmethod']['dispatchmethodcost'] = 0;
             $clientOrder['dispatchmethod']['dispatchmethodcostnetto'] = 0;
         }
         if ($rulesDiscount['symbol'] == '+') {
             $globalPricePromo = sprintf('%01.2f', $clientOrder['globalPrice'] + $rulesDiscount['discount']);
             $globalPriceWithoutVatPromo = sprintf('%01.2f', $clientOrder['globalPriceWithoutVat'] + $rulesDiscount['discount']);
             $priceWithDispatchMethodPromo = sprintf('%01.2f', $clientOrder['priceWithDispatchMethod'] + $rulesDiscount['discount']);
             $priceWithDispatchMethodNettoPromo = sprintf('%01.2f', $clientOrder['priceWithDispatchMethodNetto'] + $rulesDiscount['discount']);
             $message = $rulesDiscount['symbol'] . $this->registry->core->processPrice($rulesDiscount['discount']);
         } elseif ($rulesDiscount['symbol'] == '-') {
             $globalPricePromo = sprintf('%01.2f', $clientOrder['globalPrice'] - $rulesDiscount['discount']);
             $globalPriceWithoutVatPromo = sprintf('%01.2f', $clientOrder['globalPriceWithoutVat'] - $rulesDiscount['discount']);
             $priceWithDispatchMethodPromo = sprintf('%01.2f', $clientOrder['priceWithDispatchMethod'] - $rulesDiscount['discount']);
             $priceWithDispatchMethodNettoPromo = sprintf('%01.2f', $clientOrder['priceWithDispatchMethodNetto'] - $rulesDiscount['discount']);
             $message = $rulesDiscount['symbol'] . $this->registry->core->processPrice($rulesDiscount['discount']);
         } elseif ($rulesDiscount['symbol'] == '%') {
             $globalPricePromo = sprintf('%01.2f', abs($clientOrder['globalPrice'] * $rulesDiscount['discount'] / 100));
             $globalPriceWithoutVatPromo = sprintf('%01.2f', abs($clientOrder['globalPriceWithoutVat'] * $rulesDiscount['discount'] / 100));
             $priceWithDispatchMethodPromo = sprintf('%01.2f', abs($clientOrder['priceWithDispatchMethod'] * $rulesDiscount['discount'] / 100));
             $priceWithDispatchMethodNettoPromo = sprintf('%01.2f', abs($clientOrder['priceWithDispatchMethodNetto'] * $rulesDiscount['discount'] / 100));
             $message = ($rulesDiscount['discount'] - 100 > 0 ? '+' : '-') . abs($rulesDiscount['discount'] - 100) . $rulesDiscount['symbol'];
         }
         if ($globalPricePromo > 0 && $globalPriceWithoutVatPromo > 0 && $priceWithDispatchMethodPromo > 0 && $priceWithDispatchMethodNettoPromo > 0) {
             $clientOrder['globalPricePromo'] = $globalPricePromo;
             $clientOrder['globalPriceWithoutVatPromo'] = $globalPriceWithoutVatPromo;
             $clientOrder['priceWithDispatchMethodPromo'] = $priceWithDispatchMethodPromo;
             $clientOrder['priceWithDispatchMethodNettoPromo'] = $priceWithDispatchMethodNettoPromo;
             $clientOrder['rulescart'] = $rulesDiscount['name'];
             $clientOrder['rulescartdescription'] = $rulesDiscount['description'];
             $clientOrder['rulescartid'] = $rulesDiscount['rulescartid'];
             $clientOrder['rulescartmessage'] = $message;
             $clientOrder['rulescartfreeshipping'] = $rulesDiscount['freeshipping'];
         }
     }
     Session::setActiveClientOrder($clientOrder);
     return $this->getClientOrder();
 }