本文整理汇总了PHP中Currency::getDefaultCurrency方法的典型用法代码示例。如果您正苦于以下问题:PHP Currency::getDefaultCurrency方法的具体用法?PHP Currency::getDefaultCurrency怎么用?PHP Currency::getDefaultCurrency使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Currency
的用法示例。
在下文中一共展示了Currency::getDefaultCurrency方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: supplyOrdersImportOne
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;
}
}
示例2: postProcess
/**
* 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.');
}
//.........这里部分代码省略.........
示例3: refreshCurrencies
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);
}
}
}
示例4: __getPriceDkk
/**
* 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;
}
}
}
示例5: renderView
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++) {
//.........这里部分代码省略.........
示例6: refreshCurrencies
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);
}
}
}
示例7: supplyOrdersImport
/**
* @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);
}
示例8: initOrderingContent
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);
//.........这里部分代码省略.........
示例9: postProcess
/**
* 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);
//.........这里部分代码省略.........
示例10: _convertCurrencyToEuro
/**
* @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);
}
示例11: getSign
public function getSign()
{
return Currency::getDefaultCurrency()->getSign("right");
}
示例12: cronOrdersSync
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());
//.........这里部分代码省略.........
示例13: createCountries
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;
}
示例14: makeContext
/**
* 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;
}
示例15: getProductSearchContext
private function getProductSearchContext()
{
Context::getContext()->currency = Currency::getDefaultCurrency();
return new ProductSearchContext(Context::getContext());
}