protected function supplyOrdersImportOne($info, $force_ids, $current_line, $validateOnly = false) { // sets default values if needed AdminImportController::setDefaultValues($info); // if an id is set, instanciates a supply order with this id if possible if (array_key_exists('id', $info) && (int) $info['id'] && SupplyOrder::exists((int) $info['id'])) { $supply_order = new SupplyOrder((int) $info['id']); } elseif (array_key_exists('reference', $info) && $info['reference'] && SupplyOrder::exists(pSQL($info['reference']))) { $supply_order = SupplyOrder::getSupplyOrderByReference(pSQL($info['reference'])); } else { // new supply order $supply_order = new SupplyOrder(); } // gets parameters $id_supplier = (int) $info['id_supplier']; $id_lang = (int) $info['id_lang']; $id_warehouse = (int) $info['id_warehouse']; $id_currency = (int) $info['id_currency']; $reference = pSQL($info['reference']); $date_delivery_expected = pSQL($info['date_delivery_expected']); $discount_rate = (double) $info['discount_rate']; $is_template = (bool) $info['is_template']; $error = ''; // checks parameters if (!Supplier::supplierExists($id_supplier)) { $error = sprintf($this->l('Supplier ID (%d) is not valid (at line %d).'), $id_supplier, $current_line + 1); } if (!Language::getLanguage($id_lang)) { $error = sprintf($this->l('Lang ID (%d) is not valid (at line %d).'), $id_lang, $current_line + 1); } if (!Warehouse::exists($id_warehouse)) { $error = sprintf($this->l('Warehouse ID (%d) is not valid (at line %d).'), $id_warehouse, $current_line + 1); } if (!Currency::getCurrency($id_currency)) { $error = sprintf($this->l('Currency ID (%d) is not valid (at line %d).'), $id_currency, $current_line + 1); } if (empty($supply_order->reference) && SupplyOrder::exists($reference)) { $error = sprintf($this->l('Reference (%s) already exists (at line %d).'), $reference, $current_line + 1); } if (!empty($supply_order->reference) && ($supply_order->reference != $reference && SupplyOrder::exists($reference))) { $error = sprintf($this->l('Reference (%s) already exists (at line %d).'), $reference, $current_line + 1); } if (!Validate::isDateFormat($date_delivery_expected)) { $error = sprintf($this->l('Date format (%s) is not valid (at line %d). It should be: %s.'), $date_delivery_expected, $current_line + 1, $this->l('YYYY-MM-DD')); } elseif (new DateTime($date_delivery_expected) <= new DateTime('yesterday')) { $error = sprintf($this->l('Date (%s) cannot be in the past (at line %d). Format: %s.'), $date_delivery_expected, $current_line + 1, $this->l('YYYY-MM-DD')); } if ($discount_rate < 0 || $discount_rate > 100) { $error = sprintf($this->l('Discount rate (%d) is not valid (at line %d). %s.'), $discount_rate, $current_line + 1, $this->l('Format: Between 0 and 100')); } if ($supply_order->id > 0 && !$supply_order->isEditable()) { $error = sprintf($this->l('Supply Order (%d) is not editable (at line %d).'), $supply_order->id, $current_line + 1); } // if no errors, sets supply order if (empty($error)) { // adds parameters $info['id_ref_currency'] = (int) Currency::getDefaultCurrency()->id; $info['supplier_name'] = pSQL(Supplier::getNameById($id_supplier)); if ($supply_order->id > 0) { $info['id_supply_order_state'] = (int) $supply_order->id_supply_order_state; $info['id'] = (int) $supply_order->id; } else { $info['id_supply_order_state'] = 1; } // sets parameters AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $supply_order); // updatesd($supply_order); $res = false; if ((int) $supply_order->id && ($supply_order->exists((int) $supply_order->id) || $supply_order->exists($supply_order->reference))) { $res = $validateOnly || $supply_order->update(); } else { $supply_order->force_id = (bool) $force_ids; $res = $validateOnly || $supply_order->add(); } // errors if (!$res) { $this->errors[] = sprintf($this->l('Supply Order could not be saved (at line %d).'), $current_line + 1); } } else { $this->errors[] = $error; } }
/** * AdminController::postProcess() override * @see AdminController::postProcess() */ public function postProcess() { $this->is_editing_order = false; // Checks access if (Tools::isSubmit('submitAddsupply_order') && !($this->tabAccess['add'] === '1')) { $this->errors[] = Tools::displayError('You do not have permission to add a supply order.'); } if (Tools::isSubmit('submitBulkUpdatesupply_order_detail') && !($this->tabAccess['edit'] === '1')) { $this->errors[] = Tools::displayError('You do not have permission to edit an order.'); } // Trick to use both Supply Order as template and actual orders if (Tools::isSubmit('is_template')) { $_GET['mod'] = 'template'; } // checks if supply order reference is unique if (Tools::isSubmit('reference')) { // gets the reference $ref = pSQL(Tools::getValue('reference')); if (Tools::getValue('id_supply_order') != 0 && SupplyOrder::getReferenceById((int) Tools::getValue('id_supply_order')) != $ref) { if ((int) SupplyOrder::exists($ref) != 0) { $this->errors[] = Tools::displayError('The reference has to be unique.'); } } elseif (Tools::getValue('id_supply_order') == 0 && (int) SupplyOrder::exists($ref) != 0) { $this->errors[] = Tools::displayError('The reference has to be unique.'); } } if ($this->errors) { return; } // Global checks when add / update a supply order if (Tools::isSubmit('submitAddsupply_order') || Tools::isSubmit('submitAddsupply_orderAndStay')) { $this->action = 'save'; $this->is_editing_order = true; // get supplier ID $id_supplier = (int) Tools::getValue('id_supplier', 0); if ($id_supplier <= 0 || !Supplier::supplierExists($id_supplier)) { $this->errors[] = Tools::displayError('The selected supplier is not valid.'); } // get warehouse id $id_warehouse = (int) Tools::getValue('id_warehouse', 0); if ($id_warehouse <= 0 || !Warehouse::exists($id_warehouse)) { $this->errors[] = Tools::displayError('The selected warehouse is not valid.'); } // get currency id $id_currency = (int) Tools::getValue('id_currency', 0); if ($id_currency <= 0 || (!($result = Currency::getCurrency($id_currency)) || empty($result))) { $this->errors[] = Tools::displayError('The selected currency is not valid.'); } // get delivery date if (Tools::getValue('mod') != 'template' && strtotime(Tools::getValue('date_delivery_expected')) <= strtotime('-1 day')) { $this->errors[] = Tools::displayError('The specified date cannot be in the past.'); } // gets threshold $quantity_threshold = Tools::getValue('load_products'); if (is_numeric($quantity_threshold)) { $quantity_threshold = (int) $quantity_threshold; } else { $quantity_threshold = null; } if (!count($this->errors)) { // forces date for templates if (Tools::isSubmit('is_template') && !Tools::getValue('date_delivery_expected')) { $_POST['date_delivery_expected'] = date('Y-m-d h:i:s'); } // specify initial state $_POST['id_supply_order_state'] = 1; //defaut creation state // specify global reference currency $_POST['id_ref_currency'] = Currency::getDefaultCurrency()->id; // specify supplier name $_POST['supplier_name'] = Supplier::getNameById($id_supplier); //specific discount check $_POST['discount_rate'] = (double) str_replace(array(' ', ','), array('', '.'), Tools::getValue('discount_rate', 0)); } // manage each associated product $this->manageOrderProducts(); // if the threshold is defined and we are saving the order if (Tools::isSubmit('submitAddsupply_order') && Validate::isInt($quantity_threshold)) { $this->loadProducts((int) $quantity_threshold); } } // Manage state change if (Tools::isSubmit('submitChangestate') && Tools::isSubmit('id_supply_order') && Tools::isSubmit('id_supply_order_state')) { if ($this->tabAccess['edit'] != '1') { $this->errors[] = Tools::displayError('You do not have permission to change the order status.'); } // get state ID $id_state = (int) Tools::getValue('id_supply_order_state', 0); if ($id_state <= 0) { $this->errors[] = Tools::displayError('The selected supply order status is not valid.'); } // get supply order ID $id_supply_order = (int) Tools::getValue('id_supply_order', 0); if ($id_supply_order <= 0) { $this->errors[] = Tools::displayError('The supply order ID is not valid.'); } if (!count($this->errors)) { // try to load supply order $supply_order = new SupplyOrder($id_supply_order); if (Validate::isLoadedObject($supply_order)) { // get valid available possible states for this order $states = SupplyOrderState::getSupplyOrderStates($supply_order->id_supply_order_state); foreach ($states as $state) { // if state is valid, change it in the order if ($id_state == $state['id_supply_order_state']) { $new_state = new SupplyOrderState($id_state); $old_state = new SupplyOrderState($supply_order->id_supply_order_state); // special case of validate state - check if there are products in the order and the required state is not an enclosed state if ($supply_order->isEditable() && !$supply_order->hasEntries() && !$new_state->enclosed) { $this->errors[] = Tools::displayError('It is not possible to change the status of this order because you did not order any products.'); } if (!count($this->errors)) { $supply_order->id_supply_order_state = $state['id_supply_order_state']; if ($supply_order->save()) { if ($new_state->pending_receipt) { $supply_order_details = $supply_order->getEntries(); foreach ($supply_order_details as $supply_order_detail) { $is_present = Stock::productIsPresentInStock($supply_order_detail['id_product'], $supply_order_detail['id_product_attribute'], $supply_order->id_warehouse); if (!$is_present) { $stock = new Stock(); $stock_params = array('id_product_attribute' => $supply_order_detail['id_product_attribute'], 'id_product' => $supply_order_detail['id_product'], 'physical_quantity' => 0, 'price_te' => $supply_order_detail['price_te'], 'usable_quantity' => 0, 'id_warehouse' => $supply_order->id_warehouse); // saves stock in warehouse $stock->hydrate($stock_params); $stock->add(); } } } // if pending_receipt, // or if the order is being canceled, // or if the order is received completely // synchronizes StockAvailable if ($new_state->pending_receipt && !$new_state->receipt_state || ($old_state->receipt_state || $old_state->pending_receipt) && $new_state->enclosed && !$new_state->receipt_state || $new_state->receipt_state && $new_state->enclosed) { $supply_order_details = $supply_order->getEntries(); $products_done = array(); foreach ($supply_order_details as $supply_order_detail) { if (!in_array($supply_order_detail['id_product'], $products_done)) { StockAvailable::synchronize($supply_order_detail['id_product']); $products_done[] = $supply_order_detail['id_product']; } } } $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token; $redirect = self::$currentIndex . '&token=' . $token; $this->redirect_after = $redirect . '&conf=5'; } } } } } else { $this->errors[] = Tools::displayError('The selected supplier is not valid.'); } } } // updates receipt if (Tools::isSubmit('submitBulkUpdatesupply_order_detail') && Tools::isSubmit('id_supply_order')) { $this->postProcessUpdateReceipt(); } // use template to create a supply order if (Tools::isSubmit('create_supply_order') && Tools::isSubmit('id_supply_order')) { $this->postProcessCopyFromTemplate(); } if (!count($this->errors) && $this->is_editing_order || !$this->is_editing_order) { parent::postProcess(); } }
public static function refreshCurrencies() { // Parse if (!($feed = Tools::simplexml_load_file('http://api.prestashop.com/xml/currencies.xml'))) { return Tools::displayError('Cannot parse feed.'); } // Default feed currency (EUR) $isoCodeSource = strval($feed->source['iso_code']); if (!($default_currency = Currency::getDefaultCurrency())) { return Tools::displayError('No default currency'); } $currencies = Currency::getCurrencies(true, false); foreach ($currencies as $currency) { if ($currency->id != $default_currency->id) { $currency->refreshCurrency($feed->list, $isoCodeSource, $default_currency); } } }
/** * get the total price of the shopping cart as Danish Kroner * @param Cart|Order $cart * @return floate */ public function __getPriceDkk($cart, $t = 1) { /* t==1 use prestashop to convert in Cart Class */ $_shop_currency = Currency::getDefaultCurrency(); $_cart_currency = new Currency($cart->id_currency); if ($t == 1) { $oldc = $cart->id_currency; $cart->id_currency = (int) Currency::getIdByIsoCode('DKK'); $price = $cart->getOrderTotal(true, Cart::BOTH); $cart->id_currency = $oldc; return $price; // $price = $cart->getOrderTotal(true, Cart::BOTH); // if ($cart->id_currency != $_shop_currency->id) { // $_shop_price = ($price / $_cart_currency->conversion_rate); // } else // $_shop_price = $price; // return Tools::convertPrice($_shop_price, Currency::getCurrencyInstance((int) (Currency::getIdByIsoCode('DKK')))); } else { /* t!=1 convert manualy */ $_cart_price = $cart->total_paid; $_dkk_currency = new Currency(Currency::getIdByIsoCode('DKK')); if ($_cart_currency->id != $_shop_currency->id) { /* convert price to shop default */ $_shop_price = $_cart_price / $_cart_currency->conversion_rate; } else { $_shop_price = $_cart_price; } if (strtoupper($_shop_currency->iso_code) != "DKK") { /* convert price to DKK */ return $_shop_price * $_dkk_currency->conversion_rate; } else { return $_shop_price; } } }
public function renderView() { /** @var Customer $customer */ if (!($customer = $this->loadObject())) { return; } $this->context->customer = $customer; $gender = new Gender($customer->id_gender, $this->context->language->id); $gender_image = $gender->getImage(); $customer_stats = $customer->getStats(); $sql = 'SELECT SUM(total_paid_real) FROM ' . _DB_PREFIX_ . 'orders WHERE id_customer = %d AND valid = 1'; if ($total_customer = Db::getInstance()->getValue(sprintf($sql, $customer->id))) { $sql = 'SELECT SQL_CALC_FOUND_ROWS COUNT(*) FROM ' . _DB_PREFIX_ . 'orders WHERE valid = 1 AND id_customer != ' . (int) $customer->id . ' GROUP BY id_customer HAVING SUM(total_paid_real) > %d'; Db::getInstance()->getValue(sprintf($sql, (int) $total_customer)); $count_better_customers = (int) Db::getInstance()->getValue('SELECT FOUND_ROWS()') + 1; } else { $count_better_customers = '-'; } $orders = Order::getCustomerOrders($customer->id, true); $total_orders = count($orders); for ($i = 0; $i < $total_orders; $i++) { $orders[$i]['total_paid_real_not_formated'] = $orders[$i]['total_paid_real']; $orders[$i]['total_paid_real'] = Tools::displayPrice($orders[$i]['total_paid_real'], new Currency((int) $orders[$i]['id_currency'])); } $messages = CustomerThread::getCustomerMessages((int) $customer->id); $total_messages = count($messages); for ($i = 0; $i < $total_messages; $i++) { $messages[$i]['message'] = substr(strip_tags(html_entity_decode($messages[$i]['message'], ENT_NOQUOTES, 'UTF-8')), 0, 75); $messages[$i]['date_add'] = Tools::displayDate($messages[$i]['date_add'], null, true); if (isset(self::$meaning_status[$messages[$i]['status']])) { $messages[$i]['status'] = self::$meaning_status[$messages[$i]['status']]; } } $groups = $customer->getGroups(); $total_groups = count($groups); for ($i = 0; $i < $total_groups; $i++) { $group = new Group($groups[$i]); $groups[$i] = array(); $groups[$i]['id_group'] = $group->id; $groups[$i]['name'] = $group->name[$this->default_form_language]; } $total_ok = 0; $orders_ok = array(); $orders_ko = array(); foreach ($orders as $order) { if (!isset($order['order_state'])) { $order['order_state'] = $this->l('There is no status defined for this order.'); } if ($order['valid']) { $orders_ok[] = $order; $total_ok += $order['total_paid_real_not_formated']; } else { $orders_ko[] = $order; } } $products = $customer->getBoughtProducts(); $carts = Cart::getCustomerCarts($customer->id); $total_carts = count($carts); for ($i = 0; $i < $total_carts; $i++) { $cart = new Cart((int) $carts[$i]['id_cart']); $this->context->cart = $cart; $currency = new Currency((int) $carts[$i]['id_currency']); $this->context->currency = $currency; $summary = $cart->getSummaryDetails(); $carrier = new Carrier((int) $carts[$i]['id_carrier']); $carts[$i]['id_cart'] = sprintf('%06d', $carts[$i]['id_cart']); $carts[$i]['date_add'] = Tools::displayDate($carts[$i]['date_add'], null, true); $carts[$i]['total_price'] = Tools::displayPrice($summary['total_price'], $currency); $carts[$i]['name'] = $carrier->name; } $this->context->currency = Currency::getDefaultCurrency(); $sql = 'SELECT DISTINCT cp.id_product, c.id_cart, c.id_shop, cp.id_shop AS cp_id_shop FROM ' . _DB_PREFIX_ . 'cart_product cp JOIN ' . _DB_PREFIX_ . 'cart c ON (c.id_cart = cp.id_cart) JOIN ' . _DB_PREFIX_ . 'product p ON (cp.id_product = p.id_product) WHERE c.id_customer = ' . (int) $customer->id . ' AND NOT EXISTS ( SELECT 1 FROM ' . _DB_PREFIX_ . 'orders o JOIN ' . _DB_PREFIX_ . 'order_detail od ON (o.id_order = od.id_order) WHERE product_id = cp.id_product AND o.valid = 1 AND o.id_customer = ' . (int) $customer->id . ' )'; $interested = Db::getInstance()->executeS($sql); $total_interested = count($interested); for ($i = 0; $i < $total_interested; $i++) { $product = new Product($interested[$i]['id_product'], false, $this->default_form_language, $interested[$i]['id_shop']); if (!Validate::isLoadedObject($product)) { continue; } $interested[$i]['url'] = $this->context->link->getProductLink($product->id, $product->link_rewrite, Category::getLinkRewrite($product->id_category_default, $this->default_form_language), null, null, $interested[$i]['cp_id_shop']); $interested[$i]['id'] = (int) $product->id; $interested[$i]['name'] = Tools::htmlentitiesUTF8($product->name); } $emails = $customer->getLastEmails(); $connections = $customer->getLastConnections(); if (!is_array($connections)) { $connections = array(); } $total_connections = count($connections); for ($i = 0; $i < $total_connections; $i++) { $connections[$i]['http_referer'] = $connections[$i]['http_referer'] ? preg_replace('/^www./', '', parse_url($connections[$i]['http_referer'], PHP_URL_HOST)) : $this->l('Direct link'); } $referrers = Referrer::getReferrers($customer->id); $total_referrers = count($referrers); for ($i = 0; $i < $total_referrers; $i++) { $referrers[$i]['date_add'] = Tools::displayDate($referrers[$i]['date_add'], null, true); } $customerLanguage = new Language($customer->id_lang); $shop = new Shop($customer->id_shop); $this->tpl_view_vars = array('customer' => $customer, 'gender' => $gender, 'gender_image' => $gender_image, 'registration_date' => Tools::displayDate($customer->date_add, null, true), 'customer_stats' => $customer_stats, 'last_visit' => Tools::displayDate($customer_stats['last_visit'], null, true), 'count_better_customers' => $count_better_customers, 'shop_is_feature_active' => Shop::isFeatureActive(), 'name_shop' => $shop->name, 'customer_birthday' => Tools::displayDate($customer->birthday), 'last_update' => Tools::displayDate($customer->date_upd, null, true), 'customer_exists' => Customer::customerExists($customer->email), 'id_lang' => $customer->id_lang, 'customerLanguage' => $customerLanguage, 'customer_note' => Tools::htmlentitiesUTF8($customer->note), 'messages' => $messages, 'groups' => $groups, 'orders' => $orders, 'orders_ok' => $orders_ok, 'orders_ko' => $orders_ko, 'total_ok' => Tools::displayPrice($total_ok, $this->context->currency->id), 'products' => $products, 'addresses' => $customer->getAddresses($this->default_form_language), 'discounts' => CartRule::getCustomerCartRules($this->default_form_language, $customer->id, false, false), 'carts' => $carts, 'interested' => $interested, 'emails' => $emails, 'connections' => $connections, 'referrers' => $referrers, 'show_toolbar' => true); return parent::renderView(); }
public static function refreshCurrencies() { // Parse if (!($feed = Tools::simplexml_load_file(_PS_CURRENCY_FEED_URL_))) { return Tools::displayError('Cannot parse feed.'); } // Default feed currency (EUR) $isoCodeSource = strval($feed->source['iso_code']); if (!($default_currency = Currency::getDefaultCurrency())) { return Tools::displayError('No default currency'); } $currencies = Currency::getCurrencies(true, false, true); foreach ($currencies as $currency) { /** @var Currency $currency */ if ($currency->id != $default_currency->id) { $currency->refreshCurrency($feed->list, $isoCodeSource, $default_currency); } } }
/** * @since 1.5.0 */ public function supplyOrdersImport() { // opens CSV & sets locale $this->receiveTab(); $handle = $this->openCsvFile(); AdminImportController::setLocale(); // main loop, for each supply orders to import for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); ++$current_line) { // if convert requested if (Tools::getValue('convert')) { $line = $this->utf8EncodeArray($line); } $info = AdminImportController::getMaskedRow($line); // sets default values if needed AdminImportController::setDefaultValues($info); // if an id is set, instanciates a supply order with this id if possible if (array_key_exists('id', $info) && (int) $info['id'] && SupplyOrder::exists((int) $info['id'])) { $supply_order = new SupplyOrder((int) $info['id']); } elseif (array_key_exists('reference', $info) && $info['reference'] && SupplyOrder::exists(pSQL($info['reference']))) { $supply_order = SupplyOrder::getSupplyOrderByReference(pSQL($info['reference'])); } else { // new supply order $supply_order = new SupplyOrder(); } // gets parameters $id_supplier = (int) $info['id_supplier']; $id_lang = (int) $info['id_lang']; $id_warehouse = (int) $info['id_warehouse']; $id_currency = (int) $info['id_currency']; $reference = pSQL($info['reference']); $date_delivery_expected = pSQL($info['date_delivery_expected']); $discount_rate = (double) $info['discount_rate']; $is_template = (bool) $info['is_template']; $error = ''; // checks parameters if (!Supplier::supplierExists($id_supplier)) { $error = sprintf($this->l('Supplier ID (%d) is not valid (at line %d).'), $id_supplier, $current_line + 1); } if (!Language::getLanguage($id_lang)) { $error = sprintf($this->l('Lang ID (%d) is not valid (at line %d).'), $id_lang, $current_line + 1); } if (!Warehouse::exists($id_warehouse)) { $error = sprintf($this->l('Warehouse ID (%d) is not valid (at line %d).'), $id_warehouse, $current_line + 1); } if (!Currency::getCurrency($id_currency)) { $error = sprintf($this->l('Currency ID (%d) is not valid (at line %d).'), $id_currency, $current_line + 1); } if (empty($supply_order->reference) && SupplyOrder::exists($reference)) { $error = sprintf($this->l('Reference (%s) already exists (at line %d).'), $reference, $current_line + 1); } if (!empty($supply_order->reference) && ($supply_order->reference != $reference && SupplyOrder::exists($reference))) { $error = sprintf($this->l('Reference (%s) already exists (at line %d).'), $reference, $current_line + 1); } if (!Validate::isDateFormat($date_delivery_expected)) { $error = sprintf($this->l('Date (%s) is not valid (at line %d). Format: %s.'), $date_delivery_expected, $current_line + 1, $this->l('YYYY-MM-DD')); } elseif (new DateTime($date_delivery_expected) <= new DateTime('yesterday')) { $error = sprintf($this->l('Date (%s) cannot be in the past (at line %d). Format: %s.'), $date_delivery_expected, $current_line + 1, $this->l('YYYY-MM-DD')); } if ($discount_rate < 0 || $discount_rate > 100) { $error = sprintf($this->l('Discount rate (%d) is not valid (at line %d). %s.'), $discount_rate, $current_line + 1, $this->l('Format: Between 0 and 100')); } if ($supply_order->id > 0 && !$supply_order->isEditable()) { $error = sprintf($this->l('Supply Order (%d) is not editable (at line %d).'), $supply_order->id, $current_line + 1); } // if no errors, sets supply order if (empty($error)) { // adds parameters $info['id_ref_currency'] = (int) Currency::getDefaultCurrency()->id; $info['supplier_name'] = pSQL(Supplier::getNameById($id_supplier)); if ($supply_order->id > 0) { $info['id_supply_order_state'] = (int) $supply_order->id_supply_order_state; $info['id'] = (int) $supply_order->id; } else { $info['id_supply_order_state'] = 1; } // sets parameters AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $supply_order); // updatesd($supply_order); $res = true; if ((int) $supply_order->id && ($supply_order->exists((int) $supply_order->id) || $supply_order->exists($supply_order->reference))) { $res &= $supply_order->update(); } else { $supply_order->force_id = (bool) Tools::getValue('forceIDs'); $res &= $supply_order->add(); } // errors if (!$res) { $this->errors[] = sprintf($this->l('Supply Order could not be saved (at line %d).'), $current_line + 1); } } else { $this->errors[] = $error; } } // closes $this->closeCsvFile($handle); }
public function initOrderingContent() { // list order id by created providers $supply_order_created = array(); $this->show_toolbar = true; $this->display = 'ordering'; if ($this->is_1_6) { $this->initPageHeaderToolbar(); } $this->initToolbar(); $datas = $this->getDataGeneration(); if (!empty($datas['data_return'])) { //get default currencie $id_default_currency = Configuration::get('PS_CURRENCY_DEFAULT'); // get default id lang $id_default_lang = Configuration::get('PS_LANG_DEFAULT'); foreach ($datas['data_return'] as $id_supplier => $products_info) { // Get provider datas $supplier = new Supplier((int) $id_supplier); // get warehouse datas, delivery date and tax for the provider order $id_warehouse_data = Tools::getValue('id_warehouse'); $date_delivery_expected_data = Tools::getValue('date_delivery_expected'); $tax_rate_data = Tools::getValue('tax_rate'); $tax_rate_data = $tax_rate_data[$id_supplier]; // id warehouse $id_warehouse = $id_warehouse_data[$id_supplier]; // delivery date $date_delivery_expected = $date_delivery_expected_data[$id_supplier]; // create the provider order $supply_order = new SupplyOrder(); $supply_order->reference = ErpSupplyOrderClasses::getNextSupplyOrderReference(); $supply_order->id_supplier = $id_supplier; $supply_order->supplier_name = $supplier->name; $supply_order->id_warehouse = $id_warehouse; $supply_order->id_currency = $id_default_currency; $supply_order->id_lang = $id_default_lang; $supply_order->id_supply_order_state = 1; $supply_order->id_ref_currency = (int) Currency::getDefaultCurrency()->id; $supply_order->date_delivery_expected = $date_delivery_expected; // if recording is ok, create the order lines if ($supply_order->add()) { // get the provider id order $id_supply_order = $this->getLastIdSupplyOrder(); $supply_order_created[] = $id_supply_order; // Ajout de son historique // add historical $history = new SupplyOrderHistory(); $history->id_supply_order = $id_supply_order; $history->id_state = 3; $history->id_employee = (int) $this->context->employee->id; $history->employee_firstname = pSQL($this->context->employee->firstname); $history->employee_lastname = pSQL($this->context->employee->lastname); $history->save(); // Create entries for provider order if (!empty($products_info)) { $i = 0; foreach ($products_info as $item) { if (!isset($item['product_id'])) { continue; } $supply_order_detail = new SupplyOrderDetail(); $supply_order_detail->id_supply_order = $id_supply_order; $supply_order_detail->id_currency = (int) Currency::getDefaultCurrency()->id; $supply_order_detail->id_product = $item['product_id']; $supply_order_detail->id_product_attribute = $item['product_attribute_id']; $supply_order_detail->reference = $item['product_reference']; $supply_order_detail->supplier_reference = $item['product_supplier_reference']; $supply_order_detail->name = $item['product_name']; $supply_order_detail->ean13 = $item['product_ean13']; $supply_order_detail->upc = $item['product_upc']; $supply_order_detail->quantity_expected = $item['total_product_quantity']; $supply_order_detail->exchange_rate = 1; $supply_order_detail->unit_price_te = $item['unit_price_tax_excl']; $supply_order_detail->tax_rate = $tax_rate_data[$i]; $supply_order_detail->save(); // Get the supply order created $id_supply_order_detail = $this->getLastIdSupplyOrderDetail(); // Record the relation between provider order and customer order if (!empty($item)) { foreach ($item['concerned_id_order_detail'] as $customer_link) { $supply_order_customer = new ErpSupplyOrderCustomer(); $supply_order_customer->id_customer = $customer_link['id_customer']; $supply_order_customer->id_order_detail = $customer_link['id_order_detail']; $supply_order_customer->id_supply_order_detail = $id_supply_order_detail; $supply_order_customer->id_supply_order = $id_supply_order; $supply_order_customer->save(); } } $i++; } // Rerecording provider order data to update totals $supply_order->save(); } } } // update provider order status if (!empty($datas['order_to_change_state'])) { foreach ($datas['order_to_change_state'] as $id_order) { $order_change_state = new Order((int) $id_order); $order_change_state->setCurrentState($this->generate_order_state_to, (int) $this->context->employee->id); } } $this->confirmations[] = $this->l('Order saved successfully !'); // remove treated order in cookies $this->context->cookie->__unset('unselected_orders'); } else { $this->errors[] = Tools::displayError($this->l('No data available for ordering ! You must select at least one order.')); } $this->context->smarty->assign(array('content' => '', 'show_toolbar ' => 'true', 'show_toolbar' => true, 'toolbar_btn' => $this->toolbar_btn, 'title' => $this->l('Supply Order : order screen'), 'toolbar_scroll' => $this->toolbar_scroll, 'token' => $this->token, 'url_post' => self::$currentIndex . '&token=' . $this->token, 'supply_order_created' => !empty($supply_order_created) ? implode(',', $supply_order_created) : '')); $this->createTemplate('ordering.tpl'); $this->template = 'ordering.tpl'; }
/** * AdminController::postProcess() override * @see AdminController::postProcess() */ public function postProcess() { $this->is_editing_order = false; // Checks access if (Tools::isSubmit('submitAddsupply_order') && !($this->tabAccess['add'] === '1')) { $this->errors[] = Tools::displayError($this->l('You do not have permission to add a supply order.')); } if (Tools::isSubmit('submitBulkUpdatesupply_order_detail') && !($this->tabAccess['edit'] === '1')) { $this->errors[] = Tools::displayError($this->l('You do not have permission to edit an order.')); } // Trick to use both Supply Order as template and actual orders if (Tools::isSubmit('is_template')) { $_GET['mod'] = 'template'; } // checks if supply order reference is unique if (Tools::isSubmit('reference')) { // gets the reference $ref = pSQL(Tools::getValue('reference')); if (Tools::getValue('id_supply_order') != 0 && SupplyOrder::getReferenceById((int) Tools::getValue('id_supply_order')) != $ref) { if ((int) SupplyOrder::exists($ref) != 0) { $this->errors[] = Tools::displayError($this->l('The reference has to be unique.')); } } else { if (Tools::getValue('id_supply_order') == 0 && (int) SupplyOrder::exists($ref) != 0) { $this->errors[] = Tools::displayError($this->l('The reference has to be unique.')); } } } if ($this->errors) { return; } // Global checks when add / update a supply order if (Tools::isSubmit('submitAddsupply_order') || Tools::isSubmit('submitAddsupply_orderAndStay')) { $this->action = 'save'; $this->is_editing_order = true; // get supplier ID $id_supplier = (int) Tools::getValue('id_supplier', 0); if ($id_supplier <= 0 || !Supplier::supplierExists($id_supplier)) { $this->errors[] = Tools::displayError($this->l('The selected supplier is not valid.')); } // get warehouse id $id_warehouse = (int) Tools::getValue('id_warehouse', 0); if ($id_warehouse <= 0 || !Warehouse::exists($id_warehouse)) { $this->errors[] = Tools::displayError($this->l('The selected warehouse is not valid.')); } // get currency id $id_currency = (int) Tools::getValue('id_currency', 0); if ($id_currency <= 0 || (!($result = Currency::getCurrency($id_currency)) || empty($result))) { $this->errors[] = Tools::displayError($this->l('The selected currency is not valid.')); } // get delivery date $delivery_expected = new DateTime(pSQL(Tools::getValue('date_delivery_expected'))); // converts date to timestamp if ($delivery_expected <= new DateTime('yesterday')) { $this->errors[] = Tools::displayError($this->l('The date you specified cannot be in the past.')); } // gets threshold $quantity_threshold = Tools::getValue('load_products'); if (is_numeric($quantity_threshold)) { $quantity_threshold = (int) $quantity_threshold; } else { $quantity_threshold = null; } if (!count($this->errors)) { // forces date for templates if (Tools::isSubmit('is_template') && !Tools::getValue('date_delivery_expected')) { $_POST['date_delivery_expected'] = date('Y-m-d h:i:s'); } // specify initial state $_POST['id_supply_order_state'] = 1; //defaut creation state // specify global reference currency $_POST['id_ref_currency'] = Currency::getDefaultCurrency()->id; // specify supplier name $_POST['supplier_name'] = Supplier::getNameById($id_supplier); //specific discount check $_POST['discount_rate'] = (double) str_replace(array(' ', ','), array('', '.'), Tools::getValue('discount_rate', 0)); } // manage each associated product $this->manageOrderProducts(); // if the threshold is defined and we are saving the order if (Tools::isSubmit('submitAddsupply_order') && Validate::isInt($quantity_threshold)) { $this->loadProducts((int) $quantity_threshold); } //--ERP informations // updates/creates erp_supplier_order if it does not exist if (Tools::isSubmit('id_erpip_supply_order') && (int) Tools::getValue('id_erpip_supply_order') > 0) { $erp_supplier_order = new ErpSupplyOrder((int) Tools::getValue('id_erpip_supply_order')); } else { $erp_supplier_order = new ErpSupplyOrder(); } // creates erp_supplier_order $erp_supplier_order->escompte = Tools::getValue('escompte', null); $erp_supplier_order->global_discount_amount = Tools::getValue('global_discount_type', null); $erp_supplier_order->global_discount_type = Tools::getValue('global_discount_type', null); $erp_supplier_order->shipping_amount = Tools::getValue('shipping_amount', null); $erp_supplier_order->description = Tools::getValue('description', null); $validation = $erp_supplier_order->validateController(); // checks erp_supplier_order validity if (count($validation) > 0) { foreach ($validation as $item) { $this->errors[] = $item; } $this->errors[] = Tools::displayError('The ErpIllicopresta Supplier Order is not correct. Please make sure all of the required fields are completed.'); } else { if (Tools::isSubmit('id_erpip_supply_order') && Tools::getValue('id_erpip_supply_order') > 0) { $erp_supplier_order->update(); } else { $erp_supplier_order->save(); $_POST['id_erpip_supply_order'] = $erp_supplier_order->id; } } } // Manage state change if (Tools::isSubmit('submitChangestate') && Tools::isSubmit('id_supply_order') && Tools::isSubmit('id_supply_order_state')) { if ($this->tabAccess['edit'] != '1') { $this->errors[] = Tools::displayError($this->l('You do not have permission to change the order status.')); } // get state ID $id_state = (int) Tools::getValue('id_supply_order_state', 0); if ($id_state <= 0) { $this->errors[] = Tools::displayError($this->l('The selected supply order status is not valid.')); } // get supply order ID $id_supply_order = (int) Tools::getValue('id_supply_order', 0); if ($id_supply_order <= 0) { $this->errors[] = Tools::displayError($this->l('The supply order ID is not valid.')); } if (!count($this->errors)) { // try to load supply order $supply_order = new SupplyOrder($id_supply_order); if (Validate::isLoadedObject($supply_order)) { // get valid available possible states for this order $states = SupplyOrderState::getSupplyOrderStates($supply_order->id_supply_order_state); foreach ($states as $state) { // if state is valid, change it in the order if ($id_state == $state['id_supply_order_state']) { $new_state = new SupplyOrderState($id_state); $old_state = new SupplyOrderState($supply_order->id_supply_order_state); // special case of validate state - check if there are products in the order and the required state is not an enclosed state if ($supply_order->isEditable() && !$supply_order->hasEntries() && !$new_state->enclosed) { $this->errors[] = Tools::displayError($this->l('It is not possible to change the status of this order because you did not order any product.')); } if (!count($this->errors)) { // send mail to supplier with supply order if ($this->sendMailOnValidateSupplyOrder($supply_order)) { $supply_order->id_supply_order_state = $state['id_supply_order_state']; if ($supply_order->save()) { //-ERP information // save erp_supply_order additionale information // loads current erp_supplier` informationfor this supplier - if possible $erp_supply_order = null; if (isset($supply_order->id)) { $id_erpip_supply_order = ErpSupplyOrder::getErpSupplierOrderIdBySupplierOrderId((int) $supply_order->id); if ($id_erpip_supply_order > 0) { $erp_supply_order = new ErpSupplyOrder((int) $id_erpip_supply_order); } else { $erp_supply_order = new ErpSupplyOrder(); } } if ($erp_supply_order != null) { if (Tools::isSubmit('date_to_invoice')) { $erp_supply_order->date_to_invoice = Tools::getValue('date_to_invoice', '000-00-00'); } if (Tools::isSubmit('invoice_number')) { $erp_supply_order->invoice_number = Tools::getValue('invoice_number', ''); } $erp_supply_order->id_supply_order = $supply_order->id; $erp_supply_order->save(); } // if pending_receipt, // or if the order is being canceled, // synchronizes StockAvailable if ($new_state->pending_receipt && !$new_state->receipt_state || $old_state->receipt_state && $new_state->enclosed && !$new_state->receipt_state) { $supply_order_details = $supply_order->getEntries(); $products_done = array(); foreach ($supply_order_details as $supply_order_detail) { if (!in_array($supply_order_detail['id_product'], $products_done)) { StockAvailable::synchronize($supply_order_detail['id_product']); $products_done[] = $supply_order_detail['id_product']; } } } $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token; $redirect = self::$currentIndex . '&token=' . $token; $this->redirect_after = $redirect . '&conf=5'; } } } } } } else { $this->errors[] = Tools::displayError($this->l('The selected supplier is not valid.')); } } } // get id_supplier $id_supply_order = (int) Tools::getValue('id_supply_order', null); $supply_order = new SupplyOrder($id_supply_order); $erp_supplier_order = new ErpSupplyOrder($id_supply_order); $this->context->smarty->assign(array('supplier_id' => $supply_order->id_supplier, 'currency' => new CurrencyCore((int) $supply_order->id_currency), 'random' => rand(99999, 150000), 'template_path' => $this->template_path, 'controller_status' => $this->controller_status, 'supply_order_description' => $erp_supplier_order->description)); $this->getFilters(); //-ErpIllicopresta // Fixed bug : different variable available according Prestashop version // 1.5.4.1 => submitFiltersupply_order_detail // 1.5.5.0 => submitFiltersupply_order // Add an OR to take into account this two version // updates receipt if (Tools::isSubmit('submitBulkUpdatesupply_order_detail') && Tools::isSubmit('id_supply_order') && (Tools::isSubmit('submitFiltersupply_order') || Tools::isSubmit('submitFiltersupply_order_detail'))) { $this->postProcessUpdateReceipt(); } // use template to create a supply order if (Tools::isSubmit('create_supply_order') && Tools::isSubmit('id_supply_order')) { $this->postProcessCopyFromTemplate(); } // Export PDF of supply order if (Tools::isSubmit('submitAction') && Tools::getValue('submitAction') == 'generateSupplyOrderFormPDF') { $this->processGenerateSupplyOrderFormPDF(); } // Export PDF of receiving slip if (Tools::isSubmit('submitAction') && Tools::getValue('submitAction') == 'generateSupplyReceivingSlipFormPDF') { $this->processGenerateSupplyReceivingSlipFormPDF(); } if (!count($this->errors) && $this->is_editing_order || !$this->is_editing_order) { parent::postProcess(); } }
/** * @param float $amount * @return float */ protected function _convertCurrencyToEuro($amount) { $cart = $this->context->cart; $currency_euro = Currency::getIdByIsoCode('EUR'); if (!$currency_euro) { // No Euro currency available! if ($this->module->getConfigValue('MOLLIE_DEBUG_LOG') == Mollie::DEBUG_LOG_ERRORS) { Logger::addLog(__METHOD__ . ' said: In order to use this module, you need to enable Euros as currency.', Mollie::CRASH); } die($this->module->lang['This payment method is only available for Euros.']); } if ($cart->id_currency !== $currency_euro) { // Convert non-euro currency to default $amount = Tools::convertPrice($amount, $cart->id_currency, FALSE); if (Currency::getDefaultCurrency() !== $currency_euro) { // If default is not euro, convert to euro $amount = Tools::convertPrice($amount, $currency_euro, TRUE); } } return round($amount, 2); }
public function getSign() { return Currency::getDefaultCurrency()->getSign("right"); }
function cronOrdersSync() { $orders = $this->client->getOrders(array(7)); foreach ($orders as $order) { $channelOrderId = $order->getId(); $billingAddress = $order->getBillingAddress(); $shippingAddress = $order->getShippingAddress(); if (empty($billingAddress)) { continue; } $id_customer = $this->createPrestashopCustomer($billingAddress, $order->getEmail()); $lines = $order->getLines(); $AddressObject = new Address(); $AddressObject->id_customer = $id_customer; $AddressObject->firstname = $billingAddress->getfirstName(); $AddressObject->lastname = $billingAddress->getlastName(); $AddressObject->address1 = " " . $billingAddress->getHouseNr(); $AddressObject->address1 .= " " . $billingAddress->getHouseNrAddition(); $AddressObject->address1 .= " " . $billingAddress->getStreetName(); $AddressObject->address1 .= " " . $billingAddress->getZipCode(); $AddressObject->address1 .= " " . $billingAddress->getCity(); $AddressObject->city = $billingAddress->getCity(); $AddressObject->id_customer = $id_customer; $AddressObject->id_country = Country::getByIso($billingAddress->getCountryIso()); $AddressObject->alias = $billingAddress->getcompanyName() != "" ? "Company" : "Home"; $AddressObject->add(); $CarrierObject = new Carrier(); $CarrierObject->delay[1] = "2-4"; $CarrierObject->active = 1; $CarrierObject->name = "ChannelEngine Order"; $CarrierObject->add(); $id_carrier = $CarrierObject->id; $currency_object = new Currency(); $default_currency_object = $currency_object->getDefaultCurrency(); $id_currency = $default_currency_object->id; $id_address = $AddressObject->id; // Create Cart Object $cart = new Cart(); $cart->id_customer = (int) $id_customer; $cart->id_address_delivery = $id_address; $cart->id_address_invoice = $id_address; $cart->id_lang = 1; $cart->id_currency = (int) $id_address; $cart->id_carrier = $id_carrier; $cart->recyclable = 0; $cart->id_shop_group = 1; $cart->gift = 0; $cart->add(); if (!empty($lines)) { foreach ($lines as $item) { $quantity = $item->getQuantity(); if (strpos($item->getmerchantProductNo(), '-') !== false) { $getMerchantProductNo = explode("-", $item->getMerchantProductNo()); $cart->updateQty($quantity, $getMerchantProductNo[0], $getMerchantProductNo[1]); } else { $cart->updateQty($quantity, $item->getmerchantProductNo()); } } } $cart->update(); $order_object = new Order(); $order_object->id_address_delivery = $id_address; $order_object->id_address_invoice = $id_address; $order_object->id_cart = $cart->id; $order_object->id_currency = $id_currency; $order_object->id_customer = $id_customer; $order_object->id_carrier = $id_carrier; $order_object->payment = "ChannelEngine Order"; $order_object->module = "1"; $order_object->valid = 1; $order_object->total_paid_tax_excl = $order->getTotalInclVat(); $order_object->total_discounts_tax_incl = 0; $order_object->total_paid = $order->getTotalInclVat(); $order_object->total_paid_real = $order->getTotalInclVat(); $order_object->total_products = $order->getSubTotalInclVat() - $order->getSubTotalVat(); $order_object->total_products_wt = $order->getSubTotalInclVat(); $order_object->total_paid_tax_incl = $order->getSubTotalInclVat(); $order_object->conversion_rate = 1; $order_object->id_shop = 1; $order_object->id_lang = 1; $order_object->id_shop_group = 1; $order_object->secure_key = md5(uniqid(rand(), true)); $order_id = $order_object->add(); // Insert new Order detail list using cart for the current order $order_detail = new OrderDetail(); $orderClass = new Order(); $order_detail->createList($order_object, $cart, 1, $cart->getProducts(), 1); $order_detail_list[] = $order_detail; // Adding an entry in order_carrier table if (!is_null($CarrierObject)) { $order_carrier = new OrderCarrier(); $order_carrier->id_order = (int) $order_object->id; $order_carrier->id_carrier = (int) $id_carrier; $order_carrier->weight = (double) $order_object->getTotalWeight(); $order_carrier->shipping_cost_tax_excl = (double) $order_object->total_shipping_tax_excl; $order_carrier->shipping_cost_tax_incl = (double) $order_object->total_shipping_tax_incl; $order_carrier->add(); } foreach ($lines as $item) { $getMerchantProductNo = explode("-", $item->getMerchantProductNo()); $query = "UPDATE `" . _DB_PREFIX_ . "order_detail` SET id_channelengine_product='" . $item->getId() . "'" . "WHERE product_id ='" . $getMerchantProductNo[0] . "' AND product_attribute_id = '" . $getMerchantProductNo[1] . "' AND id_order = ' " . $order_object->id . "' "; Db::getInstance()->Execute($query); } Db::getInstance()->update('orders', array('id_channelengine_order' => $channelOrderId), 'id_order = ' . $order_object->id); } }
private static function createCountries() { if (!Country::getByIso('ES') || !Country::getByIso('PT')) { if (!self::disableCountries()) { return false; } $modulos = SeurLib::getModulosPago(); $values = array(); $currency = Currency::getDefaultCurrency(); /* ESPAÑA */ if (!Country::getByIso('ES')) { self::$spain = new Country(); self::$spain->name = array(1 => 'Spain', 2 => 'Espagne', 3 => 'España'); self::$spain->id_zone = self::$peninsula->id; self::$spain->id_currency = $currency->id; self::$spain->iso_code = 'ES'; self::$spain->contains_states = true; self::$spain->need_identification_number = true; if (!self::$spain->save()) { return false; } foreach ($modulos as $modulo) { $values[] = '(' . (int) $modulo->id . ', ' . (int) self::$spain->id . ')'; } if (!empty($values)) { Db::getInstance()->Execute(' INSERT INTO ' . _DB_PREFIX_ . 'module_country (`id_module`, `id_country`) VALUES ' . implode(',', $values)); } } /* PORTUGAL */ if (!Country::getByIso('PT')) { self::$portugal_country = new Country(); self::$portugal_country->name = array(1 => 'Portugal', 2 => 'Portugal', 3 => 'Portugal'); self::$portugal_country->id_zone = self::$portugal->id; self::$portugal_country->id_currency = $currency->id; self::$portugal_country->iso_code = 'PT'; self::$portugal_country->contains_states = false; self::$portugal_country->need_identification_number = false; if (!self::$portugal_country->save()) { return false; } foreach ($modulos as $modulo) { $values[] = '(' . (int) $modulo->id . ', ' . (int) self::$portugal_country->id . ')'; } if (!empty($values)) { Db::getInstance()->Execute(' INSERT INTO ' . _DB_PREFIX_ . 'module_country (`id_module`, `id_country`) VALUES ' . implode(',', $values)); } } } else { self::$spain = new Country((int) Country::getByIso('ES')); self::$spain->active = true; self::$spain->contains_states = true; if (!self::$spain->save()) { return false; } self::$portugal_country = new Country((int) Country::getByIso('PT')); self::$portugal_country->active = true; self::$portugal_country->id_zone = self::$portugal->id; if (!self::$portugal_country->save()) { return false; } } return true; }
/** * Modifies the current context and replaces the info related to shop, link, language and currency. * * We need this when generating the product data for the different shops and languages. * The currency will be the first found for the shop, but it defaults to the PS default currency * if no shop specific one is found. * * @param int $id_lang the language ID to add to the new context. * @param int $id_shop the shop ID to add to the new context. * @return Context the new context. */ protected function makeContext($id_lang, $id_shop) { if (_PS_VERSION_ >= '1.5') { // Reset the shop context to be the current processed shop. This will fix the "friendly url" format of urls // generated through the Link class. Shop::setContext(Shop::CONTEXT_SHOP, $id_shop); // Reset the dispatcher singleton instance so that the url rewrite setting is check on a shop basis when // generating product urls. This will fix the issue of incorrectly formatted urls when one shop has the // rewrite setting enabled and another does not. Dispatcher::$instance = null; if (method_exists('ShopUrl', 'resetMainDomainCache')) { // Reset the shop url domain cache so that it is re-initialized on a shop basis when generating product // image urls. This will fix the issue of the image urls having an incorrect shop base url when the // shops are configured to use different domains. ShopUrl::resetMainDomainCache(); } foreach (Currency::getCurrenciesByIdShop($id_shop) as $row) { if ($row['deleted'] === '0' && $row['active'] === '1') { $currency = new Currency($row['id_currency']); break; } } } $context = Context::getContext(); $context->language = new Language($id_lang); $context->shop = new Shop($id_shop); $context->link = new Link('http://', 'http://'); $context->currency = isset($currency) ? $currency : Currency::getDefaultCurrency(); return $context; }
private function getProductSearchContext() { Context::getContext()->currency = Currency::getDefaultCurrency(); return new ProductSearchContext(Context::getContext()); }
SET ' . _DB_PREFIX_ . _DPDGROUP_ADDRESS_DB_ . '.auto_postcode = NEW.postcode, ' . _DB_PREFIX_ . _DPDGROUP_ADDRESS_DB_ . '.relevance = 1 WHERE ' . _DB_PREFIX_ . _DPDGROUP_ADDRESS_DB_ . '.id_address = NEW.id_address AND ' . _DB_PREFIX_ . _DPDGROUP_ADDRESS_DB_ . '.dpd_postcode_id > 0'; foreach ($sql as $query) { if (!$database_table_install_error) { if (Db::getInstance()->execute($query) == false) { $database_table_install_error = true; } } } if (!$database_table_install_error) { $shops = version_compare(_PS_VERSION_, '1.5', '<') ? array('1' => 1) : Shop::getShops(); $current_date = date('Y-m-d H:i:s'); $currency = Currency::getDefaultCurrency(); foreach (array_keys($shops) as $id_shop) { if (!$price_rules_data_intall_error) { $sql = ' INSERT INTO `' . _DB_PREFIX_ . _DPDGROUP_CSV_DB_ . '` (`id_shop`, `date_add`, `date_upd`, `country`, `region`, `zip`, `weight_from`, `weight_to`, `shipping_price`, `currency`, `method_id`) VALUES ("' . (int) $id_shop . '", "' . pSQL($current_date) . '", "' . pSQL($current_date) . '", "*", "*", "*", "0", "0.5", "0", "' . pSQL($currency->iso_code) . '", "' . (int) _DPDGROUP_CLASSIC_ID_ . '"), ("' . (int) $id_shop . '", "' . pSQL($current_date) . '", "' . pSQL($current_date) . '", "*", "*", "*", "0", "0.5", "0", "' . pSQL($currency->iso_code) . '", "' . (int) _DPDGROUP_12_ID_ . '"), ("' . (int) $id_shop . '", "' . pSQL($current_date) . '", "' . pSQL($current_date) . '", "*", "*", "*", "0", "0.5", "0", "' . pSQL($currency->iso_code) . '", "' . (int) _DPDGROUP_10_ID_ . '"), ("' . (int) $id_shop . '", "' . pSQL($current_date) . '", "' . pSQL($current_date) . '", "*", "*", "*", "0", "0.5", "0", "' . pSQL($currency->iso_code) . '", "' . (int) _DPDGROUP_SAME_DAY_ID_ . '"),