public function postProcess() { if (Tools::isSubmit('submitconfirmpayment')) { $confirmpayment = new TableConfirmPayment(); $confirmpayment->id_order = Tools::getValue('id_order'); $confirmpayment->nama_bank = Tools::getValue('nama_bank'); $confirmpayment->reg_account_bank = Tools::getValue('reg_account_bank'); $confirmpayment->id_account_bank = Tools::getValue('id_account_bank'); $confirmpayment->payment = Tools::getValue('payment'); $confirmpayment->payment_date = Tools::getValue('payment_date'); $confirmpayment->state = 'WAITING'; if (!$confirmpayment->id_order) { $this->errors[] = Tools::displayError('Pilih Order yang Telah Dibayar'); } elseif (!$confirmpayment->nama_bank) { $this->errors[] = Tools::displayError('Nama Bank tidak boleh kosong.'); } elseif (!$confirmpayment->reg_account_bank) { $this->errors[] = Tools::displayError('Atas Nama tidak boleh kosong.'); } elseif (!$confirmpayment->id_account_bank) { $this->errors[] = Tools::displayError('Pilih Rekening Tujuan'); } elseif (!$confirmpayment->payment) { $this->errors[] = Tools::displayError('Jumlah Pembayaran tidak boleh kosong.'); } elseif (!Validate::isPrice($confirmpayment->payment)) { $this->errors[] = Tools::displayError('Jumlah Pembayaran Harus Angka.'); } elseif (!$confirmpayment->payment_date) { $this->errors[] = Tools::displayError('Tanggal Pembayaran tidak boleh kosong.'); } else { $this->context->smarty->assign('confirmation', 1); $this->context->smarty->assign('alreadySent', 1); $order_id = new OrderCore((int) $confirmpayment->id_order); $q = 'UPDATE `' . _DB_PREFIX_ . 'orders` SET `current_state` = "1" WHERE `id_order` = ' . $confirmpayment->id_order . ';'; Db::getInstance()->execute($q); $confirmpayment->save(); } } }
public static function loadData($p = 1, $limit = 1000, $orderBy = NULL, $orderWay = NULL, $filter = array()) { $where = ''; if (!empty($filter['id_carrier']) && Validate::isInt($filter['id_carrier'])) { $where .= ' AND a.`id_carrier`=' . intval($filter['id_carrier']); } if (!empty($filter['name']) && Validate::isCatalogName($filter['name'])) { $where .= ' AND a.`name` LIKE "%' . pSQL($filter['name']) . '%"'; } if (!empty($filter['active']) && Validate::isInt($filter['active'])) { $where .= ' AND a.`active`=' . ((int) $filter['active'] == 1 ? '1' : '0'); } if (!empty($filter['shipping']) && Validate::isPrice($filter['shipping'])) { $where .= ' AND a.`shipping`=' . $filter['shipping']; } if (!empty($filter['description']) && Validate::isInt($filter['description'])) { $where .= ' AND a.`description` LIKE "%' . pSQL($filter['description']) . '%"'; } if (!is_null($orderBy) and !is_null($orderWay)) { $postion = 'ORDER BY ' . pSQL($orderBy) . ' ' . pSQL($orderWay); } else { $postion = 'ORDER BY `id_carrier` DESC'; } $total = Db::getInstance()->getRow('SELECT count(*) AS total FROM `' . DB_PREFIX . 'carrier` a WHERE 1 ' . $where); if ($total == 0) { return false; } $result = Db::getInstance()->getAll('SELECT a.* FROM `' . DB_PREFIX . 'carrier` a WHERE 1 ' . $where . ' ' . $postion . ' LIMIT ' . ($p - 1) * $limit . ',' . (int) $limit); $rows = array('total' => $total['total'], 'items' => self::reLoad($result)); return $rows; }
protected function doEditProductValidation(OrderDetail $order_detail, Order $order, OrderInvoice $order_invoice = null) { if (!Validate::isLoadedObject($order_detail)) { die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('The Order Detail object could not be loaded.')))); } if (!empty($order_invoice) && !Validate::isLoadedObject($order_invoice)) { die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('The invoice object cannot be loaded.')))); } if (!Validate::isLoadedObject($order)) { die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('The order object cannot be loaded.')))); } if ($order_detail->id_order != $order->id) { die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('You cannot edit the order detail for this order.')))); } // We can't edit a delivered order if ($order->hasBeenDelivered()) { die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('You cannot edit a delivered order.')))); } if (!empty($order_invoice) && $order_invoice->id_order != Tools::getValue('id_order')) { die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('You cannot use this invoice for the order')))); } // Clean price $product_price_tax_incl = str_replace(',', '.', Tools::getValue('product_price_tax_incl')); $product_price_tax_excl = str_replace(',', '.', Tools::getValue('product_price_tax_excl')); if (!Validate::isPrice($product_price_tax_incl) || !Validate::isPrice($product_price_tax_excl)) { die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('Invalid price')))); } if (!is_array(Tools::getValue('product_quantity')) && !Validate::isUnsignedInt(Tools::getValue('product_quantity'))) { die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('Invalid quantity')))); } elseif (is_array(Tools::getValue('product_quantity'))) { foreach (Tools::getValue('product_quantity') as $qty) { if (!Validate::isUnsignedInt($qty)) { die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('Invalid quantity')))); } } } }
protected function validateDiscount($reduction) { if (!Validate::isPrice($reduction) || $reduction > 100 || $reduction < 0) { return false; } else { return true; } }
/** * Validate fields before exportation * * @return array errors */ public function validateFields() { $errors = array(); foreach ($this->fields as $key => $params) { if ($params['mandatory'] == 1 && $params['value']) { $errors[] = $kiala_instance->l('Field ') . $key . $kiala_instance->l(' is mandatory but was not found.'); } switch ($params['type']) { case 'string': if ($params['value'] && strlen($params['value']) > $params['length']) { $errors[] = $kiala_instance->l('Field ') . $key . $kiala_instance->l(' is too long.'); } break; case 'price': if ($params['value'] && strlen($params['value']) > $params['length']) { $errors[] = $kiala_instance->l('Field ') . $key . $kiala_instance->l(' is too long.'); } if ($params['value'] && !Validate::isPrice($params['value'])) { $errors[] = $kiala_instance->l('Field ') . $key . $kiala_instance->l(' has a wrong format.'); } break; case 'float': if ($params['value'] && !Validate::isFloat($params['value'])) { $errors[] = $kiala_instance->l('Field ') . $key . $kiala_instance->l(' has a wrong format.'); } break; default: } } return $errors; }
protected function _validateSpecificPrice($id_shop, $id_currency, $id_country, $id_group, $id_customer, $price, $from_quantity, $reduction, $reduction_type, $from, $to, $id_combination = 0) { if (!Validate::isUnsignedId($id_shop) || !Validate::isUnsignedId($id_currency) || !Validate::isUnsignedId($id_country) || !Validate::isUnsignedId($id_group) || !Validate::isUnsignedId($id_customer)) { $this->errors[] = Tools::displayError('Wrong IDs'); } elseif (!isset($price) && !isset($reduction) || isset($price) && !Validate::isNegativePrice($price) || isset($reduction) && !Validate::isPrice($reduction)) { $this->errors[] = Tools::displayError('Invalid price/discount amount'); } elseif (!Validate::isUnsignedInt($from_quantity)) { $this->errors[] = Tools::displayError('Invalid quantity'); } elseif ($reduction && !Validate::isReductionType($reduction_type)) { $this->errors[] = Tools::displayError('Please select a discount type (amount or percentage).'); } elseif ($from && $to && (!Validate::isDateFormat($from) || !Validate::isDateFormat($to))) { $this->errors[] = Tools::displayError('The from/to date is invalid.'); } elseif (SpecificPrice::exists((int) $this->object->id, $id_combination, $id_shop, $id_group, $id_country, $id_currency, $id_customer, $from_quantity, $from, $to, false)) { $this->errors[] = Tools::displayError('A specific price already exists for these parameters.'); } else { return true; } return false; }
public static function addCompoundTaxesToTaxArray(&$taxes, $prices) { if (!is_array($taxes) || !is_array($prices)) { return false; } $compound_taxes = array(); foreach ($prices as $price) { if (!Validate::isPrice($price) && !Validate::isNegativePrice($price)) { continue; } array_push($compound_taxes, self::calculateCompundTax($price, $taxes)); } foreach ($compound_taxes as $price_compund) { if (!$price_compund) { continue; } foreach ($price_compund as $compound_tax_name => $compound_tax) { if (array_key_exists($compound_tax_name, $taxes)) { foreach ($compound_tax as $k => $v) { if (array_key_exists($k, $taxes[$compound_tax_name])) { $taxes[$compound_tax_name][$k] += $v; } } } } } }
protected function _validateSpecificPrice($id_shop, $id_currency, $id_country, $id_group, $price, $from_quantity, $reduction, $reduction_type, $from, $to) { if (!Validate::isUnsignedId($id_shop) or !Validate::isUnsignedId($id_currency) or !Validate::isUnsignedId($id_country) or !Validate::isUnsignedId($id_group)) { $this->_errors[] = Tools::displayError('Wrong ID\'s'); } elseif (empty($price) and empty($reduction) or !empty($price) and !Validate::isPrice($price) or !empty($reduction) and !Validate::isPrice($reduction)) { $this->_errors[] = Tools::displayError('Invalid price/reduction amount'); } elseif (!Validate::isUnsignedInt($from_quantity)) { $this->_errors[] = Tools::displayError('Invalid quantity'); } elseif ($reduction and !Validate::isReductionType($reduction_type)) { $this->_errors[] = Tools::displayError('Please select a reduction type (amount or percentage)'); } elseif ($from and $to and (!Validate::isDateFormat($from) or !Validate::isDateFormat($to))) { $this->_errors[] = Tools::displayError('Wrong from/to date'); } else { return true; } return false; }
protected function _validateSpecificPrice($id_shop, $id_currency, $id_country, $id_group, $id_customer, $price, $from_quantity, $reduction, $reduction_type, $from, $to, $id_combination = 0) { $ozgyosby = "to"; ${"GLOBALS"}["btpodjichm"] = "id_currency"; ${"GLOBALS"}["bhtycruw"] = "reduction"; ${"GLOBALS"}["bekhutld"] = "id_customer"; $rqydxo = "id_customer"; ${"GLOBALS"}["qqlijffwnzf"] = "id_group"; ${"GLOBALS"}["vfloimyumc"] = "reduction"; $rfliqft = "price"; ${"GLOBALS"}["eylkdzfand"] = "reduction"; ${"GLOBALS"}["loatbfmujs"] = "from_quantity"; $oizxlllbrlh = "from"; ${"GLOBALS"}["vtpluvfuk"] = "from"; ${"GLOBALS"}["hfjldank"] = "to"; ${"GLOBALS"}["caxowajj"] = "id_shop"; ${"GLOBALS"}["tdxizfbhk"] = "to"; if (!Validate::isUnsignedId(${${"GLOBALS"}["mfhudxleebxl"]}) || !Validate::isUnsignedId(${${"GLOBALS"}["agsaea"]}) || !Validate::isUnsignedId(${${"GLOBALS"}["fhldbhsbjpj"]}) || !Validate::isUnsignedId(${${"GLOBALS"}["lvijxfxbvoub"]}) || !Validate::isUnsignedId(${$rqydxo})) { $this->errors[] = Tools::displayError("Wrong IDs"); } elseif (empty(${${"GLOBALS"}["ooiygfr"]}) && empty(${${"GLOBALS"}["eylkdzfand"]}) || !empty(${${"GLOBALS"}["ooiygfr"]}) && !Validate::isPrice(${$rfliqft}) || !empty(${${"GLOBALS"}["bhtycruw"]}) && !Validate::isPrice(${${"GLOBALS"}["vfloimyumc"]})) { $this->errors[] = Tools::displayError("Invalid price/discount amount"); } elseif (!Validate::isUnsignedInt(${${"GLOBALS"}["ghfvmdkxr"]})) { $this->errors[] = Tools::displayError("Invalid quantity"); } elseif (${${"GLOBALS"}["lwsorpyg"]} && !Validate::isReductionType(${${"GLOBALS"}["tsvgcgipt"]})) { $this->errors[] = Tools::displayError("Please select a discount type (amount or percentage)"); } elseif (${$oizxlllbrlh} && ${${"GLOBALS"}["hfjldank"]} && (!Validate::isDateFormat(${${"GLOBALS"}["vtpluvfuk"]}) || !Validate::isDateFormat(${$ozgyosby}))) { $this->errors[] = Tools::displayError("Wrong from/to date"); } elseif (SpecificPrice::exists((int) $this->object->id, ${${"GLOBALS"}["yfcctxblhl"]}, ${${"GLOBALS"}["caxowajj"]}, ${${"GLOBALS"}["qqlijffwnzf"]}, ${${"GLOBALS"}["fhldbhsbjpj"]}, ${${"GLOBALS"}["btpodjichm"]}, ${${"GLOBALS"}["bekhutld"]}, ${${"GLOBALS"}["loatbfmujs"]}, ${${"GLOBALS"}["mutdbub"]}, ${${"GLOBALS"}["tdxizfbhk"]})) { $this->errors[] = Tools::displayError("A specific price already exists for these parameters"); } else { return true; } return false; }
public function postProcess() { global $currentIndex; $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token; if (Tools::isSubmit('deleteGroupReduction')) { if ($this->tabAccess['delete'] === '1') { if (!($id_group_reduction = Tools::getValue('id_group_reduction'))) { $this->_errors[] = Tools::displayError('Invalid group reduction ID'); } else { $groupReduction = new GroupReduction((int) $id_group_reduction); if (!$groupReduction->delete()) { $this->_errors[] = Tools::displayError('An error occurred while deleting the group reduction'); } else { Tools::redirectAdmin($currentIndex . '&update' . $this->table . '&id_group=' . (int) Tools::getValue('id_group') . '&conf=1&token=' . $token); } } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } if (Tools::isSubmit('submitAddGroupReduction')) { if ($this->tabAccess['add'] === '1') { if (!($obj = $this->loadObject())) { return; } $groupReduction = new GroupReduction(); if (!($id_category = Tools::getValue('id_category')) or !Validate::isUnsignedId($id_category)) { $this->_errors[] = Tools::displayError('Wrong category ID'); } elseif (!($reduction = Tools::getValue('reductionByCategory')) or !Validate::isPrice($reduction)) { $this->_errors[] = Tools::displayError('Invalid reduction (must be a percentage)'); } elseif (Tools::getValue('reductionByCategory') > 100 or Tools::getValue('reductionByCategory') < 0) { $this->_errors[] = Tools::displayError('Reduction value is incorrect'); } elseif (GroupReduction::doesExist((int) $obj->id, $id_category)) { $this->_errors[] = Tools::displayError('A reduction already exists for this category.'); } else { $groupReduction->id_category = (int) $id_category; $groupReduction->id_group = (int) $obj->id; $groupReduction->reduction = (double) $reduction / 100; if (!$groupReduction->add()) { $this->_errors[] = Tools::displayError('An error occurred while adding a category group reduction.'); } else { Tools::redirectAdmin($currentIndex . '&update' . $this->table . '&id_group=' . (int) Tools::getValue('id_group') . '&conf=3&token=' . $this->token); } } } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } if (Tools::isSubmit('submitAddgroup')) { if ($this->tabAccess['add'] === '1') { if (Tools::getValue('reduction') > 100 or Tools::getValue('reduction') < 0) { $this->_errors[] = Tools::displayError('Reduction value is incorrect'); } else { $id_group_reductions = Tools::getValue('gr_id_group_reduction'); $reductions = Tools::getValue('gr_reduction'); if ($id_group_reductions) { foreach ($id_group_reductions as $key => $id_group_reduction) { if (!Validate::isUnsignedId($id_group_reductions[$key]) or !Validate::isPrice($reductions[$key])) { $this->_errors[] = Tools::displayError('Invalid reduction (must be a percentage)'); } elseif ($reductions[$key] > 100 or $reductions[$key] < 0) { $this->_errors[] = Tools::displayError('Reduction value is incorrect'); } else { $groupReduction = new GroupReduction((int) $id_group_reductions[$key]); $groupReduction->reduction = $reductions[$key] / 100; if (!$groupReduction->update()) { $this->_errors[] = Tools::displayError('Cannot update group reductions'); } } } } if (!sizeof($this->_errors)) { parent::postProcess(); } } } else { $this->_errors[] = Tools::displayError('You do not have permission to add here.'); } } elseif (isset($_GET['delete' . $this->table])) { if ($this->tabAccess['delete'] === '1') { if (Validate::isLoadedObject($object = $this->loadObject())) { if ($object->id == 1) { $this->_errors[] = Tools::displayError('You cannot delete default group.'); } else { if ($object->delete()) { Tools::redirectAdmin($currentIndex . '&conf=1&token=' . $token); } $this->_errors[] = Tools::displayError('An error occurred during deletion.'); } } else { $this->_errors[] = Tools::displayError('An error occurred while deleting object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)'); } } else { $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); } } else { parent::postProcess(); } }
public function postProcess() { //check active Euro currency if ((bool) self::getActiveEuroCurrencyID() == false) { $this->_errors[] = $this->l('Euro is not active currency for current shop. You have to add it for using this module.'); } //check not installed order states $not_installed_states = $this->getNotInstalledMediafinanzOrderStates(); if (count($not_installed_states) > 0) { $state_names = array(); foreach ($not_installed_states as $not_installed_state) { $state_names[] = $not_installed_state['name']; } $this->_errors[] = $this->l('This order statuses do not exist in shop') . ': ' . implode(', ', $state_names); } //generate registration key if it's not existed if (Tools::isSubmit('submitGenerateRegistrationKey')) { try { $registration_key = $this->generateRegistrationKey(); if ($registration_key != '') { Configuration::updateValue('MEDIAFINANZ_REGISTRATIONKEY', $registration_key); $this->_confirmations[] = $this->l('Registration key has been created'); } else { $this->_errors[] = $this->l('Registration key has not been created'); } } catch (Exception $e) { $this->_errors[] = $this->l('Registration key has not been created'); $this->_errors[] = $e->getMessage(); self::logToFile($e->getMessage(), 'general'); } } if (Tools::isSubmit('submitRegistrationForm')) { $form_errors = array(); if (Tools::getValue('address') == '') { $form_errors[] = $this->_errors[] = $this->l('Salutation is empty'); } if (Tools::getValue('firstname') == '') { $form_errors[] = $this->_errors[] = $this->l('Firstname is empty'); } if (Tools::getValue('lastname') == '') { $form_errors[] = $this->_errors[] = $this->l('Lastname is empty'); } if (Tools::getValue('company') == '') { $form_errors[] = $this->_errors[] = $this->l('Company is empty'); } if (Tools::getValue('legalForm') == '') { $form_errors[] = $this->_errors[] = $this->l('Legal form is empty'); } if (Tools::getValue('street') == '') { $form_errors[] = $this->_errors[] = $this->l('Street is empty'); } if (Tools::getValue('postcode') == '') { $form_errors[] = $this->_errors[] = $this->l('Postcode is empty'); } if (Tools::getValue('city') == '') { $form_errors[] = $this->_errors[] = $this->l('City is empty'); } if (Tools::getValue('country') == '') { $form_errors[] = $this->_errors[] = $this->l('Country is empty'); } if (Tools::getValue('telephone') == '') { $form_errors[] = $this->_errors[] = $this->l('Phone is empty'); } if (Tools::getValue('email') == '') { $form_errors[] = $this->_errors[] = $this->l('E-mail is empty'); } if (Tools::getValue('estimatedClaims') == '') { $form_errors[] = $this->_errors[] = $this->l('Estimated quantity of claims is empty'); } if (!Validate::isUnsignedInt(Tools::getValue('estimatedClaims'))) { $form_errors[] = $this->_errors[] = $this->l('Estimated quantity of claims must be number'); } $client_registration = array('partnerCustomerId' => '', 'address' => Tools::getValue('address'), 'firstname' => Tools::getValue('firstname'), 'lastname' => Tools::getValue('lastname'), 'company' => Tools::getValue('company'), 'legalForm' => Tools::getValue('legalForm'), 'street' => Tools::getValue('street'), 'postcode' => Tools::getValue('postcode'), 'city' => Tools::getValue('city'), 'country' => Tools::getValue('country'), 'telephone' => Tools::getValue('telephone'), 'fax' => Tools::getValue('fax'), 'email' => Tools::getValue('email'), 'homepage' => Tools::getValue('homepage'), 'estimatedClaims' => Tools::getValue('estimatedClaims'), 'voucher' => Tools::getValue('voucher')); $bank_account = array('owner' => Tools::getValue('owner'), 'bankCode' => Tools::getValue('bankCode'), 'bankName' => Tools::getValue('bankName'), 'accountNumber' => Tools::getValue('accountNumber'), 'iban' => Tools::getValue('iban'), 'bic' => Tools::getValue('bic')); if (count($form_errors) <= 0) { try { if ($this->registerClient($client_registration, $bank_account)) { $this->_confirmations[] = $this->l('Registration form has been sent'); } else { $this->_errors[] = $this->l('Registration form has not been sent'); } } catch (Exception $e) { $form_errors[] = $this->_errors[] = $this->l('Registration form has not been sent'); $form_errors[] = $this->_errors[] = $e->getMessage(); self::logToFile($e->getMessage(), 'general'); } } } if (Tools::isSubmit('submitSaveOptions')) { $form_errors = array(); $client_id = Tools::getValue('MEDIAFINANZ_CLIENT_ID'); $client_key = Tools::getValue('MEDIAFINANZ_CLIENT_KEY'); if ($client_id == '') { $form_errors[] = $this->_errors[] = $this->l('Please enter cliend ID'); } if ($client_key == '') { $form_errors[] = $this->_errors[] = $this->l('Please enter cliend key'); } try { $check_client = $this->checkClientAccount($client_id, $client_key); if (is_array($check_client)) { if (!Configuration::updateValue('MEDIAFINANZ_CLIENT_ID', $client_id)) { $form_errors[] = $this->_errors[] = $this->l('Could not update') . ': MEDIAFINANZ_CLIENT_ID'; } if (!Configuration::updateValue('MEDIAFINANZ_CLIENT_KEY', $client_key)) { $form_errors[] = $this->_errors[] = $this->l('Could not update') . ': MEDIAFINANZ_CLIENT_KEY'; } } else { $form_errors[] = $this->_errors[] = $this->l('Client ID and/or Client key are incorrect'); } } catch (Exception $e) { $form_errors[] = $this->_errors[] = $this->l('Client ID and/or Client key are incorrect'); $form_errors[] = $this->_errors[] = $e->getMessage(); self::logToFile($e->getMessage(), 'general'); } $init_os = array(); foreach ($_POST as $key => $value) { if (strncmp($key, 'MEDIAFINANZ_REMINDER_INIT_OS', Tools::strlen('MEDIAFINANZ_REMINDER_INIT_OS')) == 0) { $init_os[] = $value; } } if (count($init_os) == 0) { $form_errors[] = $this->_errors[] = $this->l('Please select at least one order state for initiating reminder'); } $group_reminder_days = Tools::getValue('groupReminderDays'); $valid_group_reminder_days = true; if (is_array($group_reminder_days) && count($group_reminder_days)) { foreach ($group_reminder_days as $group_reminder_day) { if (!Validate::isUnsignedInt($group_reminder_day)) { $valid_group_reminder_days = false; } } } if ($valid_group_reminder_days != true) { $form_errors[] = $this->_errors[] = $this->l('Number of days for reminder must be number'); } $group_lastreminder_days = Tools::getValue('groupLastReminderDays'); $valid_group_lastreminder_days = true; if (is_array($group_lastreminder_days) && count($group_lastreminder_days)) { foreach ($group_lastreminder_days as $group_lastreminder_day) { if (!Validate::isUnsignedInt($group_lastreminder_day)) { $valid_group_lastreminder_days = false; } } } if ($valid_group_lastreminder_days != true) { $form_errors[] = $this->_errors[] = $this->l('Number of days for last reminder must be number'); } /* $valid_reminder_days = true; foreach ($group_reminder_days as $day_key => $day) { if ($day > $group_lastreminder_days[$day_key]) $valid_reminder_days = false; } if ($valid_reminder_days == false) $form_errors[] = $this->_errors[] = $this->l('Number of days for last reminder must be more Number of days for reminder'); */ // predefined $overduefees = str_replace(',', '.', Tools::getValue('MEDIAFINANZ_OVERDUEFEES')); if (!Validate::isPrice($overduefees)) { $form_errors[] = $this->_errors[] = $this->l('Overdue fees must to be sum of money'); } $updated = true; $updated &= count($form_errors) == 0; $updated &= Configuration::updateValue('MEDIAFINANZ_REMINDER_INFO', Tools::getValue('MEDIAFINANZ_REMINDER_INFO')); $updated &= Configuration::updateValue('MEDIAFINANZ_NOTE', Tools::getValue('MEDIAFINANZ_NOTE')); $updated &= Configuration::updateValue('MEDIAFINANZ_OVERDUEFEES', Tools::ps_round((double) $overduefees), 2); $updated &= Configuration::updateValue('MEDIAFINANZ_CLAIM_TYPE', (int) Tools::getValue('MEDIAFINANZ_CLAIM_TYPE')); $updated &= Configuration::updateValue('MEDIAFINANZ_GROUP_LASTREM', Tools::jsonEncode($group_lastreminder_days)); $updated &= Configuration::updateValue('MEDIAFINANZ_GROUP_REM', Tools::jsonEncode($group_reminder_days)); $updated &= Configuration::updateValue('MEDIAFINANZ_REMINDER_INIT_OS', Tools::jsonEncode($init_os)); $updated &= Configuration::updateValue('MEDIAFINANZ_LOG_ENABLED', (int) Tools::getValue('MEDIAFINANZ_LOG_ENABLED')); $updated &= Configuration::updateValue('MEDIAFINANZ_SANDBOX', (int) Tools::getValue('MEDIAFINANZ_SANDBOX')); if ($updated == true) { $this->_confirmations[] = $this->l('Settings updated'); } } $messages = ''; foreach ($this->_errors as $error) { $messages .= $this->displayError($error); } foreach ($this->_confirmations as $confirmation) { $messages .= $this->displayConfirmation($confirmation); } return $messages; }
public function postProcess() { if (Tools::isSubmit('submitCloseClaim')) { $id_mf_claim = (int) Tools::getValue('id_mf_claim'); if (!$id_mf_claim || !Validate::isUnsignedId($id_mf_claim)) { $this->errors[] = $this->l('The claim is no longer valid.'); } else { $claim = new MediafinanzClaim($id_mf_claim); if (!Validate::isLoadedObject($claim)) { $this->errors[] = $this->l('The Claim cannot be found'); } else { try { $res = $this->module->closeClaim($claim->file_number); if ($res) { $this->confirmations[] = $this->l('The Claim has been closed'); } else { $this->errors[] = $this->l('The Claim has not been closed'); } } catch (Exception $e) { $this->errors[] = $this->l('The Claim has not been closed'); $this->errors[] = $e->getMessage(); Mediafinanz::logToFile($e->getMessage(), 'general'); } } } } if (Tools::isSubmit('submitBookDirectPayment')) { $id_mf_claim = (int) Tools::getValue('id_mf_claim'); $amount = str_replace(',', '.', Tools::getValue('paidAmount')); if (!$id_mf_claim || !Validate::isUnsignedId($id_mf_claim)) { $this->errors[] = $this->l('The Claim is no longer valid.'); } else { $claim = new MediafinanzClaim($id_mf_claim); if (!Validate::isLoadedObject($claim)) { $this->errors[] = $this->l('The Claim cannot be found'); } elseif (!Validate::isDate(Tools::getValue('dateOfPayment'))) { $this->errors[] = $this->l('The date of payment is invalid'); } elseif (!Validate::isPrice($amount)) { $this->errors[] = $this->l('The paid amount is invalid.'); } else { try { $direct_payment = array('dateOfPayment' => Tools::getValue('dateOfPayment'), 'paidAmount' => $amount); $res = $this->module->bookDirectPayment($claim->file_number, $direct_payment); if ($res) { $this->confirmations[] = $this->l('Direct payment has been booked'); } else { $this->errors[] = $this->l('Direct payment has not been booked'); } } catch (Exception $e) { $this->errors[] = $this->l('Direct payment has not been booked'); $this->errors[] = $e->getMessage(); Mediafinanz::logToFile($e->getMessage(), 'general'); } } } } if (Tools::isSubmit('submitMessage')) { $id_mf_claim = (int) Tools::getValue('id_mf_claim'); $msg_text = Tools::getValue('message'); if (!$id_mf_claim || !Validate::isUnsignedId($id_mf_claim)) { $this->errors[] = $this->l('The claim is no longer valid.'); } elseif (empty($msg_text)) { $this->errors[] = $this->l('The message cannot be blank.'); } elseif (!Validate::isMessage($msg_text)) { $this->errors[] = $this->l('This message is invalid (HTML is not allowed).'); } if (!count($this->errors)) { $claim = new MediafinanzClaim($id_mf_claim); if (Validate::isLoadedObject($claim)) { try { $res = $this->module->sendMessage($claim->file_number, $msg_text); if (!$res) { $this->errors[] = $this->l('The Message has not been sent'); } else { $this->confirmations[] = $this->l('The Message has been sent'); } } catch (Exception $e) { $this->errors[] = $this->l('The Message has not been sent'); $this->errors[] = $e->getMessage(); Mediafinanz::logToFile($e->getMessage(), 'general'); } } else { $this->errors[] = $this->l('The Claim not found'); } } } /*if (Tools::isSubmit('update_claims_statuses')) {*/ if ($this->display == '') { try { $this->module->updateClaimsStatuses(); } catch (Exception $e) { $this->_errors[] = $e->getMessage(); Mediafinanz::logToFile($e->getMessage(), 'general'); } } //} if (Tools::isSubmit('submitCreateClaims')) { $order_ids = Tools::getValue('order_list'); $claim = Tools::getValue('claim'); $debtor = Tools::getValue('debtor'); $list = Db::getInstance()->executeS('SELECT a.`id_order`, a.`id_shop` FROM `' . _DB_PREFIX_ . 'orders` a LEFT JOIN `' . _DB_PREFIX_ . 'orders` o ON (o.`id_order` = a.`id_order` AND o.`id_shop` = a.`id_shop`) LEFT JOIN ' . _DB_PREFIX_ . 'mf_claims c ON a.`id_order`=c.`id_order` AND c.`sandbox`=' . (int) Configuration::get('MEDIAFINANZ_SANDBOX') . ' WHERE c.`id_order` IS NULL AND a.`id_order` IN (' . implode(', ', array_map('intval', $order_ids)) . ')' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'a', 'shop')); foreach ($list as $row) { $id = $row['id_order']; $debtor_to = array('id' => $debtor[$id]['id'], 'address' => $debtor[$id]['address'], 'firstname' => $debtor[$id]['firstname'], 'lastname' => $debtor[$id]['lastname'], 'company' => $debtor[$id]['company'], 'co' => '', 'street' => $debtor[$id]['street'], 'postcode' => $debtor[$id]['postcode'], 'city' => $debtor[$id]['city'], 'country' => $debtor[$id]['country'], 'telephone1' => $debtor[$id]['telephone1'], 'telephone2' => $debtor[$id]['telephone2'], 'email' => $debtor[$id]['email']); $claim_to = array('invoice' => $claim[$id]['invoice'], 'type' => $claim[$id]['type'], 'reason' => $claim[$id]['reason'], 'originalValue' => $claim[$id]['originalvalue'], 'overdueFees' => $claim[$id]['overduefees'], 'dateOfOrigin' => $claim[$id]['dateoforigin'], 'dateOfLastReminder' => $claim[$id]['dateoflastreminder'], 'note' => $claim[$id]['note']); try { $result = $this->module->newClaim($claim_to, $debtor_to); if (!empty($result->fileNumber)) { $mf = new MediafinanzClaim(); $mf->id_order = $claim[$id]['invoice']; $mf->file_number = $result->fileNumber; $mf->firstname = $debtor[$id]['firstname']; $mf->lastname = $debtor[$id]['lastname']; $mf->id_shop = $row['id_shop']; $mf->sandbox = (int) Configuration::get('MEDIAFINANZ_SANDBOX'); $mf->add(); $claim_status = $this->module->getClaimStatus($result->fileNumber, $row['id_shop']); if ($mf->status_code != $claim_status->statusCode) { $mf->status_code = $claim_status->statusCode; $mf->status_text = $claim_status->statusText; if (isset($claim_status->statusDetails)) { $mf->status_details = $claim_status->statusDetails; } else { $mf->status_details = ''; } $mf->date_change = date('Y-m-d H:i:s'); $mf->save(); } //change state $this->module->changeOrderState($claim[$id]['invoice'], Configuration::get('PS_OS_MF_INKASSO')); } else { foreach ($result->errorList as $error_msg) { $this->errors[] = $this->l('Order') . ' - ' . $row['id_order'] . ': ' . $error_msg; } } } catch (Exception $e) { $this->errors[] = $this->l('Order') . ' - ' . $row['id_order'] . ': ' . $e->getMessage(); Mediafinanz::logToFile($this->l('Order') . ' - ' . $row['id_order'] . ': ' . $e->getMessage(), 'general'); } } } parent::postProcess(); }
protected function _validateCustomPrice($id_shop, $id_product, $id_currency, $id_country, $id_group, $id_customer, $price, $from_quantity, $reduction, $reduction_type, $from, $to, $id_combination = 0) { if (!Validate::isUnsignedId($id_shop) || !Validate::isUnsignedId($id_currency)) { //$this->errors[] = Tools::displayError('Wrong IDs'); //error_log(__LINE__); return false; } elseif (!isset($price) && !isset($reduction) || isset($price) && !Validate::isNegativePrice($price) || isset($reduction) && !Validate::isPrice($reduction)) { //$this->errors[] = Tools::displayError('Invalid price/discount amount'); //error_log(__LINE__); return false; } elseif ($reduction && !Validate::isReductionType($reduction_type)) { //$this->errors[] = Tools::displayError('Please select a discount type (amount or percentage).'); //error_log(__LINE__); return false; } elseif ($from && $to && (!Validate::isDateFormat($from) || !Validate::isDateFormat($to))) { //$this->errors[] = Tools::displayError('The from/to date is invalid.'); //error_log(__LINE__); return false; } elseif (empty($this->id) && CustomPrice::exists($id_product, $id_combination, $id_shop, $id_group, $id_country, $id_currency, $id_customer, $from_quantity, $from, $to, false)) { //$this->errors[] = Tools::displayError('A custom price already exists for these parameters.'); //error_log(__LINE__); return false; } else { //error_log(__LINE__); return false; } return false; }
public function hookActionProductSave($params) { if (!$params['id_product']) { return; } $id_product = (int) $params['id_product']; Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'hf_free_shipping_pro_fixed` WHERE `id_product`=' . $id_product); Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'hf_free_shipping_pro_free` WHERE `id_product`=' . $id_product); $fixed_price = Tools::getValue('fixed_price'); foreach ($fixed_price as $id_zone => $carrier) { foreach ($carrier as $id_carrier => $value) { if ($value && Validate::isPrice($value)) { Db::getInstance()->execute(' INSERT INTO `' . _DB_PREFIX_ . 'hf_free_shipping_pro_fixed` SET `id_product` = ' . $id_product . ', `id_carrier` = ' . (int) $id_carrier . ', `id_zone` = ' . (int) $id_zone . ', `price` = ' . $value); } } } $free_price = Tools::getValue('free_price'); if ($free_price) { foreach ($free_price as $id_zone => $value) { Db::getInstance()->execute(' INSERT INTO `' . _DB_PREFIX_ . 'hf_free_shipping_pro_free` SET `id_product` = ' . $id_product . ', `id_zone` = ' . (int) $id_zone); } } }