Beispiel #1
0
 public function add()
 {
     $CurrentViewData = array('basic_pane' => array('enable' => 1, 'producerid' => 0), 'price_pane' => array('buycurrencyid' => Session::getActiveShopCurrencyId(), 'sellcurrencyid' => Session::getActiveShopCurrencyId(), 'vatid' => App::getModel('view')->getDefaultVatId()), 'weight_pane' => array('weight' => 0, 'width' => 0, 'height' => 0, 'deepth' => 0, 'unit' => 0, 'packagesize' => 1), 'stock_pane' => array('stock' => 0, 'trackstock' => 0, 'availablityid' => 0, 'disableatstockenabled' => 0, 'disableatstock' => 0));
     $this->formModel->setPopulateData($CurrentViewData);
     $form = $this->formModel->initForm();
     if ($form->Validate(FormEngine\FE::SubmittedData())) {
         $this->model->addNewProduct($form->getSubmitValues(FormEngine\Elements\Form::FORMAT_FLAT));
         if (FormEngine\FE::IsAction('next')) {
             App::redirect(__ADMINPANE__ . '/product/add');
         } else {
             App::redirect(__ADMINPANE__ . '/product');
         }
     }
     $this->renderLayout(array('form' => $form->Render()));
 }
Beispiel #2
0
 public function initForm()
 {
     $set = App::getModel('attributegroup')->getSugestVariant((int) $this->registry->core->getParam());
     $availablity = $this->registry->core->getDefaultValueToSelect() + App::getModel('availablity')->getAvailablityToSelect();
     $form = new FormEngine\Elements\Form(array('name' => 'product', 'action' => '', 'method' => 'post'));
     $basicPane = $form->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'basic_pane', 'label' => _('TXT_BASIC_INFORMATION'))));
     $basicLanguageData = $basicPane->AddChild(new FormEngine\Elements\FieldsetLanguage(array('name' => 'language_data', 'label' => _('TXT_LANGUAGE_DATA'))));
     $seoname = $basicLanguageData->AddChild(new FormEngine\Elements\TextField(array('name' => 'name', 'label' => _('TXT_PRODUCT_NAME'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_PRODUCT_NAME')), new FormEngine\Rules\LanguageUnique(_('ERR_NAME_ALREADY_EXISTS'), 'producttranslation', 'name', null, array('column' => 'productid', 'values' => (int) $this->registry->core->getParam()))))));
     $basicLanguageData->AddChild(new FormEngine\Elements\TextField(array('name' => 'seo', 'label' => _('TXT_PRODUCT_SEO'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_PRODUCT_SEO')), new FormEngine\Rules\Format(_('ERR_ALPHANUMERIC_INVALID'), '/^[A-Za-z0-9-_\\",\'\\s]+$/'), new FormEngine\Rules\LanguageUnique('Wybierz inny adres URL, podany już istnieje', 'producttranslation', 'seo', null, array('column' => 'productid', 'values' => (int) $this->registry->core->getParam()))))));
     $basicPane->AddChild(new FormEngine\Elements\Checkbox(array('name' => 'enable', 'label' => _('TXT_ENABLE_PRODUCT'), 'default' => '0')));
     $basicPane->AddChild(new FormEngine\Elements\TextField(array('name' => 'ean', 'label' => _('TXT_EAN'))));
     $basicPane->AddChild(new FormEngine\Elements\TextField(array('name' => 'delivelercode', 'label' => _('TXT_DELIVELERCODE'))));
     $producerid = $basicPane->AddChild(new FormEngine\Elements\Select(array('name' => 'producerid', 'label' => _('TXT_PRODUCER'), 'addable' => true, 'onAdd' => 'xajax_AddProducer', 'add_item_prompt' => 'Podaj nazwę producenta', 'options' => FormEngine\Option::Make($this->registry->core->getDefaultValueToSelect() + App::getModel('producer')->getProducerToSelect()))));
     $basicPane->AddChild(new FormEngine\Elements\Select(array('name' => 'delivererid', 'label' => _('TXT_DELIVERER'), 'addable' => true, 'onAdd' => 'xajax_AddDeliverer', 'add_item_prompt' => 'Podaj nazwę dostawcy', 'options' => FormEngine\Option::Make($this->registry->core->getDefaultValueToSelect() + App::getModel('deliverer')->getDelivererToSelect()))));
     $metaData = $form->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'meta_data', 'label' => _('TXT_META_INFORMATION'))));
     $metaData->AddChild(new FormEngine\Elements\Tip(array('tip' => '<p align="center">W przypadku braku informacji META system wygeneruje je automatycznie. W każdej chwili możesz je zmienić edytując dane poniżej.</p>', 'direction' => FormEngine\Elements\Tip::DOWN)));
     $languageData = $metaData->AddChild(new FormEngine\Elements\FieldsetLanguage(array('name' => 'language_data', 'label' => _('TXT_LANGUAGE_DATA'))));
     $languageData->AddChild(new FormEngine\Elements\TextField(array('name' => 'keywordtitle', 'label' => _('TXT_KEYWORD_TITLE'))));
     $languageData->AddChild(new FormEngine\Elements\Textarea(array('name' => 'keyworddescription', 'label' => _('TXT_KEYWORD_DESCRIPTION'), 'comment' => _('TXT_MAX_LENGTH') . ' 1000', 'max_length' => 1000)));
     $languageData->AddChild(new FormEngine\Elements\Textarea(array('name' => 'keyword', 'label' => _('TXT_KEYWORDS'), 'comment' => _('TXT_KEYWORDS_HELP'))));
     $stockPane = $form->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'stock_pane', 'label' => _('TXT_SHIPPING_STOCK_SETTINGS'))));
     if ((int) $set > 0) {
         $stockPane->AddChild(new FormEngine\Elements\Tip(array('tip' => '<p><strong style="color: red;">UWAGA:</strong>Ten produkt posiada warianty produktu. Jego stan magazynowy zostanie określony automatycznie na podstawie sumy stanów magazynowych wszystkich wariantów. Przejdź do zakładki Warianty produktu aby edytować stany.</p>', 'direction' => FormEngine\Elements\Tip::DOWN)));
         $stockPane->AddChild(new FormEngine\Elements\Constant(array('name' => 'stock', 'label' => _('TXT_STOCK'), 'suffix' => _('TXT_QTY'), 'default' => 0)));
         $stockPane->AddChild(new FormEngine\Elements\Hidden(array('name' => 'stock', 'label' => _('TXT_STOCK'), 'default' => 0)));
     } else {
         $stockPane->AddChild(new FormEngine\Elements\TextField(array('name' => 'stock', 'label' => _('TXT_STOCK'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_STOCK')), new FormEngine\Rules\Format(_('ERR_NUMERIC_INVALID'), '/[0-9]{1,}/')), 'suffix' => _('TXT_QTY'), 'default' => 0)));
     }
     $stockPane->AddChild(new FormEngine\Elements\Tip(array('tip' => '<p align="center">Śledzenie stanu magazynowego spowoduje, że stan magazynowy będzie się zmieniał automatycznie w przypadku zamówień. Produkty z włączonym śledzeniem i ilością 0 nie będą mogły być zamówione przez klientów.</p>', 'direction' => FormEngine\Elements\Tip::DOWN)));
     $stockPane->AddChild(new FormEngine\Elements\Checkbox(array('name' => 'trackstock', 'label' => _('TXT_TRACKSTOCK'))));
     $disableatstockenabled = $stockPane->AddChild(new FormEngine\Elements\Checkbox(array('name' => 'disableatstockenabled', 'label' => _('TXT_DISABLEATSTOCK_ENABLE'), 'default' => '0')));
     $stockPane->AddChild(new FormEngine\Elements\TextField(array('name' => 'disableatstock', 'label' => _('TXT_DISABLEATSTOCK'), 'rules' => array(new FormEngine\Rules\Format(_('ERR_NUMERIC_INVALID'), '/[0-9]{1,}/')), 'dependencies' => array(new FormEngine\Dependency(FormEngine\Dependency::SHOW, $disableatstockenabled, new FormEngine\Conditions\Equals('1'))), 'default' => '0')));
     $stockPane->AddChild(new FormEngine\Elements\Select(array('name' => 'availablityid', 'label' => _('TXT_AVAILABLITY'), 'options' => FormEngine\Option::Make($availablity))));
     $categoryPane = $form->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'category_pane', 'label' => _('TXT_CATEGORY'))));
     $categoryPane->AddChild(new FormEngine\Elements\Tip(array('tip' => '<p align="center">Wybierz kategorie w jakich ma pojawić się produkt. Kategoriami możesz zarządzać na stronie <a href="' . $this->registry->router->generate('admin', true, array('controller' => 'category')) . '" target="_blank">Katalog &raquo; Kategorie</a>.</p>', 'direction' => FormEngine\Elements\Tip::DOWN)));
     $category = $categoryPane->AddChild(new FormEngine\Elements\Tree(array('name' => 'category', 'label' => _('TXT_CATEGORY'), 'choosable' => false, 'selectable' => true, 'sortable' => false, 'clickable' => false, 'items' => App::getModel('view')->getChildCategories(), 'load_children' => array(App::getModel('view'), 'getChildCategories'))));
     $pricePane = $form->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'price_pane', 'label' => _('TXT_PRICE'))));
     $vat = $pricePane->AddChild(new FormEngine\Elements\Select(array('name' => 'vatid', 'label' => _('TXT_VAT'), 'options' => FormEngine\Option::Make(App::getModel('vat')->getVATAll()), 'addable' => true, 'onAdd' => 'xajax_AddVat', 'add_item_prompt' => 'Podaj wartość stawki VAT')));
     $currencies = App::getModel('currencieslist')->getCurrencyForSelect();
     $sellcurrency = $pricePane->AddChild(new FormEngine\Elements\Select(array('name' => 'sellcurrencyid', 'label' => _('TXT_SELL_CURRENCY'), 'options' => FormEngine\Option::Make($currencies), 'default' => Session::getActiveShopCurrencyId())));
     $buycurrency = $pricePane->AddChild(new FormEngine\Elements\Select(array('name' => 'buycurrencyid', 'label' => _('TXT_BUY_CURRENCY'), 'options' => FormEngine\Option::Make($currencies), 'default' => Session::getActiveShopCurrencyId())));
     $pricePane->AddChild(new FormEngine\Elements\Price(array('name' => 'buyprice', 'label' => _('TXT_BUYPRICE'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_BUYPRICE')), new FormEngine\Rules\Format(_('ERR_NUMERIC_INVALID'), '/[0-9]{1,}/')), 'filters' => array(new FormEngine\Filters\CommaToDotChanger()), 'vat_field' => $vat)));
     $standardPrice = $pricePane->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'standard_price', 'label' => _('TXT_STANDARD_SELLPRICE'), 'class' => 'priceGroup')));
     $price = $standardPrice->AddChild(new FormEngine\Elements\Price(array('name' => 'sellprice', 'label' => _('TXT_SELLPRICE'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_SELLPRICE')), new FormEngine\Rules\Format(_('ERR_NUMERIC_INVALID'), '/[0-9]{1,}/')), 'vat_field' => $vat)));
     $enablePromotion = $standardPrice->AddChild(new FormEngine\Elements\Checkbox(array('name' => 'promotion', 'label' => _('TXT_ENABLE_PROMOTION'), 'default' => '0')));
     $standardPrice->AddChild(new FormEngine\Elements\Price(array('name' => 'discountprice', 'label' => _('TXT_DISCOUNTPRICE'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_SELLPRICE')), new FormEngine\Rules\Format(_('ERR_NUMERIC_INVALID'), '/[0-9]{1,}/')), 'vat_field' => $vat, 'dependencies' => array(new FormEngine\Dependency(FormEngine\Dependency::SHOW, $enablePromotion, new FormEngine\Conditions\Equals(1))))));
     $standardPrice->AddChild(new FormEngine\Elements\Date(array('name' => 'promotionstart', 'label' => _('TXT_START_DATE'), 'dependencies' => array(new FormEngine\Dependency(FormEngine\Dependency::SHOW, $enablePromotion, new FormEngine\Conditions\Equals(1))))));
     $standardPrice->AddChild(new FormEngine\Elements\Date(array('name' => 'promotionend', 'label' => _('TXT_END_DATE'), 'dependencies' => array(new FormEngine\Dependency(FormEngine\Dependency::SHOW, $enablePromotion, new FormEngine\Conditions\Equals(1))))));
     $pricePane->AddChild(new FormEngine\Elements\Tip(array('tip' => '<p align="center"><strong>Ceny dla grup klientów</strong><br />Jeżeli chcesz aby dana grupa klientów posiadała inne ceny, uzupełnij wybrane sekcje poniżej.</p>', 'direction' => FormEngine\Elements\Tip::DOWN)));
     $clientGroups = App::getModel('clientgroup/clientgroup')->getClientGroupAll();
     foreach ($clientGroups as $clientGroup) {
         $group = $pricePane->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'field_' . $clientGroup['id'], 'label' => $clientGroup['name'], 'class' => 'priceGroup')));
         $groups[$clientGroup['id']] = $group->AddChild(new FormEngine\Elements\Checkbox(array('name' => 'groupid_' . $clientGroup['id'], 'label' => _('TXT_ENABLE_GROUP_PRICE'), 'default' => '0')));
         $group->AddChild(new FormEngine\Elements\Price(array('name' => 'sellprice_' . $clientGroup['id'], 'label' => _('TXT_SELLPRICE'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_SELLPRICE')), new FormEngine\Rules\Format(_('ERR_NUMERIC_INVALID'), '/[0-9]{1,}/')), 'vat_field' => $vat, 'dependencies' => array(new FormEngine\Dependency(FormEngine\Dependency::HIDE, $groups[$clientGroup['id']], new FormEngine\Conditions\Not(new FormEngine\Conditions\Equals(1)))))));
         $promotion[$clientGroup['id']] = $group->AddChild(new FormEngine\Elements\Checkbox(array('name' => 'promotion_' . $clientGroup['id'], 'label' => _('TXT_ENABLE_CLIENTGROUP_PROMOTION'), 'default' => '0')));
         $group->AddChild(new FormEngine\Elements\Price(array('name' => 'discountprice_' . $clientGroup['id'], 'label' => _('TXT_DISCOUNTPRICE'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_SELLPRICE')), new FormEngine\Rules\Format(_('ERR_NUMERIC_INVALID'), '/[0-9]{1,}/')), 'vat_field' => $vat, 'dependencies' => array(new FormEngine\Dependency(FormEngine\Dependency::SHOW, $promotion[$clientGroup['id']], new FormEngine\Conditions\Equals(1))))));
         $group->AddChild(new FormEngine\Elements\Date(array('name' => 'promotionstart_' . $clientGroup['id'], 'label' => _('TXT_START_DATE'), 'dependencies' => array(new FormEngine\Dependency(FormEngine\Dependency::SHOW, $promotion[$clientGroup['id']], new FormEngine\Conditions\Equals(1))))));
         $group->AddChild(new FormEngine\Elements\Date(array('name' => 'promotionend_' . $clientGroup['id'], 'label' => _('TXT_END_DATE'), 'dependencies' => array(new FormEngine\Dependency(FormEngine\Dependency::SHOW, $promotion[$clientGroup['id']], new FormEngine\Conditions\Equals(1))))));
     }
     $weightPane = $form->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'weight_pane', 'label' => _('TXT_WEIGHT_DATA'))));
     $weightPane->AddChild(new FormEngine\Elements\TextField(array('name' => 'weight', 'label' => _('TXT_WEIGHT'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_WEIGHT')), new FormEngine\Rules\Format(_('ERR_NUMERIC_INVALID'), '/[0-9]{1,}/')), 'suffix' => 'kg', 'filters' => array(new FormEngine\Filters\CommaToDotChanger()), 'default' => 0)));
     $weightPane->AddChild(new FormEngine\Elements\TextField(array('name' => 'width', 'label' => _('TXT_WIDTH'), 'suffix' => 'cm', 'filters' => array(new FormEngine\Filters\CommaToDotChanger()))));
     $weightPane->AddChild(new FormEngine\Elements\TextField(array('name' => 'height', 'label' => _('TXT_HEIGHT'), 'suffix' => 'cm', 'filters' => array(new FormEngine\Filters\CommaToDotChanger()))));
     $weightPane->AddChild(new FormEngine\Elements\TextField(array('name' => 'deepth', 'label' => _('TXT_DEEPTH'), 'suffix' => 'cm', 'filters' => array(new FormEngine\Filters\CommaToDotChanger()))));
     $weightPane->AddChild(new FormEngine\Elements\Tip(array('tip' => '<p align="center">Wybierz miarę produktu w jakiej sprzedawany jest produkt. Jednostkami możesz zarządzać na stronie <a href="' . $this->registry->router->generate('admin', true, array('controller' => 'unitmeasure')) . '" target="_blank">Katalog &raquo; Jednostka miary</a>. Jeżeli chcesz tylko dodać nową opcję, użyj ikony dodawania obok listy wyboru.</p>', 'direction' => FormEngine\Elements\Tip::DOWN)));
     $weightPane->AddChild(new FormEngine\Elements\Select(array('name' => 'unit', 'label' => _('TXT_UNIT_MEASURE'), 'options' => FormEngine\Option::Make($this->registry->core->getDefaultValueToSelect() + App::getModel('unitmeasure')->getUnitMeasureToSelect()), 'addable' => true, 'onAdd' => 'xajax_AddUnitMeasure', 'add_item_prompt' => 'Podaj nazwę jednostki miary', 'default' => 0)));
     $weightPane->AddChild(new FormEngine\Elements\Tip(array('tip' => '<p align="center">Wpisz ilość sztuk w opakowaniu. Podczas dodawania produktu do koszyka ilość zostanie zaokrąglona do pełnych opakowań</p>')));
     $weightPane->AddChild(new FormEngine\Elements\TextField(array('name' => 'packagesize', 'label' => _('TXT_PACKAGE_SIZE'), 'comment' => _('TXT_PACKAGE_SIZE_HELP'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_PACKAGE_SIZE')), new FormEngine\Rules\Format(_('ERR_NUMERIC_INVALID'), '/[0-9]{1,}/')), 'filters' => array(new FormEngine\Filters\CommaToDotChanger()), 'default' => 1)));
     $descriptionPane = $form->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'description_pane', 'label' => _('TXT_DESCRIPTION'))));
     $descriptionLanguageData = $descriptionPane->AddChild(new FormEngine\Elements\FieldsetLanguage(array('name' => 'language_data', 'label' => _('TXT_LANGUAGE_DATA'))));
     $descriptionLanguageData->AddChild(new FormEngine\Elements\RichTextEditor(array('name' => 'shortdescription', 'label' => _('TXT_SHORTDESCRIPTION'), 'comment' => _('TXT_MAX_LENGTH') . ' 1000', 'max_length' => 1000, 'rows' => 20)));
     $descriptionLanguageData->AddChild(new FormEngine\Elements\RichTextEditor(array('name' => 'description', 'label' => _('TXT_DESCRIPTION'), 'comment' => _('TXT_MAX_LENGTH') . ' 5000', 'max_length' => 5000, 'rows' => 30)));
     $descriptionLanguageData->AddChild(new FormEngine\Elements\RichTextEditor(array('name' => 'longdescription', 'label' => _('TXT_ADDITIONAL_INFO'), 'rows' => 30)));
     $photosPane = $form->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'photos_pane', 'label' => _('TXT_PHOTOS'))));
     $photosPane->AddChild(new FormEngine\Elements\Tip(array('tip' => '<p align="center">Wybierz zdjęcia dla produktu z biblioteki lub wgraj je z dysku komputera. Zdjęcie oznaczone jako główne będzie wyświetlane w listach produktów oraz w karcie produktu jako pierwsze.</p>', 'direction' => FormEngine\Elements\Tip::DOWN)));
     $photosPane->AddChild(new FormEngine\Elements\Image(array('name' => 'photo', 'label' => _('TXT_PHOTOS'), 'repeat_min' => 0, 'repeat_max' => FormEngine\FE::INFINITE, 'upload_url' => App::getURLAdressWithAdminPane() . 'files/add', 'main_id' => isset($this->populateData['photos_pane']['mainphotoid']) ? $this->populateData['photos_pane']['mainphotoid'] : '')));
     $filePane = $form->addChild(new FormEngine\Elements\Fieldset(array('name' => 'files_pane', 'label' => _('TXT_FILES'))));
     $filePane->AddChild(new FormEngine\Elements\Tip(array('tip' => '<p align="center">Wybierz pliki z biblioteki, które chcesz przypisać do tego produktu.</p>', 'direction' => FormEngine\Elements\Tip::DOWN)));
     $filePane->AddChild(new FormEngine\Elements\Downloader(array('name' => 'file', 'label' => _('TXT_FILES'), 'repeat_min' => 0, 'repeat_max' => FormEngine\FE::INFINITE, 'upload_url' => App::getURLAdressWithAdminPane() . 'virtualproduct/add')));
     $warrantyPane = $form->addChild(new FormEngine\Elements\Fieldset(array('name' => 'warranty_pane', 'label' => _('TXT_WARRANTY'))));
     $warrantyPane->AddChild(new FormEngine\Elements\Tip(array('tip' => '<p align="center">Wybierz pliki z biblioteki, które chcesz przypisać do tego produktu.</p>', 'direction' => FormEngine\Elements\Tip::DOWN)));
     $warrantyPane->AddChild(new FormEngine\Elements\Downloader(array('name' => 'warranty', 'label' => _('TXT_WARRANTY'), 'repeat_min' => 0, 'repeat_max' => FormEngine\FE::INFINITE, 'upload_url' => App::getURLAdressWithAdminPane() . 'virtualproduct/add')));
     $upsellProducts = $form->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'upsell_products', 'label' => _('TXT_UPSELL'))));
     $upsellProducts->AddChild(new FormEngine\Elements\ProductSelectRelated(array('name' => 'upsell', 'repeat_min' => 1, 'repeat_max' => FormEngine\FE::INFINITE, 'exclude' => array((int) $this->registry->core->getParam()))));
     $similarProducts = $form->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'similar_products', 'label' => _('TXT_SIMILAR_PRODUCT_LIST'))));
     $similarProducts->AddChild(new FormEngine\Elements\ProductSelectRelated(array('name' => 'similar', 'repeat_min' => 1, 'repeat_max' => FormEngine\FE::INFINITE, 'exclude' => array((int) $this->registry->core->getParam()))));
     $crosssellProducts = $form->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'crosssell_products', 'label' => _('TXT_CROSSSELL'))));
     $crosssellProducts->AddChild(new FormEngine\Elements\ProductSelectRelated(array('name' => 'crosssell', 'repeat_min' => 1, 'repeat_max' => FormEngine\FE::INFINITE, 'exclude' => array((int) $this->registry->core->getParam()))));
     $statusProductPane = $form->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'statusproduct_pane', 'label' => _('TXT_PRODUCT_STATUS'))));
     $statusProductPane->AddChild(new FormEngine\Elements\Tip(array('tip' => '<p align="center">Statusy produktów są używane do wyświetlania specjalnych oznaczeń na listach i kartach produktów.</p>', 'direction' => FormEngine\Elements\Tip::DOWN)));
     $statusProductPane->AddChild(new FormEngine\Elements\MultiSelect(array('name' => 'productstatuses', 'label' => _('TXT_PRODUCT_STATUS'), 'addable' => true, 'onAdd' => 'xajax_AddProductStatus', 'add_item_prompt' => 'Podaj nazwę statusu', 'options' => FormEngine\Option::Make(App::getModel('productstatus')->getProductstatusAll(false)))));
     $idnew = $statusProductPane->AddChild(new FormEngine\Elements\Checkbox(array('name' => 'newactive', 'label' => _('TXT_PRODUCT_IS_NEW'))));
     $newData = $statusProductPane->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'new_data', 'label' => _('TXT_NEW_DATA'), 'dependencies' => array(new FormEngine\Dependency(FormEngine\Dependency::HIDE, $idnew, new FormEngine\Conditions\Not(new FormEngine\Conditions\Equals('1')))))));
     $newData->AddChild(new FormEngine\Elements\Date(array('name' => 'startnew', 'label' => _('TXT_START_DATE'))));
     $newData->AddChild(new FormEngine\Elements\Date(array('name' => 'endnew', 'label' => _('TXT_END_DATE'))));
     $groups = App::getModel('attributegroup/attributegroup')->getGroupsForCategory(0);
     if (!empty($groups)) {
         $variantsPane = $form->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'variants_pane', 'label' => _('TXT_PRODUCT_VARIANTS'))));
         $variantsPane->AddChild(new FormEngine\Elements\ProductVariantsEditor(array('name' => 'variants', 'label' => _('TXT_PRODUCT_VARIANTS'), 'category' => $category, 'price' => $price, 'set' => $set, 'vat_field' => $vat, 'availablity' => $availablity, 'photos' => App::getModel('product')->productSelectedPhotos((int) $this->registry->core->getParam()), 'allow_generate' => App::getModel('order')->checkProductWithAttributes((int) $this->registry->core->getParam()))));
     }
     $Data = Event::dispatch($this, 'admin.product.initForm', array('form' => $form, 'id' => (int) $this->registry->core->getParam(), 'data' => $this->populateData));
     if (!empty($Data)) {
         $form->Populate($Data);
     }
     $form->AddFilter(new FormEngine\Filters\Trim());
     $form->AddFilter(new FormEngine\Filters\Secure());
     return $form;
 }
Beispiel #3
0
 public function edit()
 {
     Event::dispatch($this, 'admin.order.checkPaymentStatus', array('id' => (int) $this->registry->core->getParam()));
     $rawOrderData = $this->model->getOrderById($this->registry->core->getParam());
     if (isset($rawOrderData['currencyid']) && !empty($rawOrderData['currencyid'])) {
         $currencyid = $rawOrderData['currencyid'];
     } else {
         $currencyid = Session::getActiveShopCurrencyId();
     }
     try {
         $order = $this->model->getOrderById((int) $this->registry->core->getParam());
         $order['id'] = (int) $this->registry->core->getParam();
         $orderNotes = $this->model->getOrderNotes($order['id']);
         $clientOrderHistory = $this->model->getclientOrderHistory($order['clientid']);
     } catch (Exception $e) {
         throw new CoreException($e->getMessage());
     }
     $addNotes = new FormEngine\Elements\Form(array('name' => 'add_notes', 'class' => 'statusChange', 'action' => '', 'method' => 'post'));
     $addNotes->AddChild(new FormEngine\Elements\Textarea(array('name' => 'contents', 'label' => _('TXT_CONTENT'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_CONTENT'))))));
     $addNotes->AddChild(new FormEngine\Elements\Submit(array('name' => 'add', 'label' => _('TXT_ADD'), 'icon' => '_images_panel/icons/buttons/add.png')));
     $form = new FormEngine\Elements\Form(array('name' => 'order', 'action' => '', 'class' => 'editOrder', 'method' => 'post'));
     $productsData = $form->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'products_data', 'label' => _('TXT_EDIT_ORDER_ORDERED_PRODUCTS'))));
     $products = $productsData->AddChild(new FormEngine\Elements\OrderEditor(array('name' => 'products', 'label' => _('TXT_EDIT_ORDER_ORDERED_PRODUCTS'), 'advanced_editor' => true, 'repeat_min' => 1, 'repeat_max' => FormEngine\FE::INFINITE, 'clientgroupid' => (int) $rawOrderData['clientgroupid'], 'currencyid' => (int) $rawOrderData['currencyid'], 'viewid' => $rawOrderData['viewid'], 'on_change' => 'OnProductListChanged')));
     $addressData = $form->AddChild(new FormEngine\Elements\Columns(array('name' => 'address_data')));
     $billingData = $addressData->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'billing_data', 'label' => _('TXT_EDIT_ORDER_BILLING_DATA'))));
     $billingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'firstname', 'label' => _('TXT_FIRSTNAME'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_FIRSTNAME'))))));
     $billingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'surname', 'label' => _('TXT_SURNAME'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_SURNAME'))))));
     $billingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'street', 'label' => _('TXT_STREET'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_STREET'))))));
     $billingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'streetno', 'label' => _('TXT_STREETNO'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_STREETNO'))))));
     $billingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'placeno', 'label' => _('TXT_PLACENO'))));
     $billingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'place', 'label' => _('TXT_PLACE'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_PLACE'))))));
     $billingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'postcode', 'label' => _('TXT_POSTCODE'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_POSTCODE'))))));
     $billingData->AddChild(new FormEngine\Elements\Select(array('name' => 'countryid', 'label' => _('TXT_NAME_OF_COUNTRY'), 'options' => FormEngine\Option::Make(App::getModel('countrieslist')->getCountryForSelect()), 'default' => 0, 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_NAME_OF_COUNTRY'))))));
     $billingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'companyname', 'label' => _('TXT_COMPANYNAME'))));
     $billingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'nip', 'label' => _('TXT_NIP'))));
     $billingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'phone', 'label' => _('TXT_PHONE'), 'rules' => array(new FormEngine\Rules\Format(_('ERR_WRONG_FORMAT'), '/^[0-9 -+]+$/')))));
     $billingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'phone2', 'label' => _('TXT_ADDITIONAL_PHONE'), 'rules' => array(new FormEngine\Rules\Format(_('ERR_WRONG_FORMAT'), '/^[0-9 -+]+$/')))));
     $billingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'email', 'label' => _('TXT_EMAIL'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_EMAIL'))))));
     $shippingData = $addressData->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'shipping_data', 'label' => _('TXT_EDIT_ORDER_SHIPPING_DATA'))));
     $shippingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'firstname', 'label' => _('TXT_FIRSTNAME'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_FIRSTNAME'))))));
     $shippingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'surname', 'label' => _('TXT_SURNAME'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_SURNAME'))))));
     $shippingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'street', 'label' => _('TXT_STREET'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_STREET'))))));
     $shippingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'streetno', 'label' => _('TXT_STREETNO'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_STREETNO'))))));
     $shippingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'placeno', 'label' => _('TXT_PLACENO'))));
     $shippingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'place', 'label' => _('TXT_PLACE'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_PLACE'))))));
     $shippingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'postcode', 'label' => _('TXT_POSTCODE'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_POSTCODE'))))));
     $shippingData->AddChild(new FormEngine\Elements\Select(array('name' => 'countryid', 'label' => _('TXT_NAME_OF_COUNTRY'), 'options' => FormEngine\Option::Make(App::getModel('countrieslist')->getCountryForSelect()), 'default' => 0, 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_NAME_OF_COUNTRY'))))));
     $shippingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'companyname', 'label' => _('TXT_COMPANYNAME'))));
     $shippingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'nip', 'label' => _('TXT_NIP'))));
     $shippingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'phone', 'label' => _('TXT_PHONE'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_PHONE')), new FormEngine\Rules\Format(_('ERR_WRONG_FORMAT'), '/^[0-9 -+]+$/')))));
     $shippingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'phone2', 'label' => _('TXT_ADDITIONAL_PHONE'), 'rules' => array(new FormEngine\Rules\Format(_('ERR_WRONG_FORMAT'), '/^[0-9 -+]+$/')))));
     $shippingData->AddChild(new FormEngine\Elements\TextField(array('name' => 'email', 'label' => _('TXT_EMAIL'), 'rules' => array(new FormEngine\Rules\Required(_('ERR_EMPTY_EMAIL'))))));
     $additionalData = $form->AddChild(new FormEngine\Elements\Columns(array('name' => 'additional_data')));
     $paymentData = $additionalData->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'payment_data', 'label' => _('TXT_EDIT_ORDER_PAYMENT_METHOD'))));
     $paymentData->AddChild(new FormEngine\Elements\Select(array('name' => 'payment_method', 'label' => _('TXT_EDIT_ORDER_PAYMENT_METHOD'), 'options' => FormEngine\Option::Make($this->registry->core->getDefaultValueToSelect() + $this->model->getPaymentmethodAllToSelect($this->registry->core->getParam())))));
     $weight = 0;
     foreach ($order['products'] as $product) {
         $weight += $product['weight'];
     }
     $paymentData->AddChild(new FormEngine\Elements\Select(array('name' => 'delivery_method', 'label' => _('TXT_EDIT_ORDER_DELIVERY_METHOD'), 'options' => FormEngine\Option::Make($this->model->getDispatchmethodAllToSelect($order['total'], $this->registry->core->getParam(), $weight)))));
     $paymentData->AddChild(new FormEngine\Elements\Select(array('name' => 'rules_cart', 'label' => _('TXT_RULES_CART'), 'options' => FormEngine\Option::Make($this->model->getAllRulesForOrder($this->registry->core->getParam())))));
     $paymentData->AddChild(new FormEngine\Elements\Constant(array('name' => 'currency', 'label' => _('TXT_KIND_OF_CURRENCY'))));
     $summaryData = $additionalData->AddChild(new FormEngine\Elements\Fieldset(array('name' => 'summary_data', 'label' => _('TXT_VIEW_ORDER_SUMMARY'))));
     $summaryData->AddChild(new FormEngine\Elements\Constant(array('name' => 'total_net_total', 'label' => _('TXT_NETTO_AMOUNT'))));
     $summaryData->AddChild(new FormEngine\Elements\Constant(array('name' => 'total_vat_value', 'label' => _('TXT_VIEW_ORDER_TAX'))));
     $summaryData->AddChild(new FormEngine\Elements\Constant(array('name' => 'total_delivery', 'label' => _('TXT_DELIVERERPRICE'))));
     $summaryData->AddChild(new FormEngine\Elements\Constant(array('name' => 'total_total', 'label' => _('TXT_VIEW_ORDER_TOTAL'))));
     $form->AddFilter(new FormEngine\Filters\NoCode());
     $form->AddFilter(new FormEngine\Filters\Trim());
     $form->AddFilter(new FormEngine\Filters\Secure());
     $orderData = array('address_data' => array('billing_data' => array('firstname' => $rawOrderData['billing_address']['firstname'], 'surname' => $rawOrderData['billing_address']['surname'], 'street' => $rawOrderData['billing_address']['street'], 'streetno' => $rawOrderData['billing_address']['streetno'], 'placeno' => $rawOrderData['billing_address']['placeno'], 'place' => $rawOrderData['billing_address']['city'], 'postcode' => $rawOrderData['billing_address']['postcode'], 'countryid' => $rawOrderData['billing_address']['countryid'], 'companyname' => $rawOrderData['billing_address']['companyname'], 'nip' => $rawOrderData['billing_address']['nip'], 'phone' => $rawOrderData['billing_address']['phone'], 'phone2' => $rawOrderData['billing_address']['phone2'], 'email' => $rawOrderData['billing_address']['email']), 'shipping_data' => array('firstname' => $rawOrderData['delivery_address']['firstname'], 'surname' => $rawOrderData['delivery_address']['surname'], 'street' => $rawOrderData['delivery_address']['street'], 'streetno' => $rawOrderData['delivery_address']['streetno'], 'placeno' => $rawOrderData['delivery_address']['placeno'], 'place' => $rawOrderData['delivery_address']['city'], 'postcode' => $rawOrderData['delivery_address']['postcode'], 'countryid' => $rawOrderData['delivery_address']['countryid'], 'companyname' => $rawOrderData['delivery_address']['companyname'], 'nip' => $rawOrderData['delivery_address']['nip'], 'phone' => $rawOrderData['delivery_address']['phone'], 'phone2' => $rawOrderData['billing_address']['phone2'], 'email' => $rawOrderData['delivery_address']['email'])), 'additional_data' => array('payment_data' => array('delivery_method' => $rawOrderData['delivery_method']['dispatchmethodid'], 'payment_method' => $rawOrderData['payment_method']['paymentmethodid'], 'rules_cart' => $rawOrderData['rulescartid'], 'currency' => $rawOrderData['currencysymbol']), 'summary_data' => array('total_net_total' => 132)), 'products_data' => array('products' => $this->model->getProductsDataGrid((int) $this->registry->core->getParam())));
     $form->Populate($orderData);
     $statusChange = new FormEngine\Elements\Form(array('name' => 'add_status_change', 'class' => 'statusChange', 'action' => '', 'method' => 'post'));
     $idstatus = $statusChange->AddChild(new FormEngine\Elements\Select(array('name' => 'status', 'label' => _('TXT_VIEW_ORDER_CHANGE_STATUS'), 'options' => FormEngine\Option::Make(App::getModel('orderstatus')->getOrderStatusToSelect()))));
     $statusChange->AddChild(new FormEngine\Elements\Textarea(array('name' => 'comment', 'label' => _('TXT_VIEW_ORDER_CHANGE_COMMENT'), 'dependencies' => array(new FormEngine\Dependency(FormEngine\Dependency::SUGGEST, $idstatus, array(App::getModel('orderstatus'), 'getDefaultComment'))))));
     $statusChange->AddChild(new FormEngine\Elements\Checkbox(array('name' => 'inform', 'label' => _('TXT_VIEW_ORDER_CHANGE_INFORM_CLIENT'))));
     $statusChange->AddChild(new FormEngine\Elements\Submit(array('name' => 'update', 'label' => _('TXT_VIEW_ORDER_CHANGE_UPDATE'), 'icon' => '_images_panel/icons/buttons/flag-green.png')));
     $statusChange->Populate(array('status' => $order['current_status_id']));
     $form->AddFilter(new FormEngine\Filters\Trim());
     $form->AddFilter(new FormEngine\Filters\Secure());
     $form->AddFilter(new FormEngine\Filters\Trim());
     $form->AddFilter(new FormEngine\Filters\Secure());
     if ($addNotes->Validate(FormEngine\FE::SubmittedData())) {
         try {
             $notes = $addNotes->getSubmitValues(FormEngine\Elements\Form::FORMAT_FLAT);
             $this->model->addOrderNotes($addNotes->getSubmitValues(FormEngine\Elements\Form::FORMAT_FLAT), $order['id']);
             Session::setVolatileMessage("Dodano notatkę do zamówienia {$this->id}");
             App::redirect(__ADMINPANE__ . '/order/edit/' . (int) $this->registry->core->getParam());
         } catch (Exception $e) {
             $this->registry->template->assign('error', $e->getMessage());
         }
     }
     if ($statusChange->Validate(FormEngine\FE::SubmittedData())) {
         $this->model->addOrderHistory($statusChange->getSubmitValues(FormEngine\Elements\Form::FORMAT_FLAT), $this->registry->core->getParam());
         try {
             $email = $statusChange->getSubmitValues(FormEngine\Elements\Form::FORMAT_FLAT);
             if ($email['inform'] == 1) {
                 $this->model->notifyUser($order, $email['status']);
             }
             Session::setVolatileMessage("Zaktualizowano status zamówienia {$this->id}");
             $this->model->updateOrderStatus($_POST, $this->registry->core->getParam());
             App::redirect(__ADMINPANE__ . '/order/edit/' . (int) $this->registry->core->getParam());
         } catch (Exception $e) {
             $this->registry->template->assign('error', $e->getMessage());
         }
     }
     if ($form->Validate(FormEngine\FE::SubmittedData())) {
         try {
             $this->model->updateOrderById($_POST, $this->registry->core->getParam());
             App::redirect(__ADMINPANE__ . '/order/');
         } catch (Exception $e) {
             $this->registry->template->assign('error', $e->getMessage());
         }
     }
     $this->registry->template->assign('viewid', Helper::getViewId());
     $this->registry->xajaxInterface->registerFunction(array('CalculateDeliveryCost', $this->model, 'calculateDeliveryCostEdit'));
     $this->registry->xajaxInterface->registerFunction(array('GetDispatchMethodForPrice', $this->model, 'getDispatchMethodForPriceForAjaxEdit'));
     $this->registry->template->assign('xajax', $this->registry->xajax->getJavascript());
     $this->registry->xajax->processRequest();
     $this->registry->template->assign('statusChange', $statusChange->Render());
     $this->registry->template->assign('addNotes', $addNotes->Render());
     $this->registry->template->assign('orderNotes', $orderNotes);
     $this->registry->template->assign('clientOrderHistory', $clientOrderHistory);
     $this->registry->template->assign('order', $order);
     $this->registry->template->assign('currencyid', Session::getActiveCurrencyId());
     $this->registry->template->assign('currencysymbol', Session::getActiveCurrencySymbol());
     $this->registry->template->assign('form', $form->Render());
     $this->registry->template->display($this->loadTemplate('edit.tpl'));
 }
Beispiel #4
0
 public function changeAJAXCurrencyView($id)
 {
     $objResponse = new xajaxResponse();
     try {
         $shopCurrencyId = Session::getActiveShopCurrencyId();
         $currencyData = $this->getCurrencySelectedData($id);
         if (is_array($currencyData) && !empty($currencyData)) {
             Session::setActiveCurrencyId($currencyData['id']);
             Session::setActiveCurrencySymbol($currencyData['symbol']);
             App::getModel('cart')->setTempCartAfterCurrencyChange();
         }
         $objResponse->script('window.location.reload( false )');
     } catch (Exception $fe) {
         throw new FrontendException($e->getMessage());
     }
     return $objResponse;
 }
Beispiel #5
0
 /**
  * Chcek cart rules.
  * If there is any rule, reduce global price. Otherwise return 0.
  *
  * @param
  *        	array client order
  * @return array discount (rulescartid, suffixtypeid, symbol, discount) or 0
  * @access public
  */
 public function getRulesCart($clientOrder)
 {
     $clientGroupId = Session::getActiveClientGroupid();
     $Data = array();
     $discount = array();
     $check = true;
     $allRules = $this->getAllCartRules();
     if (is_array($allRules) && !empty($allRules)) {
         foreach ($allRules as $rule) {
             $ruleid = $rule['idrulescart'];
             $ruleName = $rule['name'];
             $ruleDescription = $rule['description'];
             if ($clientGroupId > 0) {
                 $sql = "SELECT \n\t\t\t\t\t\t\t\tRCCG.rulescartid, \n\t\t\t\t\t\t\t\tRCR.ruleid, \n\t\t\t\t\t\t\t\tRCR.pkid, \n\t\t\t\t\t\t\t\tRCR.pricefrom, \n\t\t\t\t\t\t\t\tRCR.priceto,\n\t\t\t\t\t\t\t\tRCCG.suffixtypeid, \n\t\t\t\t\t\t\t\tRCCG.discount, \n\t\t\t\t\t\t\t\tRCCG.freeshipping, \n\t\t\t\t\t\t\t\tS.symbol,\n\t\t\t\t\t\t\t\tRCCG.clientgroupid\n\t\t\t\t\t\t\tFROM rulescartclientgroup RCCG\n\t\t\t\t\t\t\tLEFT JOIN rulescart RC ON RCCG.rulescartid = RC.idrulescart\n\t\t\t\t\t\t\tLEFT JOIN rulescartrule RCR ON RCR.rulescartid = RC.idrulescart\n\t\t\t\t\t\t\tLEFT JOIN rulescartview RCV ON RCV.rulescartid = RC.idrulescart\n\t\t\t\t\t\t\tLEFT JOIN suffixtype S ON RCCG.suffixtypeid = S.idsuffixtype\n\t\t\t\t\t\t\tWHERE RCR.rulescartid = :ruleid\n\t\t\t\t\t\t    AND RCV.viewid= :viewid\n\t\t\t\t\t\t\tAND RCCG.clientgroupid= :clientgroupid\n\t\t\t\t\t\t\tAND IF(RC.datefrom is not null, (cast(RC.datefrom as date) <= curdate()), 1)\n\t\t\t\t\t\t\tAND IF(RC.dateto is not null, (cast(RC.dateto as date)>= curdate()),1)";
                 $stmt = Db::getInstance()->prepare($sql);
                 $stmt->bindValue('clientgroupid', $clientGroupId);
                 $stmt->bindValue('viewid', Helper::getViewId());
                 $stmt->bindValue('ruleid', $ruleid);
             } else {
                 $sql = "SELECT \n\t\t\t\t\t\t\t\tRCR.rulescartid, \n\t\t\t\t\t\t\t\tRCR.ruleid, \n\t\t\t\t\t\t\t\tRCR.pkid, \n\t\t\t\t\t\t\t\tRCR.pricefrom, \n\t\t\t\t\t\t\t\tRCR.priceto,\n\t\t\t\t\t\t\t\tRC.suffixtypeid, \n\t\t\t\t\t\t\t\tRC.freeshipping, \n\t\t\t\t\t\t\t\tRC.discount, \n\t\t\t\t\t\t\t\tS.symbol,\n\t\t\t\t\t\t\t\t'clientgroupid' = NULL as clientgroupid\n\t\t\t\t\t\t\tFROM  rulescart RC\n\t\t\t\t\t\t\tLEFT JOIN rulescartrule RCR ON RCR.rulescartid = RC.idrulescart\n\t\t\t\t\t\t\tLEFT JOIN rulescartview RCV ON RCV.rulescartid = RC.idrulescart\n\t\t\t\t\t\t\tLEFT JOIN suffixtype S ON RC.suffixtypeid = S.idsuffixtype\n\t\t      \t\t\t\tWHERE RCR.rulescartid = :ruleid\n\t\t                 \tAND RC.discountforall =1\n\t\t          \t\t\tAND RCV.viewid= :viewid\n\t\t          \t\t\tAND IF(RC.datefrom is not null, (cast(RC.datefrom as date) <= curdate()), 1)\n\t\t\t\t\t\t\tAND IF(RC.dateto is not null, (cast(RC.dateto as date)>= curdate()),1)";
                 $stmt = Db::getInstance()->prepare($sql);
                 $stmt->bindValue('viewid', Helper::getViewId());
                 $stmt->bindValue('ruleid', $ruleid);
             }
             try {
                 $stmt->execute();
                 while ($rs = $stmt->fetch()) {
                     $ruleid = $rs['ruleid'];
                     $rulescartid = $rs['rulescartid'];
                     switch ($ruleid) {
                         case 9:
                             // delivery (dispatchmethod)
                             if (isset($Data[$rulescartid][$ruleid]) && $Data[$rulescartid][$ruleid] == 0 || !isset($Data[$rulescartid][$ruleid])) {
                                 if (isset($clientOrder['dispatchmethod']['dispatchmethodid']) && $clientOrder['dispatchmethod']['dispatchmethodid'] == $rs['pkid']) {
                                     $Data[$rulescartid][$ruleid] = 1;
                                 } else {
                                     $Data[$rulescartid][$ruleid] = 0;
                                 }
                             }
                             break;
                         case 10:
                             // paymentmethod
                             if (isset($Data[$rulescartid][$ruleid]) && $Data[$rulescartid][$ruleid] == 0 || !isset($Data[$rulescartid][$ruleid])) {
                                 if (isset($clientOrder['payment']['idpaymentmethod']) && $clientOrder['payment']['idpaymentmethod'] == $rs['pkid']) {
                                     $Data[$rulescartid][$ruleid] = 1;
                                 } else {
                                     $Data[$rulescartid][$ruleid] = 0;
                                 }
                             }
                             break;
                         case 11:
                             // final cart price
                             if (isset($Data[$rulescartid][$ruleid]) && $Data[$rulescartid][$ruleid] == 0 || !isset($Data[$rulescartid][$ruleid])) {
                                 if (isset($clientOrder['globalPrice']) && $clientOrder['globalPrice'] >= $rs['pricefrom']) {
                                     $Data[$rulescartid][$ruleid] = 1;
                                 } else {
                                     $Data[$rulescartid][$ruleid] = 0;
                                 }
                             }
                             break;
                         case 12:
                             // final cart price
                             if (isset($Data[$rulescartid][$ruleid]) && $Data[$rulescartid][$ruleid] == 0 || !isset($Data[$rulescartid][$ruleid])) {
                                 if (isset($clientOrder['globalPrice']) && $clientOrder['globalPrice'] <= $rs['priceto']) {
                                     $Data[$rulescartid][$ruleid] = 1;
                                 } else {
                                     $Data[$rulescartid][$ruleid] = 0;
                                 }
                             }
                             break;
                         case 13:
                             // final cart price with dispatch method
                             if (isset($Data[$rulescartid][$ruleid]) && $Data[$rulescartid][$ruleid] == 0 || !isset($Data[$rulescartid][$ruleid])) {
                                 if (isset($clientOrder['priceWithDispatchMethod']) && $clientOrder['priceWithDispatchMethod'] >= $rs['pricefrom']) {
                                     $Data[$rulescartid][$ruleid] = 1;
                                 } else {
                                     $Data[$rulescartid][$ruleid] = 0;
                                 }
                             }
                             break;
                         case 14:
                             // final cart price with dispatch method
                             if (isset($Data[$rulescartid][$ruleid]) && $Data[$rulescartid][$ruleid] == 0 || !isset($Data[$rulescartid][$ruleid])) {
                                 if ($clientOrder['priceWithDispatchMethod'] <= $rs['priceto']) {
                                     $Data[$rulescartid][$ruleid] = 1;
                                 } else {
                                     $Data[$rulescartid][$ruleid] = 0;
                                 }
                             }
                             break;
                     }
                     $discountValue = $rs['discount'];
                     $discountSymbol = $rs['symbol'];
                     if ($discountSymbol !== '%' && $discountValue > 0) {
                         $shopCurrency = Session::getActiveShopCurrencyId();
                         $currentCurrency = Session::getActiveCurrencyId();
                         if ($shopCurrency != $currentCurrency) {
                             $rate = Session::getActiveCurrencyRate();
                             if (!empty($rate) && $rate > 0) {
                                 $discountValue = $rate * $discountValue;
                             }
                         }
                     }
                     $discount[$rs['rulescartid']]['rulescartid'] = $rs['rulescartid'];
                     $discount[$rs['rulescartid']]['name'] = $ruleName;
                     $discount[$rs['rulescartid']]['description'] = $ruleDescription;
                     $discount[$rs['rulescartid']]['suffixtypeid'] = $rs['suffixtypeid'];
                     $discount[$rs['rulescartid']]['discount'] = $discountValue;
                     $discount[$rs['rulescartid']]['symbol'] = $discountSymbol;
                     $discount[$rs['rulescartid']]['freeshipping'] = $rs['freeshipping'];
                 }
             } catch (Exception $e) {
                 throw new FrontendException(_('ERR_RULES_CART'));
             }
         }
         // end foreach
     }
     // end if is_array rulesAll
     if (count($Data) > 0) {
         foreach ($Data as $rulescart => $rules) {
             foreach ($rules as $rule) {
                 if ($rule == 0) {
                     unset($Data[$rulescart]);
                 }
             }
         }
     }
     foreach ($Data as $rulescart => $rules) {
         return $discount[$rulescart];
     }
 }