public function hydrate(array $data, $id_lang = null) { parent::hydrate($data, $id_lang); if (!isset($data['physical_quantity_remainder'])) { PP::hydrateQty($this, 'physical_quantity', $data['physical_quantity'] + $this->physical_quantity_remainder); } }
public function getTotalWeight() { $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT SUM(product_weight * ' . PP::sqlQty('product_quantity') . ') FROM ' . _DB_PREFIX_ . 'order_detail WHERE id_order = ' . (int) $this->id); return (double) $result; }
public static function validateSpecificPriceProductQuantity($value) { if (PP::productQtyPolicyLegacy((int) Tools::getValue('id_product'))) { return self::isUnsignedInt($value); } else { if (is_string($value)) { $value = str_replace(',', '.', $value); } return self::isUnsignedFloat($value); } }
protected function addAttribute($attributes, $price = 0, $weight = 0) { foreach ($attributes as $attribute) { $price += (double) preg_replace('/[^0-9.-]/', '', str_replace(',', '.', Tools::getValue('price_impact_' . (int) $attribute))); $weight += (double) preg_replace('/[^0-9.]/', '', str_replace(',', '.', Tools::getValue('weight_impact_' . (int) $attribute))); } if ($this->product->id) { $result = array('id_product' => (int) $this->product->id, 'price' => (double) $price, 'weight' => (double) $weight, 'ecotax' => 0, 'reference' => pSQL(Tools::getValue('reference')), 'default_on' => 0, 'available_date' => '0000-00-00'); PP::setQty($result, str_replace(',', '.', Tools::getValue('quantity'))); return $result; } return array(); }
protected function getQuantitySold($id_product, $id_product_attribute, $coverage) { $query = new DbQuery(); $query->select('SUM(' . PP::sqlQty('product_quantity', 'od') . ')'); $query->from('order_detail', 'od'); $query->leftJoin('orders', 'o', 'od.id_order = o.id_order'); $query->leftJoin('order_history', 'oh', 'o.date_upd = oh.date_add'); $query->leftJoin('order_state', 'os', 'os.id_order_state = oh.id_order_state'); $query->where('od.product_id = ' . (int) $id_product); $query->where('od.product_attribute_id = ' . (int) $id_product_attribute); $query->where('TO_DAYS(NOW()) - TO_DAYS(oh.date_add) <= ' . (int) $coverage); $query->where('o.valid = 1'); $query->where('os.logable = 1 AND os.delivery = 1 AND os.shipped = 1'); $quantity = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query); return $quantity; }
protected function setDetailProductPrice(Order $order, Cart $cart, $product) { $this->setContext((int) $product['id_shop']); $specific_price = $null = null; Product::getPriceStatic((int) $product['id_product'], true, (int) $product['id_product_attribute'], 6, null, false, true, array($product['cart_quantity'], $product['cart_quantity_fractional']), false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}, $specific_price, true, true, $this->context); $this->specificPrice = $specific_price; $this->original_product_price = Product::getPriceStatic($product['id_product'], false, (int) $product['id_product_attribute'], 6, null, false, false, 1, false, null, null, null, $null, true, true, $this->context); $this->product_price = $this->original_product_price; $this->unit_price_tax_incl = (double) $product['price_wt']; $this->unit_price_tax_excl = (double) $product['price']; $this->total_price_tax_incl = (double) $product['total_wt']; $this->total_price_tax_excl = (double) $product['total']; $this->purchase_supplier_price = (double) $product['wholesale_price']; if ($product['id_supplier'] > 0 && ($supplier_price = ProductSupplier::getProductPrice((int) $product['id_supplier'], $product['id_product'], $product['id_product_attribute'], true)) > 0) { $this->purchase_supplier_price = (double) $supplier_price; } $this->setSpecificPrice($order, $product); $this->group_reduction = (double) Group::getReduction((int) $order->id_customer); $shop_id = $this->context->shop->id; $quantity_discount = SpecificPrice::getQuantityDiscount((int) $product['id_product'], $shop_id, (int) $cart->id_currency, (int) $this->vat_address->id_country, (int) $this->customer->id_default_group, (int) PP::resolveQty($product['cart_quantity'], $product['cart_quantity_fractional']), false, null, null, $null, true, true, $this->context); $unit_price = Product::getPriceStatic((int) $product['id_product'], true, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : null, 2, null, false, true, 1, false, (int) $order->id_customer, null, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}, $null, true, true, $this->context); $this->product_quantity_discount = 0.0; if ($quantity_discount) { $this->product_quantity_discount = $unit_price; if (Product::getTaxCalculationMethod((int) $order->id_customer) == PS_TAX_EXC) { $this->product_quantity_discount = Tools::ps_round($unit_price, 2); } if (isset($this->tax_calculator)) { $this->product_quantity_discount -= $this->tax_calculator->addTaxes($quantity_discount['price']); } } $this->discount_quantity_applied = $this->specificPrice && $this->specificPrice['from_quantity'] > PP::getSpecificPriceFromQty((int) $product['id_product']) ? 1 : 0; $this->id_cart_product = (int) $product['id_cart_product']; $this->product_quantity_fractional = (double) $product['cart_quantity_fractional']; $ppropertiessmartprice_hook3 = null; }
public static function callbackName($echo, $tr) { static $show = null; if ($show === null) { $show = (bool) Configuration::get('PP_TEMPLATE_NAME_IN_CATALOG'); } if ($show) { $id_pp_template = PP::getProductTemplateId($tr); if ($id_pp_template > 0) { PP::getAdminProductsTemplates(PP::getProductTemplateId($tr)); $name = PP::getTemplateName($id_pp_template, true); if ($name != '') { static $template_title = null; if ($template_title === null) { $module = Module::getInstanceByName('pproperties'); $translations = $module->getTranslations('AdminProductsController'); $template_title = $translations['template_title']; } return $echo . '<br><span class="pp_list_template" title="' . $template_title . '"><i class="icon-template"></i>' . PP::safeOutputLenient($name) . '</span>'; } } } return $echo; }
public function postProcess() { $this->adminControllerPostProcess(); // Checks access if (Tools::isSubmit('addStock') && !($this->tabAccess['add'] === '1')) { $this->errors[] = Tools::displayError('You do not have the required permission to add stock.'); } if (Tools::isSubmit('removeStock') && !($this->tabAccess['delete'] === '1')) { $this->errors[] = Tools::displayError('You do not have the required permission to delete stock'); } if (Tools::isSubmit('transferStock') && !($this->tabAccess['edit'] === '1')) { $this->errors[] = Tools::displayError('You do not have the required permission to transfer stock.'); } if (count($this->errors)) { return; } // Global checks when add / remove / transfer product if ((Tools::isSubmit('addstock') || Tools::isSubmit('removestock') || Tools::isSubmit('transferstock')) && Tools::isSubmit('is_post')) { // get product ID $id_product = (int) Tools::getValue('id_product', 0); if ($id_product <= 0) { $this->errors[] = Tools::displayError('The selected product is not valid.'); } // get product_attribute ID $id_product_attribute = (int) Tools::getValue('id_product_attribute', 0); // check the product hash $check = Tools::getValue('check', ''); $check_valid = md5(_COOKIE_KEY_ . $id_product . $id_product_attribute); if ($check != $check_valid) { $this->errors[] = Tools::displayError('The selected product is not valid.'); } // get quantity and check that the post value is really an integer // If it's not, we have nothing to do $quantity = Tools::getValue('quantity', 0); $quantity = PP::normalizeProductQty($quantity, $id_product); if (!is_numeric($quantity) || $quantity <= 0) { $this->errors[] = Tools::displayError('The quantity value is not valid.'); } //$quantity = (int)$quantity; $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token; $redirect = self::$currentIndex . '&token=' . $token; } // Global checks when add / remove product if ((Tools::isSubmit('addstock') || Tools::isSubmit('removestock')) && Tools::isSubmit('is_post')) { // 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 stock movement reason id $id_stock_mvt_reason = (int) Tools::getValue('id_stock_mvt_reason', 0); if ($id_stock_mvt_reason <= 0 || !StockMvtReason::exists($id_stock_mvt_reason)) { $this->errors[] = Tools::displayError('The reason is not valid.'); } // get usable flag $usable = Tools::getValue('usable', null); if (is_null($usable)) { $this->errors[] = Tools::displayError('You have to specify whether the product quantity is usable for sale on shops or not.'); } $usable = (bool) $usable; } if (Tools::isSubmit('addstock') && Tools::isSubmit('is_post')) { // get product unit price $price = str_replace(',', '.', Tools::getValue('price', 0)); if (!is_numeric($price)) { $this->errors[] = Tools::displayError('The product price is not valid.'); } $price = round((double) $price, 6); // get product unit price 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.'); } // if all is ok, add stock if (count($this->errors) == 0) { $warehouse = new Warehouse($id_warehouse); // convert price to warehouse currency if needed if ($id_currency != $warehouse->id_currency) { // First convert price to the default currency $price_converted_to_default_currency = Tools::convertPrice($price, $id_currency, false); // Convert the new price from default currency to needed currency $price = Tools::convertPrice($price_converted_to_default_currency, $warehouse->id_currency, true); } // add stock $stock_manager = StockManagerFactory::getManager(); if ($stock_manager->addProduct($id_product, $id_product_attribute, $warehouse, $quantity, $id_stock_mvt_reason, $price, $usable)) { // Create warehouse_product_location entry if we add stock to a new warehouse $id_wpl = (int) WarehouseProductLocation::getIdByProductAndWarehouse($id_product, $id_product_attribute, $id_warehouse); if (!$id_wpl) { $wpl = new WarehouseProductLocation(); $wpl->id_product = (int) $id_product; $wpl->id_product_attribute = (int) $id_product_attribute; $wpl->id_warehouse = (int) $id_warehouse; $wpl->save(); } StockAvailable::synchronize($id_product); if (Tools::isSubmit('addstockAndStay')) { $redirect = self::$currentIndex . '&id_product=' . (int) $id_product; if ($id_product_attribute) { $redirect .= '&id_product_attribute=' . (int) $id_product_attribute; } $redirect .= '&addstock&token=' . $token; } Tools::redirectAdmin($redirect . '&conf=1'); } else { $this->errors[] = Tools::displayError('An error occurred. No stock was added.'); } } } if (Tools::isSubmit('removestock') && Tools::isSubmit('is_post')) { // if all is ok, remove stock if (count($this->errors) == 0) { $warehouse = new Warehouse($id_warehouse); // remove stock $stock_manager = StockManagerFactory::getManager(); $removed_products = $stock_manager->removeProduct($id_product, $id_product_attribute, $warehouse, $quantity, $id_stock_mvt_reason, $usable); if (count($removed_products) > 0) { StockAvailable::synchronize($id_product); Tools::redirectAdmin($redirect . '&conf=2'); } else { $physical_quantity_in_stock = (int) $stock_manager->getProductPhysicalQuantities($id_product, $id_product_attribute, array($warehouse->id), false); $usable_quantity_in_stock = (int) $stock_manager->getProductPhysicalQuantities($id_product, $id_product_attribute, array($warehouse->id), true); $not_usable_quantity = $physical_quantity_in_stock - $usable_quantity_in_stock; if ($usable_quantity_in_stock < $quantity) { $this->errors[] = sprintf(Tools::displayError('You don\'t have enough usable quantity. Cannot remove %d items out of %d.'), (int) $quantity, (int) $usable_quantity_in_stock); } elseif ($not_usable_quantity < $quantity) { $this->errors[] = sprintf(Tools::displayError('You don\'t have enough usable quantity. Cannot remove %d items out of %d.'), (int) $quantity, (int) $not_usable_quantity); } else { $this->errors[] = Tools::displayError('It is not possible to remove the specified quantity. Therefore no stock was removed.'); } } } } if (Tools::isSubmit('transferstock') && Tools::isSubmit('is_post')) { // get source warehouse id $id_warehouse_from = (int) Tools::getValue('id_warehouse_from', 0); if ($id_warehouse_from <= 0 || !Warehouse::exists($id_warehouse_from)) { $this->errors[] = Tools::displayError('The source warehouse is not valid.'); } // get destination warehouse id $id_warehouse_to = (int) Tools::getValue('id_warehouse_to', 0); if ($id_warehouse_to <= 0 || !Warehouse::exists($id_warehouse_to)) { $this->errors[] = Tools::displayError('The destination warehouse is not valid.'); } // get usable flag for source warehouse $usable_from = Tools::getValue('usable_from', null); if (is_null($usable_from)) { $this->errors[] = Tools::displayError('You have to specify whether the product quantity in your source warehouse(s) is ready for sale or not.'); } $usable_from = (bool) $usable_from; // get usable flag for destination warehouse $usable_to = Tools::getValue('usable_to', null); if (is_null($usable_to)) { $this->errors[] = Tools::displayError('You have to specify whether the product quantity in your destination warehouse(s) is ready for sale or not.'); } $usable_to = (bool) $usable_to; // if we can process stock transfers if (count($this->errors) == 0) { // transfer stock $stock_manager = StockManagerFactory::getManager(); $is_transfer = $stock_manager->transferBetweenWarehouses($id_product, $id_product_attribute, $quantity, $id_warehouse_from, $id_warehouse_to, $usable_from, $usable_to); StockAvailable::synchronize($id_product); if ($is_transfer) { Tools::redirectAdmin($redirect . '&conf=3'); } else { $this->errors[] = Tools::displayError('It is not possible to transfer the specified quantity. No stock was transferred.'); } } } }
public static function callbackRealQuantity($echo, $tr) { return PP::adminControllerDisplayListContentQuantity($echo, $tr, 'real_quantity', 'stock-instant-state real'); }
public function checkReplacedStringsAndReport($filename, $param, $key = null) { $result = $this->checkReplacedStrings($filename, $param); $length = count($result); if ($length > 0) { $key = $key == null ? $this->module->l('Files integration') : $key; $test_results = array(); $notes = array(); for ($i = 0; $i < $length; $i++) { foreach ($result[$i] as $type => $value) { $info = ''; $details = ''; $note = false; switch ($type) { case 'file_not_found': $info = '<span class="warning"> ' . $this->module->l('(file not found)') . '</span>'; break; case 'string_not_found': $info = $this->notWritableWarning($filename); if (Tools::strlen($info) == 0) { $info = '<span class="warning"> ' . $this->module->l('(string not found)') . '</span>'; $details = '<br><span class="warning-details"><span class="warning">' . $this->module->l('searching for:') . ' </span>' . PP::safeOutput(mb_strimwidth($value[0], 0, 150, ' ...')) . '</span>' . '<br><span class="warning-details"><span class="warning">' . $this->module->l('replace with:') . ' </span>' . PP::safeOutput(mb_strimwidth($value[1], 0, 150, ' ...')) . '</span>'; } break; case 'string_not_found_note': $note = true; $info = $this->notWritableWarning($filename); if (Tools::strlen($info) == 0) { $info = '<span class="note"> ' . $this->module->l('(optional string not found, no action required)') . '</span>'; $details = '<br><span class="note-details"><span class="note">' . $this->module->l('searching for:') . ' </span>' . PP::safeOutput(mb_strimwidth($value[0], 0, 150, ' ...')) . '</span>' . '<br><span class="note-details"><span class="note">' . $this->module->l('replace with:') . ' </span>' . PP::safeOutput(mb_strimwidth($value[1], 0, 150, ' ...')) . '</span>'; } break; case 'string_count': $info = $this->notWritableWarning($filename); if (Tools::strlen($info) == 0) { $info = '<span class="warning"> ' . sprintf($this->module->l('(string expected to be found %d times, found %d times)'), $value[2], $value[3]) . '</span>'; $details = '<br><span class="warning-details"><span class="warning">' . $this->module->l('searching for:') . ' </span>' . PP::safeOutput(mb_strimwidth($value[0], 0, 150, ' ...')) . '</span>' . '<br><span class="warning-details"><span class="warning">' . $this->module->l('replace with:') . ' </span>' . PP::safeOutput(mb_strimwidth($value[1], 0, 150, ' ...')) . '</span>'; } break; default: break; } $str = sprintf($note ? $this->module->l('String replacement note for file: %s%s') : $this->module->l('String replacement warning for file: %s%s'), PSM::normalizePath($filename, 'relative'), $info); if (!in_array($str, $note ? $notes : $test_results)) { if ($note) { $notes[] = $str; } else { $test_results[] = $str; } } if (Tools::strlen($details) > 0) { if ($note) { $notes[] = $details; } else { $test_results[] = $details; } } } } if (count($test_results)) { $str = implode($test_results); if (!isset($this->module->integration_test_result[$key]) || !in_array($str, $this->module->integration_test_result[$key])) { $this->module->integration_test_result[$key][] = $str; } } if (count($notes)) { if (!isset($this->module->integration_test_result_notes)) { $this->module->integration_test_result_notes = array(); } $str = implode($notes); if (!isset($this->module->integration_test_result_notes[$key]) || !in_array($str, $this->module->integration_test_result_notes[$key])) { $this->module->integration_test_result_notes[$key][] = $str; } } return false; } return true; }
public function hookActionValidateOrder($params) { if (!$this->merchant_order || empty($this->merchant_mails)) { return; } // Getting differents vars $context = Context::getContext(); $id_lang = (int) $context->language->id; $id_shop = (int) $context->shop->id; $currency = $params['currency']; $order = $params['order']; $customer = $params['customer']; $configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER', 'PS_MAIL_PASSWD', 'PS_SHOP_NAME', 'PS_MAIL_COLOR'), $id_lang, null, $id_shop); $delivery = new Address((int) $order->id_address_delivery); $invoice = new Address((int) $order->id_address_invoice); $order_date_text = Tools::displayDate($order->date_add); $carrier = new Carrier((int) $order->id_carrier); $message = $this->getAllMessages($order->id); if (!$message || empty($message)) { $message = $this->l('No message'); } $items_table = ''; $products = $params['order']->getProducts(); $customized_datas = Product::getAllCustomizedDatas((int) $params['cart']->id); Product::addCustomizationPrice($products, $customized_datas); foreach ($products as $key => $product) { PP::smartyPPAssign(array('order' => $product, 'currency' => $currency)); $product_has_customized_datas = Product::hasCustomizedDatas($product, $customized_datas); $unit_price = Product::getTaxCalculationMethod($customer->id) == PS_TAX_EXC ? $product['product_price'] : $product['product_price_wt']; $customization_text = ''; if ($product_has_customized_datas && isset($customized_datas[$product['product_id']][$product['product_attribute_id']])) { foreach ($customized_datas[$product['product_id']][$product['product_attribute_id']][$order->id_address_delivery] as $customization) { if ($product['id_cart_product'] == $customization['id_cart_product']) { if (isset($customization['datas'][Product::CUSTOMIZE_TEXTFIELD])) { foreach ($customization['datas'][Product::CUSTOMIZE_TEXTFIELD] as $text) { $customization_text .= $text['name'] . ': ' . $text['value'] . '<br />'; } } if (isset($customization['datas'][Product::CUSTOMIZE_FILE])) { $customization_text .= count($customization['datas'][Product::CUSTOMIZE_FILE]) . ' ' . $this->l('image(s)') . '<br />'; } $customization_text .= '---<br />'; } } if (method_exists('Tools', 'rtrimString')) { $customization_text = Tools::rtrimString($customization_text, '---<br />'); } else { $customization_text = preg_replace('/---<br \\/>$/', '', $customization_text); } } $url = $context->link->getProductLink($product['product_id']); $items_table .= '<tr style="background-color:' . ($key % 2 ? '#DDE2E6' : '#EBECEE') . ';"> <td style="padding:0.6em 0.4em;">' . $product['product_reference'] . '</td> <td style="padding:0.6em 0.4em;"> <strong><a href="' . $url . '">' . $product['product_name'] . '</a>' . (isset($product['attributes_small']) ? ' ' . $product['attributes_small'] : '') . (!empty($customization_text) ? '<br />' . $customization_text : '') . PP::smartyDisplayProductName(array('name' => '')) . '</strong> </td> <td style="padding:0.6em 0.4em; text-align:right;">' . PP::smartyDisplayPrice(array('price' => $unit_price)) . '</td> <td style="padding:0.6em 0.4em; text-align:center;">' . PP::smartyDisplayQty(array('quantity' => $product['product_quantity'])) . '</td> <td style="padding:0.6em 0.4em; text-align:right;">' . PP::smartyDisplayPrice(array('price' => $unit_price * PP::resolveQty($product['product_quantity'], $product['product_quantity_fractional']), 'm' => 'total')) . '</td> </tr>'; PP::smartyPPAssign(); } foreach ($params['order']->getCartRules() as $discount) { $items_table .= '<tr style="background-color:#EBECEE;"> <td colspan="4" style="padding:0.6em 0.4em; text-align:right;">' . $this->l('Voucher code:') . ' ' . $discount['name'] . '</td> <td style="padding:0.6em 0.4em; text-align:right;">-' . Tools::displayPrice($discount['value'], $currency, false) . '</td> </tr>'; } if ($delivery->id_state) { $delivery_state = new State((int) $delivery->id_state); } if ($invoice->id_state) { $invoice_state = new State((int) $invoice->id_state); } if (Product::getTaxCalculationMethod($customer->id) == PS_TAX_EXC) { $total_products = $order->getTotalProductsWithoutTaxes(); } else { $total_products = $order->getTotalProductsWithTaxes(); } $order_state = $params['orderStatus']; // Filling-in vars for email $template_vars = array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{delivery_block_txt}' => MailAlert::getFormatedAddress($delivery, "\n"), '{invoice_block_txt}' => MailAlert::getFormatedAddress($invoice, "\n"), '{delivery_block_html}' => MailAlert::getFormatedAddress($delivery, '<br />', array('firstname' => '<span style="color:' . $configuration['PS_MAIL_COLOR'] . '; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:' . $configuration['PS_MAIL_COLOR'] . '; font-weight:bold;">%s</span>')), '{invoice_block_html}' => MailAlert::getFormatedAddress($invoice, '<br />', array('firstname' => '<span style="color:' . $configuration['PS_MAIL_COLOR'] . '; font-weight:bold;">%s</span>', 'lastname' => '<span style="color:' . $configuration['PS_MAIL_COLOR'] . '; font-weight:bold;">%s</span>')), '{delivery_company}' => $delivery->company, '{delivery_firstname}' => $delivery->firstname, '{delivery_lastname}' => $delivery->lastname, '{delivery_address1}' => $delivery->address1, '{delivery_address2}' => $delivery->address2, '{delivery_city}' => $delivery->city, '{delivery_postal_code}' => $delivery->postcode, '{delivery_country}' => $delivery->country, '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '', '{delivery_phone}' => $delivery->phone ? $delivery->phone : $delivery->phone_mobile, '{delivery_other}' => $delivery->other, '{invoice_company}' => $invoice->company, '{invoice_firstname}' => $invoice->firstname, '{invoice_lastname}' => $invoice->lastname, '{invoice_address2}' => $invoice->address2, '{invoice_address1}' => $invoice->address1, '{invoice_city}' => $invoice->city, '{invoice_postal_code}' => $invoice->postcode, '{invoice_country}' => $invoice->country, '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '', '{invoice_phone}' => $invoice->phone ? $invoice->phone : $invoice->phone_mobile, '{invoice_other}' => $invoice->other, '{order_name}' => $order->reference, '{order_status}' => $order_state->name, '{shop_name}' => $configuration['PS_SHOP_NAME'], '{date}' => $order_date_text, '{carrier}' => $carrier->name == '0' ? $configuration['PS_SHOP_NAME'] : $carrier->name, '{payment}' => Tools::substr($order->payment, 0, 32), '{items}' => $items_table, '{total_paid}' => Tools::displayPrice($order->total_paid, $currency), '{total_products}' => Tools::displayPrice($total_products, $currency), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $currency), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $currency), '{total_tax_paid}' => Tools::displayPrice($order->total_products_wt - $order->total_products + ($order->total_shipping_tax_incl - $order->total_shipping_tax_excl), $currency, false), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $currency), '{currency}' => $currency->sign, '{gift}' => (bool) $order->gift, '{gift_message}' => $order->gift_message, '{message}' => $message); // Shop iso $iso = Language::getIsoById((int) Configuration::get('PS_LANG_DEFAULT')); // Send 1 email by merchant mail, because Mail::Send doesn't work with an array of recipients $merchant_mails = explode(self::__MA_MAIL_DELIMITOR__, $this->merchant_mails); foreach ($merchant_mails as $merchant_mail) { // Default language $mail_id_lang = $id_lang; $mail_iso = $iso; // Use the merchant lang if he exists as an employee $results = Db::getInstance()->executeS(' SELECT `id_lang` FROM `' . _DB_PREFIX_ . 'employee` WHERE `email` = \'' . pSQL($merchant_mail) . '\' '); if ($results) { $user_iso = Language::getIsoById((int) $results[0]['id_lang']); if ($user_iso) { $mail_id_lang = (int) $results[0]['id_lang']; $mail_iso = $user_iso; } } $dir_mail = false; if (file_exists(dirname(__FILE__) . '/mails/' . $mail_iso . '/new_order.txt') && file_exists(dirname(__FILE__) . '/mails/' . $mail_iso . '/new_order.html')) { $dir_mail = dirname(__FILE__) . '/mails/'; } if (file_exists(_PS_MAIL_DIR_ . $mail_iso . '/new_order.txt') && file_exists(_PS_MAIL_DIR_ . $mail_iso . '/new_order.html')) { $dir_mail = _PS_MAIL_DIR_; } if ($dir_mail) { Mail::Send($mail_id_lang, 'new_order', sprintf(Mail::l('New order : #%d - %s', $mail_id_lang), $order->id, $order->reference), $template_vars, $merchant_mail, null, $configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME'], null, null, $dir_mail, null, $id_shop); } } }
public static function getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, $id_product_attribute = null, $all_combinations = false, $id_customer = 0) { if (!SpecificPrice::isFeatureActive()) { return array(); } $now = date('Y-m-d H:i:s'); $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT *, ' . SpecificPrice::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group, $id_customer) . ' FROM `' . _DB_PREFIX_ . 'specific_price` WHERE `id_product` IN(0, ' . (int) $id_product . ') AND ' . (!$all_combinations ? '`id_product_attribute` IN(0, ' . (int) $id_product_attribute . ') AND ' : '') . ' `id_shop` IN(0, ' . (int) $id_shop . ') AND `id_currency` IN(0, ' . (int) $id_currency . ') AND `id_country` IN(0, ' . (int) $id_country . ') AND `id_group` IN(0, ' . (int) $id_group . ') AND `id_customer` IN(0, ' . (int) $id_customer . ') AND ( (`from` = \'0000-00-00 00:00:00\' OR \'' . $now . '\' >= `from`) AND (`to` = \'0000-00-00 00:00:00\' OR \'' . $now . '\' <= `to`) ) ORDER BY `from_quantity` ASC, `id_specific_price_rule` ASC, `score` DESC '); $targeted_prices = array(); $last_quantity = array(); foreach ($res as $specific_price) { if (!isset($last_quantity[(int) $specific_price['id_product_attribute']])) { $last_quantity[(int) $specific_price['id_product_attribute']] = $specific_price['from_quantity']; } elseif ($last_quantity[(int) $specific_price['id_product_attribute']] == $specific_price['from_quantity']) { continue; } $last_quantity[(int) $specific_price['id_product_attribute']] = $specific_price['from_quantity']; if ($specific_price['from_quantity'] > PP::getSpecificPriceFromQty((int) $id_product)) { $targeted_prices[] = $specific_price; } } return $targeted_prices; }
* @author PrestaShop SA <*****@*****.**> * @copyright 2007-2015 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ require_once dirname(__FILE__) . '/../../config/config.inc.php'; require_once dirname(__FILE__) . '/../../init.php'; require_once dirname(__FILE__) . '/WishList.php'; require_once dirname(__FILE__) . '/blockwishlist.php'; $context = Context::getContext(); $action = Tools::getValue('action'); $add = !strcmp($action, 'add') ? 1 : 0; $delete = !strcmp($action, 'delete') ? 1 : 0; $id_wishlist = (int) Tools::getValue('id_wishlist'); $id_product = (int) Tools::getValue('id_product'); $quantity = PP::normalizeProductQty(Tools::getValue('quantity'), $id_product); $id_product_attribute = (int) Tools::getValue('id_product_attribute'); // Instance of module class for translations $module = new BlockWishList(); if (Configuration::get('PS_TOKEN_ENABLE') == 1 && strcmp(Tools::getToken(false), Tools::getValue('token')) && $context->customer->isLogged() === true) { echo $module->l('Invalid token', 'cart'); } if ($context->customer->isLogged()) { if ($id_wishlist && WishList::exists($id_wishlist, $context->customer->id) === true) { $context->cookie->id_wishlist = (int) $id_wishlist; } if ((int) $context->cookie->id_wishlist > 0 && !WishList::exists($context->cookie->id_wishlist, $context->customer->id)) { $context->cookie->id_wishlist = ''; } if (empty($context->cookie->id_wishlist) === true || $context->cookie->id_wishlist == false) { $context->smarty->assign('error', true);
/** * Compiles code for the {/foreach} tag * * @param array $args array with attributes from parser * @param object $compiler compiler object * @param array $parameter array with compilation parameter * * @return string compiled code */ public function compile($args, $compiler, $parameter) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); // must endblock be nocache? if ($compiler->nocache) { $compiler->tag_nocache = true; } list($openTag, $compiler->nocache, $item, $key) = $this->closeTag($compiler, array('foreach', 'foreachelse')); return "<?php } ?>" . PP::smartyCompile('foreach', 'close', $item, $compiler->smarty); }
public function ajaxProcessUpdateQty() { if ($this->tabAccess['edit'] === '1') { $errors = array(); if (!$this->context->cart->id) { return; } if ($this->context->cart->OrderExists()) { $errors[] = Tools::displayError('An order has already been placed with this cart.'); } elseif (!($id_product = (int) Tools::getValue('id_product')) || !($product = new Product((int) $id_product, true, $this->context->language->id))) { $errors[] = Tools::displayError('Invalid product'); } elseif (!($qty = Tools::getValue('qty')) || $qty == 0) { $errors[] = Tools::displayError('Invalid quantity'); } else { $icp = (int) Tools::getValue('icp'); if ($icp != 'add' && (!($icp = (int) $icp) || $icp == 0)) { $errors[] = Tools::displayError('Invalid cart product reference'); } } if (!count($errors)) { // Don't try to use a product if not instanciated before due to errors if (isset($product) && $product->id) { $id_product_attribute = Tools::getValue('id_product_attribute'); if ($icp == 'add') { $id_cart_product = 0; $properties = $product->productProperties(); $qty_policy = $properties['pp_qty_policy']; $qty = PP::resolveInputQty($qty, $qty_policy, $properties['pp_qty_step']); if (PP::qtyPolicyFractional($qty_policy)) { $quantity_fractional = $qty; $qty = 1; $update_qty = $quantity_fractional; } else { $qty = (int) $qty; $quantity_fractional = 0; $update_qty = $qty; } } else { $cart_products = $this->context->cart->getProducts(); if (count($cart_products)) { foreach ($cart_products as $cart_product) { if ($icp == (int) $cart_product['id_cart_product']) { $id_cart_product = $icp; $qty = (int) $qty; $quantity_fractional = $cart_product['cart_quantity_fractional']; $update_qty = $qty; break; } } } } if (isset($id_cart_product)) { if ($id_product_attribute != 0) { if (!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !Attribute::checkAttributeQty((int) $id_product_attribute, PP::resolveQty($qty, $quantity_fractional))) { $errors[] = Tools::displayError('There is not enough product in stock.'); } } else { if (!$product->checkQty(PP::resolveQty($qty, $quantity_fractional))) { $errors[] = Tools::displayError('There is not enough product in stock.'); } } if (!($id_customization = (int) Tools::getValue('id_customization', 0)) && !$product->hasAllRequiredCustomizableFields()) { $errors[] = Tools::displayError('Please fill in all required fields.'); } $this->context->cart->save(); } else { $errors[] = Tools::displayError('This product cannot be added to the cart.'); } } else { $errors[] = Tools::displayError('This product cannot be added to the cart.'); } } if (!count($errors)) { if ((int) $update_qty < 0) { $update_qty = str_replace('-', '', $update_qty); $operator = 'down'; } else { $operator = 'up'; } if (!($qty_upd = $this->context->cart->updateQty($update_qty, $id_product, (int) $id_product_attribute, (int) $id_customization, $operator, 0, null, true, $id_cart_product))) { $errors[] = Tools::displayError('You already have the maximum quantity available for this product.'); } elseif ($qty_upd < 0) { $minimal_qty = $id_product_attribute ? $product->attributeMinQty((int) $id_product_attribute) : $product->minQty(); $errors[] = sprintf(Tools::displayError('You must add a minimum quantity of %d', false), $minimal_qty); } } echo Tools::jsonEncode(array_merge($this->ajaxReturnVars(), array('errors' => $errors))); } }
public static function setQuantity($id_product, $id_product_attribute, $quantity, $id_shop = null) { if (!Validate::isUnsignedId($id_product)) { return false; } $context = Context::getContext(); if ($id_shop === null && Shop::getContext() != Shop::CONTEXT_GROUP) { $id_shop = (int) $context->shop->id; } $depends_on_stock = StockAvailable::dependsOnStock($id_product); if (!$depends_on_stock) { $id_stock_available = (int) StockAvailable::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop); if ($id_stock_available) { $stock_available = new StockAvailable($id_stock_available); PP::setQty($stock_available, $quantity); $stock_available->update(); } else { $out_of_stock = StockAvailable::outOfStock($id_product, $id_shop); $stock_available = new StockAvailable(); $stock_available->out_of_stock = (int) $out_of_stock; $stock_available->id_product = (int) $id_product; $stock_available->id_product_attribute = (int) $id_product_attribute; PP::setQty($stock_available, $quantity); if ($id_shop === null) { $shop_group = Shop::getContextShopGroup(); } else { $shop_group = new ShopGroup((int) Shop::getGroupFromShop((int) $id_shop)); } if ($shop_group->share_stock) { $stock_available->id_shop = 0; $stock_available->id_shop_group = (int) $shop_group->id; } else { $stock_available->id_shop = (int) $id_shop; $stock_available->id_shop_group = 0; } $stock_available->add(); } Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $stock_available->quantity + $stock_available->quantity_remainder)); } Cache::clean('StockAvailable::getQuantityAvailableByProduct_' . (int) $id_product . '*'); }
protected function _displaySpecificPriceModificationForm($defaultCurrency, $shops, $currencies, $countries, $groups) { if (!($obj = $this->loadObject())) { return; } $content = ''; $specific_prices = SpecificPrice::getByProductId((int) $obj->id); $specific_price_priorities = SpecificPrice::getPriority((int) $obj->id); $tmp = array(); foreach ($shops as $shop) { $tmp[$shop['id_shop']] = $shop; } $shops = $tmp; $tmp = array(); foreach ($currencies as $currency) { $tmp[$currency['id_currency']] = $currency; } $currencies = $tmp; $tmp = array(); foreach ($countries as $country) { $tmp[$country['id_country']] = $country; } $countries = $tmp; $tmp = array(); foreach ($groups as $group) { $tmp[$group['id_group']] = $group; } $groups = $tmp; $length_before = strlen($content); if (is_array($specific_prices) && count($specific_prices)) { $i = 0; foreach ($specific_prices as $specific_price) { $id_currency = $specific_price['id_currency'] ? $specific_price['id_currency'] : $defaultCurrency->id; if (!isset($currencies[$id_currency])) { continue; } $current_specific_currency = $currencies[$id_currency]; if ($specific_price['reduction_type'] == 'percentage') { $impact = '- ' . $specific_price['reduction'] * 100 . ' %'; } elseif ($specific_price['reduction'] > 0) { $impact = '- ' . Tools::displayPrice(Tools::ps_round($specific_price['reduction'], 2), $current_specific_currency) . ' '; if ($specific_price['reduction_tax']) { $impact .= '(' . $this->l('Tax incl.') . ')'; } else { $impact .= '(' . $this->l('Tax excl.') . ')'; } } else { $impact = '--'; } if ($specific_price['from'] == '0000-00-00 00:00:00' && $specific_price['to'] == '0000-00-00 00:00:00') { $period = $this->l('Unlimited'); } else { $period = $this->l('From') . ' ' . ($specific_price['from'] != '0000-00-00 00:00:00' ? $specific_price['from'] : '0000-00-00 00:00:00') . '<br />' . $this->l('To') . ' ' . ($specific_price['to'] != '0000-00-00 00:00:00' ? $specific_price['to'] : '0000-00-00 00:00:00'); } if ($specific_price['id_product_attribute']) { $combination = new Combination((int) $specific_price['id_product_attribute']); $attributes = $combination->getAttributesName((int) $this->context->language->id); $attributes_name = ''; foreach ($attributes as $attribute) { $attributes_name .= $attribute['name'] . ' - '; } $attributes_name = rtrim($attributes_name, ' - '); } else { $attributes_name = $this->l('All combinations'); } $rule = new SpecificPriceRule((int) $specific_price['id_specific_price_rule']); $rule_name = $rule->id ? $rule->name : '--'; if ($specific_price['id_customer']) { $customer = new Customer((int) $specific_price['id_customer']); if (Validate::isLoadedObject($customer)) { $customer_full_name = $customer->firstname . ' ' . $customer->lastname; } unset($customer); } if (!$specific_price['id_shop'] || in_array($specific_price['id_shop'], Shop::getContextListShopID())) { $content .= ' <tr ' . ($i % 2 ? 'class="alt_row"' : '') . '> <td>' . $rule_name . '</td> <td>' . $attributes_name . '</td>'; $can_delete_specific_prices = true; if (Shop::isFeatureActive()) { $id_shop_sp = $specific_price['id_shop']; $can_delete_specific_prices = count($this->context->employee->getAssociatedShops()) > 1 && !$id_shop_sp || $id_shop_sp; $content .= ' <td>' . ($id_shop_sp ? $shops[$id_shop_sp]['name'] : $this->l('All shops')) . '</td>'; } $price = Tools::ps_round($specific_price['price'], 2); $fixed_price = $price == Tools::ps_round($obj->price, 2) || $specific_price['price'] == -1 ? '--' : Tools::displayPrice($price, $current_specific_currency); $content .= ' <td>' . ($specific_price['id_currency'] ? $currencies[$specific_price['id_currency']]['name'] : $this->l('All currencies')) . '</td> <td>' . ($specific_price['id_country'] ? $countries[$specific_price['id_country']]['name'] : $this->l('All countries')) . '</td> <td>' . ($specific_price['id_group'] ? $groups[$specific_price['id_group']]['name'] : $this->l('All groups')) . '</td> <td title="' . $this->l('ID:') . ' ' . $specific_price['id_customer'] . '">' . (isset($customer_full_name) ? $customer_full_name : $this->l('All customers')) . '</td> <td>' . $fixed_price . '</td> <td>' . $impact . '</td> <td>' . $period . '</td> <td>' . PP::formatQty($specific_price["from_quantity"]) . '</th> <td>' . (!$rule->id && $can_delete_specific_prices ? '<a class="btn btn-default" name="delete_link" href="' . self::$currentIndex . '&id_product=' . (int) Tools::getValue('id_product') . '&action=deleteSpecificPrice&id_specific_price=' . (int) $specific_price['id_specific_price'] . '&token=' . Tools::getValue('token') . '"><i class="icon-trash"></i></a>' : '') . '</td> </tr>'; $i++; unset($customer_full_name); } } } if ($length_before === strlen($content)) { $content .= ' <tr> <td class="text-center" colspan="13"><i class="icon-warning-sign"></i> ' . $this->l('No specific prices.') . '</td> </tr>'; } $content .= ' </tbody> </table> </div> <div class="panel-footer"> <a href="' . $this->context->link->getAdminLink('AdminProducts') . '" class="btn btn-default"><i class="process-icon-cancel"></i> ' . $this->l('Cancel') . '</a> <button id="product_form_submit_btn" type="submit" name="submitAddproduct" class="btn btn-default pull-right" disabled="disabled"><i class="process-icon-loading"></i> ' . $this->l('Save') . '</button> <button id="product_form_submit_btn" type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right" disabled="disabled"><i class="process-icon-loading"></i> ' . $this->l('Save and stay') . '</button> </div> </div>'; $content .= ' <script type="text/javascript"> var currencies = new Array(); currencies[0] = new Array(); currencies[0]["sign"] = "' . $defaultCurrency->sign . '"; currencies[0]["format"] = ' . intval($defaultCurrency->format) . '; '; foreach ($currencies as $currency) { $content .= ' currencies[' . $currency['id_currency'] . '] = new Array(); currencies[' . $currency['id_currency'] . ']["sign"] = "' . $currency['sign'] . '"; currencies[' . $currency['id_currency'] . ']["format"] = ' . intval($currency['format']) . '; '; } $content .= ' </script> '; // Not use id_customer if ($specific_price_priorities[0] == 'id_customer') { unset($specific_price_priorities[0]); } // Reindex array starting from 0 $specific_price_priorities = array_values($specific_price_priorities); $content .= '<div class="panel"> <h3>' . $this->l('Priority management') . '</h3> <div class="alert alert-info"> ' . $this->l('Sometimes one customer can fit into multiple price rules. Priorities allow you to define which rule applies to the customer.') . ' </div>'; $content .= ' <div class="form-group"> <label class="control-label col-lg-3" for="specificPricePriority1">' . $this->l('Priorities') . '</label> <div class="input-group col-lg-9"> <select id="specificPricePriority1" name="specificPricePriority[]"> <option value="id_shop"' . ($specific_price_priorities[0] == 'id_shop' ? ' selected="selected"' : '') . '>' . $this->l('Shop') . '</option> <option value="id_currency"' . ($specific_price_priorities[0] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option> <option value="id_country"' . ($specific_price_priorities[0] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option> <option value="id_group"' . ($specific_price_priorities[0] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option> </select> <span class="input-group-addon"><i class="icon-chevron-right"></i></span> <select name="specificPricePriority[]"> <option value="id_shop"' . ($specific_price_priorities[1] == 'id_shop' ? ' selected="selected"' : '') . '>' . $this->l('Shop') . '</option> <option value="id_currency"' . ($specific_price_priorities[1] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option> <option value="id_country"' . ($specific_price_priorities[1] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option> <option value="id_group"' . ($specific_price_priorities[1] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option> </select> <span class="input-group-addon"><i class="icon-chevron-right"></i></span> <select name="specificPricePriority[]"> <option value="id_shop"' . ($specific_price_priorities[2] == 'id_shop' ? ' selected="selected"' : '') . '>' . $this->l('Shop') . '</option> <option value="id_currency"' . ($specific_price_priorities[2] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option> <option value="id_country"' . ($specific_price_priorities[2] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option> <option value="id_group"' . ($specific_price_priorities[2] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option> </select> <span class="input-group-addon"><i class="icon-chevron-right"></i></span> <select name="specificPricePriority[]"> <option value="id_shop"' . ($specific_price_priorities[3] == 'id_shop' ? ' selected="selected"' : '') . '>' . $this->l('Shop') . '</option> <option value="id_currency"' . ($specific_price_priorities[3] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option> <option value="id_country"' . ($specific_price_priorities[3] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option> <option value="id_group"' . ($specific_price_priorities[3] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option> </select> </div> </div> <div class="form-group"> <div class="col-lg-9 col-lg-offset-3"> <p class="checkbox"> <label for="specificPricePriorityToAll"><input type="checkbox" name="specificPricePriorityToAll" id="specificPricePriorityToAll" />' . $this->l('Apply to all products') . '</label> </p> </div> </div> <div class="panel-footer"> <a href="' . $this->context->link->getAdminLink('AdminProducts') . '" class="btn btn-default"><i class="process-icon-cancel"></i> ' . $this->l('Cancel') . '</a> <button id="product_form_submit_btn" type="submit" name="submitAddproduct" class="btn btn-default pull-right" disabled="disabled"><i class="process-icon-loading"></i> ' . $this->l('Save') . '</button> <button id="product_form_submit_btn" type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right" disabled="disabled"><i class="process-icon-loading"></i> ' . $this->l('Save and stay') . '</button> </div> </div> '; return $content; }
private function getAllProperties($ms = false) { $ms = PP::resolveMS($ms); $all_properties = array(); $db = Db::getInstance(); $rows = $db->executeS('SELECT * FROM `' . _DB_PREFIX_ . 'pp_property_lang`'); $pp_property = $db->executeS('SELECT * FROM `' . _DB_PREFIX_ . 'pp_property`'); foreach ($this->active_languages as $language) { $id_lang = $language['id_lang']; $properties = array(); foreach ($pp_property as $property) { $id_pp_property = $property['id_pp_property']; $property['text'] = ''; $property['text_1'] = ''; $property['text_2'] = ''; $found = $this->getAllPropertiesLang($property, $rows, $id_pp_property, $id_lang, $ms); if (!$found) { $this->getAllPropertiesLang($property, $rows, $id_pp_property, 1, $ms); } $properties[$id_pp_property] = $property; } $all_properties[$id_lang] = $properties; } return $all_properties; }
protected function displayAjaxSetMeasurementSystem() { $this->context->cookie->pp_measurement_system_fo = PP::resolveMS((int) Tools::getValue('measurement_system')); die('1'); }
public static function callbackPhysicalQuantity($echo, $tr) { return PP::adminControllerDisplayListContentQuantity($echo, $tr, 'physical_quantity', 'stock-mvt physical'); }
function pp_init_with_user() { global $current_user, $pp_current_user, $pp; if (empty($pp_current_user) || !defined('INIT_ACTION_DONE_PP')) { return; } // Prevent conflicts with JSON REST API (no filtering support for now) if (defined('JSON_API_VERSION') && !defined('PP_FILTER_JSON_REST') && false !== strpos($_SERVER['REQUEST_URI'], apply_filters('json_url_prefix', 'wp-json'))) { return; } require_once dirname(__FILE__) . '/pp_main.php'; if (empty($pp)) { $pp = new PP(); } else { $pp->load_user_config(); } $pp_current_user->retrieve_extra_groups(); // retrieve BP groups and other group types registered by 3rd party pp_supplement_user_allcaps($pp_current_user); $current_user->allcaps = array_merge($current_user->allcaps, $pp_current_user->allcaps); // copies above changes and any 3rd party filtering do_action('pp_user_init'); }
function smartyModifierFormatQty($qty, $currency = null) { if ($currency) { return PP::smartyFormatQty(array('qty' => $qty, 'currency' => $currency)); } else { return PP::smartyFormatQty(array('qty' => $qty)); } }
public function testMultipleManyManysToTheSameModel() { $pp1 = new PP(); $pp1->name = 'pp1a'; $pp1->save(); $this->assertTrue($pp1->save()); $pp1Id = $pp1->id; $pp2 = new PP(); $pp2->name = 'pp2a'; $this->assertTrue($pp2->save()); $pp2Id = $pp2->id; $p = new P(); $p->name = 'manyNames'; $p->ppManyAssumptive->add($pp1); $p->ppManySpecific->add($pp2); $this->assertTrue($p->save()); $pId = $p->id; //Retrieve row to make sure columns are coppect $row = ZurmoRedBean::getRow('select * from p'); $this->assertCount(5, $row); $this->assertEquals(1, ZurmoRedBean::count('p_pp')); $row = ZurmoRedBean::getRow('select * from p_pp'); $this->assertTrue(isset($row['p_id']) && ($row['p_id'] = $p->id)); $this->assertTrue(isset($row['pp_id']) && ($row['pp_id'] = $pp1->id)); $this->assertCount(3, $row); $this->assertEquals(1, ZurmoRedBean::count('ppmanyspecificlink_p_pp')); $row = ZurmoRedBean::getRow('select * from ppmanyspecificlink_p_pp'); $this->assertTrue(isset($row['p_id']) && ($row['p_id'] = $p->id)); $this->assertTrue(isset($row['pp_id']) && ($row['pp_id'] = $pp2->id)); $this->assertCount(3, $row); //Unlink and make sure the tables are cleared $p->forget(); $pp1->forget(); $pp2->forget(); $p = P::getById($pId); $this->assertEquals(1, $p->ppManyAssumptive->count()); $this->assertEquals(1, $p->ppManySpecific->count()); $p->ppManyAssumptive->removeAll(); $p->ppManySpecific->removeAll(); $this->assertTrue($p->save()); $this->assertEquals(0, ZurmoRedBean::count('p_pp')); $this->assertEquals(0, ZurmoRedBean::count('ppmanyspecificlink_p_pp')); }
public static function smartyConvertPrice($params, &$smarty = null) { $currency = self::smartyGetCurrency($params); $price = array_key_exists('price', $params) ? $params['price'] : null; $product = array_key_exists('product', $params) ? $params['product'] : self::$smarty_product; if ($product != null) { $product_properties = PP::getProductProperties($product); $mode = array_key_exists('m', $params) ? $params['m'] : null; list($key, $price) = PP::calcProductDisplayPrice($product, $product_properties, $price, $mode); $display = is_numeric($price) ? Tools::displayPrice($price, $currency) : ($price === null ? 0 : $price); if ($key) { $display .= ' <span class="' . $key . '">' . PP::safeOutput($product_properties[$key]) . '</span>'; } } else { $display = Tools::displayPrice($price === null ? 0 : $price, $currency); } return $display; }
public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_method = 'Unknown', $message = null, $extra_vars = array(), $currency_special = null, $dont_touch_amount = false, $secure_key = false, Shop $shop = null) { if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Function called', 1, null, 'Cart', (int) $id_cart, true); } if (!isset($this->context)) { $this->context = Context::getContext(); } $this->context->cart = new Cart($id_cart); $this->context->customer = new Customer($this->context->cart->id_customer); // The tax cart is loaded before the customer so re-cache the tax calculation method $this->context->cart->setTaxCalculationMethod(); $this->context->language = new Language($this->context->cart->id_lang); $this->context->shop = $shop ? $shop : new Shop($this->context->cart->id_shop); ShopUrl::resetMainDomainCache(); $id_currency = $currency_special ? (int) $currency_special : (int) $this->context->cart->id_currency; $this->context->currency = new Currency($id_currency, null, $this->context->shop->id); if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') { $context_country = $this->context->country; } $order_status = new OrderState((int) $id_order_state, (int) $this->context->language->id); if (!Validate::isLoadedObject($order_status)) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Order Status cannot be loaded', 3, null, 'Cart', (int) $id_cart, true); throw new PrestaShopException('Can\'t load Order status'); } if (!$this->active) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Module is not active', 3, null, 'Cart', (int) $id_cart, true); die(Tools::displayError()); } // Does order already exists ? if (Validate::isLoadedObject($this->context->cart) && $this->context->cart->OrderExists() == false) { if ($secure_key !== false && $secure_key != $this->context->cart->secure_key) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Secure key does not match', 3, null, 'Cart', (int) $id_cart, true); die(Tools::displayError()); } // For each package, generate an order $delivery_option_list = $this->context->cart->getDeliveryOptionList(); $package_list = $this->context->cart->getPackageList(); $cart_delivery_option = $this->context->cart->getDeliveryOption(); // If some delivery options are not defined, or not valid, use the first valid option foreach ($delivery_option_list as $id_address => $package) { if (!isset($cart_delivery_option[$id_address]) || !array_key_exists($cart_delivery_option[$id_address], $package)) { foreach ($package as $key => $val) { $cart_delivery_option[$id_address] = $key; break; } } } $order_list = array(); $order_detail_list = array(); do { $reference = Order::generateReference(); } while (Order::getByReference($reference)->count()); $this->currentOrderReference = $reference; $order_creation_failed = false; $cart_total_paid = (double) Tools::ps_round((double) $this->context->cart->getOrderTotal(true, Cart::BOTH), 2); foreach ($cart_delivery_option as $id_address => $key_carriers) { foreach ($delivery_option_list[$id_address][$key_carriers]['carrier_list'] as $id_carrier => $data) { foreach ($data['package_list'] as $id_package) { // Rewrite the id_warehouse $package_list[$id_address][$id_package]['id_warehouse'] = (int) $this->context->cart->getPackageIdWarehouse($package_list[$id_address][$id_package], (int) $id_carrier); $package_list[$id_address][$id_package]['id_carrier'] = $id_carrier; } } } // Make sure CartRule caches are empty CartRule::cleanCache(); $cart_rules = $this->context->cart->getCartRules(); foreach ($cart_rules as $cart_rule) { if (($rule = new CartRule((int) $cart_rule['obj']->id)) && Validate::isLoadedObject($rule)) { if ($error = $rule->checkValidity($this->context, true, true)) { $this->context->cart->removeCartRule((int) $rule->id); if (isset($this->context->cookie) && isset($this->context->cookie->id_customer) && $this->context->cookie->id_customer && !empty($rule->code)) { if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { Tools::redirect('index.php?controller=order-opc&submitAddDiscount=1&discount_name=' . urlencode($rule->code)); } Tools::redirect('index.php?controller=order&submitAddDiscount=1&discount_name=' . urlencode($rule->code)); } else { $rule_name = isset($rule->name[(int) $this->context->cart->id_lang]) ? $rule->name[(int) $this->context->cart->id_lang] : $rule->code; $error = Tools::displayError(sprintf('CartRule ID %1s (%2s) used in this cart is not valid and has been withdrawn from cart', (int) $rule->id, $rule_name)); PrestaShopLogger::addLog($error, 3, '0000002', 'Cart', (int) $this->context->cart->id); } } } } foreach ($package_list as $id_address => $packageByAddress) { foreach ($packageByAddress as $id_package => $package) { $order = new Order(); $order->product_list = $package['product_list']; if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') { $address = new Address($id_address); $this->context->country = new Country($address->id_country, $this->context->cart->id_lang); if (!$this->context->country->active) { throw new PrestaShopException('The delivery address country is not active.'); } } $carrier = null; if (!$this->context->cart->isVirtualCart() && isset($package['id_carrier'])) { $carrier = new Carrier($package['id_carrier'], $this->context->cart->id_lang); $order->id_carrier = (int) $carrier->id; $id_carrier = (int) $carrier->id; } else { $order->id_carrier = 0; $id_carrier = 0; } $order->id_customer = (int) $this->context->cart->id_customer; $order->id_address_invoice = (int) $this->context->cart->id_address_invoice; $order->id_address_delivery = (int) $id_address; $order->id_currency = $this->context->currency->id; $order->id_lang = (int) $this->context->cart->id_lang; $order->id_cart = (int) $this->context->cart->id; $order->reference = $reference; $order->id_shop = (int) $this->context->shop->id; $order->id_shop_group = (int) $this->context->shop->id_shop_group; $order->secure_key = $secure_key ? pSQL($secure_key) : pSQL($this->context->customer->secure_key); $order->payment = $payment_method; if (isset($this->name)) { $order->module = $this->name; } $order->recyclable = $this->context->cart->recyclable; $order->gift = (int) $this->context->cart->gift; $order->gift_message = $this->context->cart->gift_message; $order->mobile_theme = $this->context->cart->mobile_theme; $order->conversion_rate = $this->context->currency->conversion_rate; $amount_paid = !$dont_touch_amount ? Tools::ps_round((double) $amount_paid, 2) : $amount_paid; $order->total_paid_real = 0; $order->total_products = (double) $this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS, $order->product_list, $id_carrier); $order->total_products_wt = (double) $this->context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS, $order->product_list, $id_carrier); $order->total_discounts_tax_excl = (double) abs($this->context->cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS, $order->product_list, $id_carrier)); $order->total_discounts_tax_incl = (double) abs($this->context->cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS, $order->product_list, $id_carrier)); $order->total_discounts = $order->total_discounts_tax_incl; $order->total_shipping_tax_excl = (double) $this->context->cart->getPackageShippingCost((int) $id_carrier, false, null, $order->product_list); $order->total_shipping_tax_incl = (double) $this->context->cart->getPackageShippingCost((int) $id_carrier, true, null, $order->product_list); $order->total_shipping = $order->total_shipping_tax_incl; if (!is_null($carrier) && Validate::isLoadedObject($carrier)) { $order->carrier_tax_rate = $carrier->getTaxesRate(new Address($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); } $order->total_wrapping_tax_excl = (double) abs($this->context->cart->getOrderTotal(false, Cart::ONLY_WRAPPING, $order->product_list, $id_carrier)); $order->total_wrapping_tax_incl = (double) abs($this->context->cart->getOrderTotal(true, Cart::ONLY_WRAPPING, $order->product_list, $id_carrier)); $order->total_wrapping = $order->total_wrapping_tax_incl; $order->total_paid_tax_excl = (double) Tools::ps_round((double) $this->context->cart->getOrderTotal(false, Cart::BOTH, $order->product_list, $id_carrier), _PS_PRICE_COMPUTE_PRECISION_); $order->total_paid_tax_incl = (double) Tools::ps_round((double) $this->context->cart->getOrderTotal(true, Cart::BOTH, $order->product_list, $id_carrier), _PS_PRICE_COMPUTE_PRECISION_); $order->total_paid = $order->total_paid_tax_incl; $order->round_mode = Configuration::get('PS_PRICE_ROUND_MODE'); $order->invoice_date = '0000-00-00 00:00:00'; $order->delivery_date = '0000-00-00 00:00:00'; if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Order is about to be added', 1, null, 'Cart', (int) $id_cart, true); } // Creating order $result = $order->add(); if (!$result) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Order cannot be created', 3, null, 'Cart', (int) $id_cart, true); throw new PrestaShopException('Can\'t save Order'); } // Amount paid by customer is not the right one -> Status = payment error // We don't use the following condition to avoid the float precision issues : http://www.php.net/manual/en/language.types.float.php // if ($order->total_paid != $order->total_paid_real) // We use number_format in order to compare two string if ($order_status->logable && number_format($cart_total_paid, _PS_PRICE_COMPUTE_PRECISION_) != number_format($amount_paid, _PS_PRICE_COMPUTE_PRECISION_)) { $id_order_state = Configuration::get('PS_OS_ERROR'); } $order_list[] = $order; if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - OrderDetail is about to be added', 1, null, 'Cart', (int) $id_cart, true); } // Insert new Order detail list using cart for the current order $order_detail = new OrderDetail(null, null, $this->context); $order_detail->createList($order, $this->context->cart, $id_order_state, $order->product_list, 0, true, $package_list[$id_address][$id_package]['id_warehouse']); $order_detail_list[] = $order_detail; if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - OrderCarrier is about to be added', 1, null, 'Cart', (int) $id_cart, true); } // Adding an entry in order_carrier table if (!is_null($carrier)) { $order_carrier = new OrderCarrier(); $order_carrier->id_order = (int) $order->id; $order_carrier->id_carrier = (int) $id_carrier; $order_carrier->weight = (double) $order->getTotalWeight(); $order_carrier->shipping_cost_tax_excl = (double) $order->total_shipping_tax_excl; $order_carrier->shipping_cost_tax_incl = (double) $order->total_shipping_tax_incl; $order_carrier->add(); } } } // The country can only change if the address used for the calculation is the delivery address, and if multi-shipping is activated if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') { $this->context->country = $context_country; } if (!$this->context->country->active) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Country is not active', 3, null, 'Cart', (int) $id_cart, true); throw new PrestaShopException('The order address country is not active.'); } if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Payment is about to be added', 1, null, 'Cart', (int) $id_cart, true); } // Register Payment only if the order status validate the order if ($order_status->logable) { // $order is the last order loop in the foreach // The method addOrderPayment of the class Order make a create a paymentOrder // linked to the order reference and not to the order id if (isset($extra_vars['transaction_id'])) { $transaction_id = $extra_vars['transaction_id']; } else { $transaction_id = null; } if (!$order->addOrderPayment($amount_paid, null, $transaction_id)) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Cannot save Order Payment', 3, null, 'Cart', (int) $id_cart, true); throw new PrestaShopException('Can\'t save Order Payment'); } } // Next ! $only_one_gift = false; $cart_rule_used = array(); $products = $this->context->cart->getProducts(); // Make sure CarRule caches are empty CartRule::cleanCache(); foreach ($order_detail_list as $key => $order_detail) { $order = $order_list[$key]; if (!$order_creation_failed && isset($order->id)) { if (!$secure_key) { $message .= '<br />' . Tools::displayError('Warning: the secure key is empty, check your payment account before validation'); } // Optional message to attach to this order if (isset($message) & !empty($message)) { $msg = new Message(); $message = strip_tags($message, '<br>'); if (Validate::isCleanHtml($message)) { if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Message is about to be added', 1, null, 'Cart', (int) $id_cart, true); } $msg->message = $message; $msg->id_order = (int) $order->id; $msg->private = 1; $msg->add(); } } // Insert new Order detail list using cart for the current order //$orderDetail = new OrderDetail(null, null, $this->context); //$orderDetail->createList($order, $this->context->cart, $id_order_state); // Construct order detail table for the email $products_list = ''; $virtual_product = true; $ppropertiessmartprice_hook1 = null; $product_var_tpl_list = array(); foreach ($order->product_list as $product) { PP::smartyPPAssign(array('cart' => $product, 'currency' => $this->context->currency)); $price = Product::getPriceStatic((int) $product['id_product'], false, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : null, 6, null, false, true, array($product['cart_quantity'], $product['cart_quantity_fractional']), false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $price_wt = Product::getPriceStatic((int) $product['id_product'], true, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : null, 2, null, false, true, array($product['cart_quantity'], $product['cart_quantity_fractional']), false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $ppropertiessmartprice_hook2 = ''; $product_var_tpl = array('reference' => $product['reference'], 'name' => $product['name'] . (isset($product['attributes']) ? ' - ' . $product['attributes'] : '') . PP::smartyDisplayProductName(array('name' => '')) . $ppropertiessmartprice_hook2, 'unit_price' => PP::smartyDisplayPrice(array('price' => Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt)), 'price' => PP::smartyDisplayPrice(array('price' => Product::getTaxCalculationMethod() == PS_TAX_EXC ? $product['total'] : $product['total_wt'], 'quantity' => (int) $product['cart_quantity'], 'm' => 'total')), 'quantity' => PP::smartyDisplayQty(array('quantity' => (int) $product['cart_quantity'])), 'customization' => array()); $customized_datas = Product::getAllCustomizedDatas((int) $order->id_cart); $productHasCustomizedDatas = Product::hasCustomizedDatas($product, $customized_datas); if ($productHasCustomizedDatas && isset($customized_datas[$product['id_product']][$product['id_product_attribute']])) { $product_var_tpl['customization'] = array(); foreach ($customized_datas[$product['id_product']][$product['id_product_attribute']][$order->id_address_delivery] as $customization) { if ($product['id_cart_product'] == $customization['id_cart_product']) { $customization_text = ''; if (isset($customization['datas'][Product::CUSTOMIZE_TEXTFIELD])) { foreach ($customization['datas'][Product::CUSTOMIZE_TEXTFIELD] as $text) { $customization_text .= $text['name'] . ': ' . $text['value'] . '<br />'; } } if (isset($customization['datas'][Product::CUSTOMIZE_FILE])) { $customization_text .= sprintf(Tools::displayError('%d image(s)'), count($customization['datas'][Product::CUSTOMIZE_FILE])) . '<br />'; } $customization_quantity = (int) $product['customization_quantity']; $product_var_tpl['customization'][] = array('customization_text' => $customization_text, 'customization_quantity' => PP::smartyDisplayQty(array('quantity' => $customization_quantity)), 'quantity' => PP::smartyDisplayPrice(array('price' => Product::getTaxCalculationMethod() == PS_TAX_EXC ? $product['total_customization'] : $product['total_customization_wt'], 'm' => 'total'))); } } } $product_var_tpl_list[] = $product_var_tpl; // Check if is not a virutal product for the displaying of shipping if (!$product['is_virtual']) { $virtual_product &= false; } } // end foreach ($products) PP::smartyPPAssign(); $product_list_txt = ''; $product_list_html = ''; if (count($product_var_tpl_list) > 0) { $product_list_txt = $this->getEmailTemplateContent('order_conf_product_list.txt', Mail::TYPE_TEXT, $product_var_tpl_list); $product_list_html = $this->getEmailTemplateContent('order_conf_product_list.tpl', Mail::TYPE_HTML, $product_var_tpl_list); } $cart_rules_list = array(); $total_reduction_value_ti = 0; $total_reduction_value_tex = 0; foreach ($cart_rules as $cart_rule) { $package = array('id_carrier' => $order->id_carrier, 'id_address' => $order->id_address_delivery, 'products' => $order->product_list); $values = array('tax_incl' => $cart_rule['obj']->getContextualValue(true, $this->context, CartRule::FILTER_ACTION_ALL_NOCAP, $package), 'tax_excl' => $cart_rule['obj']->getContextualValue(false, $this->context, CartRule::FILTER_ACTION_ALL_NOCAP, $package)); // If the reduction is not applicable to this order, then continue with the next one if (!$values['tax_excl']) { continue; } // IF // This is not multi-shipping // The value of the voucher is greater than the total of the order // Partial use is allowed // This is an "amount" reduction, not a reduction in % or a gift // THEN // The voucher is cloned with a new value corresponding to the remainder if (count($order_list) == 1 && $values['tax_incl'] > $order->total_products_wt - $total_reduction_value_ti && $cart_rule['obj']->partial_use == 1 && $cart_rule['obj']->reduction_amount > 0) { // Create a new voucher from the original $voucher = new CartRule($cart_rule['obj']->id); // We need to instantiate the CartRule without lang parameter to allow saving it unset($voucher->id); // Set a new voucher code $voucher->code = empty($voucher->code) ? Tools::substr(md5($order->id . '-' . $order->id_customer . '-' . $cart_rule['obj']->id), 0, 16) : $voucher->code . '-2'; if (preg_match('/\\-([0-9]{1,2})\\-([0-9]{1,2})$/', $voucher->code, $matches) && $matches[1] == $matches[2]) { $voucher->code = preg_replace('/' . $matches[0] . '$/', '-' . (int) ($matches[1] + 1), $voucher->code); } // Set the new voucher value if ($voucher->reduction_tax) { $voucher->reduction_amount = $total_reduction_value_ti + $values['tax_incl'] - $order->total_products_wt; // Add total shipping amout only if reduction amount > total shipping if ($voucher->free_shipping == 1 && $voucher->reduction_amount >= $order->total_shipping_tax_incl) { $voucher->reduction_amount -= $order->total_shipping_tax_incl; } } else { $voucher->reduction_amount = $total_reduction_value_tex + $values['tax_excl'] - $order->total_products; // Add total shipping amout only if reduction amount > total shipping if ($voucher->free_shipping == 1 && $voucher->reduction_amount >= $order->total_shipping_tax_excl) { $voucher->reduction_amount -= $order->total_shipping_tax_excl; } } if ($voucher->reduction_amount <= 0) { continue; } $voucher->id_customer = $order->id_customer; $voucher->quantity = 1; $voucher->quantity_per_user = 1; $voucher->free_shipping = 0; if ($voucher->add()) { // If the voucher has conditions, they are now copied to the new voucher CartRule::copyConditions($cart_rule['obj']->id, $voucher->id); $params = array('{voucher_amount}' => Tools::displayPrice($voucher->reduction_amount, $this->context->currency, false), '{voucher_num}' => $voucher->code, '{firstname}' => $this->context->customer->firstname, '{lastname}' => $this->context->customer->lastname, '{id_order}' => $order->reference, '{order_name}' => $order->getUniqReference()); Mail::Send((int) $order->id_lang, 'voucher', sprintf(Mail::l('New voucher for your order %s', (int) $order->id_lang), $order->reference), $params, $this->context->customer->email, $this->context->customer->firstname . ' ' . $this->context->customer->lastname, null, null, null, null, _PS_MAIL_DIR_, false, (int) $order->id_shop); } $values['tax_incl'] = $order->total_products_wt - $total_reduction_value_ti; $values['tax_excl'] = $order->total_products - $total_reduction_value_tex; } $total_reduction_value_ti += $values['tax_incl']; $total_reduction_value_tex += $values['tax_excl']; $order->addCartRule($cart_rule['obj']->id, $cart_rule['obj']->name, $values, 0, $cart_rule['obj']->free_shipping); if ($id_order_state != Configuration::get('PS_OS_ERROR') && $id_order_state != Configuration::get('PS_OS_CANCELED') && !in_array($cart_rule['obj']->id, $cart_rule_used)) { $cart_rule_used[] = $cart_rule['obj']->id; // Create a new instance of Cart Rule without id_lang, in order to update its quantity $cart_rule_to_update = new CartRule($cart_rule['obj']->id); $cart_rule_to_update->quantity = max(0, $cart_rule_to_update->quantity - 1); $cart_rule_to_update->update(); } $cart_rules_list[] = array('voucher_name' => $cart_rule['obj']->name, 'voucher_reduction' => ($values['tax_incl'] != 0.0 ? '-' : '') . Tools::displayPrice($values['tax_incl'], $this->context->currency, false)); } $cart_rules_list_txt = ''; $cart_rules_list_html = ''; if (count($cart_rules_list) > 0) { $cart_rules_list_txt = $this->getEmailTemplateContent('order_conf_cart_rules.txt', Mail::TYPE_TEXT, $cart_rules_list); $cart_rules_list_html = $this->getEmailTemplateContent('order_conf_cart_rules.tpl', Mail::TYPE_HTML, $cart_rules_list); } // Specify order id for message $old_message = Message::getMessageByCartId((int) $this->context->cart->id); if ($old_message) { $update_message = new Message((int) $old_message['id_message']); $update_message->id_order = (int) $order->id; $update_message->update(); // Add this message in the customer thread $customer_thread = new CustomerThread(); $customer_thread->id_contact = 0; $customer_thread->id_customer = (int) $order->id_customer; $customer_thread->id_shop = (int) $this->context->shop->id; $customer_thread->id_order = (int) $order->id; $customer_thread->id_lang = (int) $this->context->language->id; $customer_thread->email = $this->context->customer->email; $customer_thread->status = 'open'; $customer_thread->token = Tools::passwdGen(12); $customer_thread->add(); $customer_message = new CustomerMessage(); $customer_message->id_customer_thread = $customer_thread->id; $customer_message->id_employee = 0; $customer_message->message = $update_message->message; $customer_message->private = 0; if (!$customer_message->add()) { $this->errors[] = Tools::displayError('An error occurred while saving message'); } } if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Hook validateOrder is about to be called', 1, null, 'Cart', (int) $id_cart, true); } // Hook validate order Hook::exec('actionValidateOrder', array('cart' => $this->context->cart, 'order' => $order, 'customer' => $this->context->customer, 'currency' => $this->context->currency, 'orderStatus' => $order_status)); foreach ($this->context->cart->getProducts() as $product) { if ($order_status->logable) { ProductSale::addProductSale((int) $product['id_product'], (int) $product['cart_quantity']); } } if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Order Status is about to be added', 1, null, 'Cart', (int) $id_cart, true); } // Set the order status $new_history = new OrderHistory(); $new_history->id_order = (int) $order->id; $new_history->changeIdOrderState((int) $id_order_state, $order, true); $new_history->addWithemail(true, $extra_vars); // Switch to back order if needed if (Configuration::get('PS_STOCK_MANAGEMENT') && $order_detail->getStockState()) { $history = new OrderHistory(); $history->id_order = (int) $order->id; $history->changeIdOrderState(Configuration::get($order->valid ? 'PS_OS_OUTOFSTOCK_PAID' : 'PS_OS_OUTOFSTOCK_UNPAID'), $order, true); $history->addWithemail(); } unset($order_detail); // Order is reloaded because the status just changed $order = new Order($order->id); // Send an e-mail to customer (one order = one email) if ($id_order_state != Configuration::get('PS_OS_ERROR') && $id_order_state != Configuration::get('PS_OS_CANCELED') && $this->context->customer->id) { $invoice = new Address($order->id_address_invoice); $delivery = new Address($order->id_address_delivery); $delivery_state = $delivery->id_state ? new State($delivery->id_state) : false; $invoice_state = $invoice->id_state ? new State($invoice->id_state) : false; $data = array('{firstname}' => $this->context->customer->firstname, '{lastname}' => $this->context->customer->lastname, '{email}' => $this->context->customer->email, '{delivery_block_txt}' => $this->_getFormatedAddress($delivery, "\n"), '{invoice_block_txt}' => $this->_getFormatedAddress($invoice, "\n"), '{delivery_block_html}' => $this->_getFormatedAddress($delivery, '<br />', array('firstname' => '<span style="font-weight:bold;">%s</span>', 'lastname' => '<span style="font-weight:bold;">%s</span>')), '{invoice_block_html}' => $this->_getFormatedAddress($invoice, '<br />', array('firstname' => '<span style="font-weight:bold;">%s</span>', 'lastname' => '<span style="font-weight:bold;">%s</span>')), '{delivery_company}' => $delivery->company, '{delivery_firstname}' => $delivery->firstname, '{delivery_lastname}' => $delivery->lastname, '{delivery_address1}' => $delivery->address1, '{delivery_address2}' => $delivery->address2, '{delivery_city}' => $delivery->city, '{delivery_postal_code}' => $delivery->postcode, '{delivery_country}' => $delivery->country, '{delivery_state}' => $delivery->id_state ? $delivery_state->name : '', '{delivery_phone}' => $delivery->phone ? $delivery->phone : $delivery->phone_mobile, '{delivery_other}' => $delivery->other, '{invoice_company}' => $invoice->company, '{invoice_vat_number}' => $invoice->vat_number, '{invoice_firstname}' => $invoice->firstname, '{invoice_lastname}' => $invoice->lastname, '{invoice_address2}' => $invoice->address2, '{invoice_address1}' => $invoice->address1, '{invoice_city}' => $invoice->city, '{invoice_postal_code}' => $invoice->postcode, '{invoice_country}' => $invoice->country, '{invoice_state}' => $invoice->id_state ? $invoice_state->name : '', '{invoice_phone}' => $invoice->phone ? $invoice->phone : $invoice->phone_mobile, '{invoice_other}' => $invoice->other, '{order_name}' => $order->getUniqReference(), '{date}' => Tools::displayDate(date('Y-m-d H:i:s'), null, 1), '{carrier}' => $virtual_product || !isset($carrier->name) ? Tools::displayError('No carrier') : $carrier->name, '{payment}' => Tools::substr($order->payment, 0, 32), '{products}' => $product_list_html, '{products_txt}' => $product_list_txt, '{discounts}' => $cart_rules_list_html, '{discounts_txt}' => $cart_rules_list_txt, '{total_paid}' => Tools::displayPrice($order->total_paid, $this->context->currency, false), '{total_products}' => Tools::displayPrice($order->total_paid - $order->total_shipping - $order->total_wrapping + $order->total_discounts, $this->context->currency, false), '{total_discounts}' => Tools::displayPrice($order->total_discounts, $this->context->currency, false), '{total_shipping}' => Tools::displayPrice($order->total_shipping, $this->context->currency, false), '{total_wrapping}' => Tools::displayPrice($order->total_wrapping, $this->context->currency, false), '{total_tax_paid}' => Tools::displayPrice($order->total_products_wt - $order->total_products + ($order->total_shipping_tax_incl - $order->total_shipping_tax_excl), $this->context->currency, false)); if (is_array($extra_vars)) { $data = array_merge($data, $extra_vars); } // Join PDF invoice if ((int) Configuration::get('PS_INVOICE') && $order_status->invoice && $order->invoice_number) { $pdf = new PDF($order->getInvoicesCollection(), PDF::TEMPLATE_INVOICE, $this->context->smarty); $file_attachement = array(); $file_attachement['content'] = $pdf->render(false); $file_attachement['name'] = Configuration::get('PS_INVOICE_PREFIX', (int) $order->id_lang, null, $order->id_shop) . sprintf('%06d', $order->invoice_number) . '.pdf'; $file_attachement['mime'] = 'application/pdf'; } else { $file_attachement = null; } if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Mail is about to be sent', 1, null, 'Cart', (int) $id_cart, true); } if (Validate::isEmail($this->context->customer->email)) { Mail::Send((int) $order->id_lang, 'order_conf', Mail::l('Order confirmation', (int) $order->id_lang), $data, $this->context->customer->email, $this->context->customer->firstname . ' ' . $this->context->customer->lastname, null, null, $file_attachement, null, _PS_MAIL_DIR_, false, (int) $order->id_shop); } } // updates stock in shops if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { $product_list = $order->getProducts(); foreach ($product_list as $product) { // if the available quantities depends on the physical stock if (StockAvailable::dependsOnStock($product['product_id'])) { // synchronizes StockAvailable::synchronize($product['product_id'], $order->id_shop); } } } } else { $error = Tools::displayError('Order creation failed'); PrestaShopLogger::addLog($error, 4, '0000002', 'Cart', (int) $order->id_cart); die($error); } } // End foreach $order_detail_list // Update Order Details Tax in case cart rules have free shipping foreach ($order->getOrderDetailList() as $detail) { $order_detail = new OrderDetail($detail['id_order_detail']); $order_detail->updateTaxAmount($order); } // Use the last order as currentOrder if (isset($order) && $order->id) { $this->currentOrder = (int) $order->id; } if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - End of validateOrder', 1, null, 'Cart', (int) $id_cart, true); } return true; } else { $error = Tools::displayError('Cart cannot be loaded or an order has already been placed using this cart'); PrestaShopLogger::addLog($error, 4, '0000001', 'Cart', (int) $this->context->cart->id); die($error); } }
protected function getCacheId($name = null) { $cache_array = array(); $cache_array[] = $name !== null ? $name : $this->name; if (Configuration::get('PS_SSL_ENABLED')) { $cache_array[] = (int) Tools::usingSecureMode(); } if (Shop::isFeatureActive()) { $cache_array[] = (int) $this->context->shop->id; } if (Group::isFeatureActive()) { $cache_array[] = (int) Group::getCurrent()->id; } if (Language::isMultiLanguageActivated()) { $cache_array[] = (int) $this->context->language->id; } if (Currency::isMultiCurrencyActivated()) { $cache_array[] = (int) $this->context->currency->id; } $cache_array[] = (int) $this->context->country->id; if (PP::isMeasurementSystemFOActivated()) { $cache_array[] = PP::resolveMS(); } return implode('|', $cache_array); }
private function defaultQtyInternal($qty, $format) { $default_qty = $this->p_properties['pp_default_quantity']; if ($qty > $default_qty) { $default_qty = $qty; } return $format ? PP::formatQty($default_qty) : $default_qty; }
public function ajaxProcessEditProductOnOrder() { // Return value $res = true; $order = new Order((int) Tools::getValue('id_order')); $order_detail = new OrderDetail((int) Tools::getValue('product_id_order_detail')); if (Tools::isSubmit('product_invoice')) { $order_invoice = new OrderInvoice((int) Tools::getValue('product_invoice')); } // Check fields validity $this->doEditProductValidation($order_detail, $order, isset($order_invoice) ? $order_invoice : null); // If multiple product_quantity, the order details concern a product customized $qty_behavior = PP::qtyBehavior($order_detail, $order_detail->product_quantity) && !is_array(Tools::getValue('product_quantity')); $product_quantity = 0; if (is_array(Tools::getValue('product_quantity'))) { foreach (Tools::getValue('product_quantity') as $id_customization => $qty) { // Update quantity of each customization Db::getInstance()->update('customization', array('quantity' => (int) $qty), 'id_customization = ' . (int) $id_customization); // Calculate the real quantity of the product $product_quantity += $qty; } } else { $product_quantity = str_replace(',', '.', Tools::getValue('product_quantity')); } $product_price_tax_incl = Tools::ps_round(Tools::getValue('product_price_tax_incl'), 2); $product_price_tax_excl = Tools::ps_round(Tools::getValue('product_price_tax_excl'), 2); $total_products_tax_incl = PP::calcPrice($product_price_tax_incl, $qty_behavior ? $order_detail->product_quantity : $product_quantity, $qty_behavior ? $product_quantity : $order_detail->product_quantity_fractional, $order_detail->product_id); $total_products_tax_excl = PP::calcPrice($product_price_tax_excl, $qty_behavior ? $order_detail->product_quantity : $product_quantity, $qty_behavior ? $product_quantity : $order_detail->product_quantity_fractional, $order_detail->product_id); // Calculate differences of price (Before / After) $diff_price_tax_incl = $total_products_tax_incl - $order_detail->total_price_tax_incl; $diff_price_tax_excl = $total_products_tax_excl - $order_detail->total_price_tax_excl; $ppropertiessmartprice_hook1 = null; // Apply change on OrderInvoice if (isset($order_invoice)) { // If OrderInvoice to use is different, we update the old invoice and new invoice if ($order_detail->id_order_invoice != $order_invoice->id) { $old_order_invoice = new OrderInvoice($order_detail->id_order_invoice); // We remove cost of products $old_order_invoice->total_products -= $order_detail->total_price_tax_excl; $old_order_invoice->total_products_wt -= $order_detail->total_price_tax_incl; $old_order_invoice->total_paid_tax_excl -= $order_detail->total_price_tax_excl; $old_order_invoice->total_paid_tax_incl -= $order_detail->total_price_tax_incl; $res &= $old_order_invoice->update(); $order_invoice->total_products += $order_detail->total_price_tax_excl; $order_invoice->total_products_wt += $order_detail->total_price_tax_incl; $order_invoice->total_paid_tax_excl += $order_detail->total_price_tax_excl; $order_invoice->total_paid_tax_incl += $order_detail->total_price_tax_incl; $order_detail->id_order_invoice = $order_invoice->id; } } if ($diff_price_tax_incl != 0 && $diff_price_tax_excl != 0) { $order_detail->unit_price_tax_excl = $product_price_tax_excl; $order_detail->unit_price_tax_incl = $product_price_tax_incl; $order_detail->total_price_tax_incl += $diff_price_tax_incl; $order_detail->total_price_tax_excl += $diff_price_tax_excl; if (isset($order_invoice)) { // Apply changes on OrderInvoice $order_invoice->total_products += $diff_price_tax_excl; $order_invoice->total_products_wt += $diff_price_tax_incl; $order_invoice->total_paid_tax_excl += $diff_price_tax_excl; $order_invoice->total_paid_tax_incl += $diff_price_tax_incl; } // Apply changes on Order $order = new Order($order_detail->id_order); $order->total_products += $diff_price_tax_excl; $order->total_products_wt += $diff_price_tax_incl; $order->total_paid += $diff_price_tax_incl; $order->total_paid_tax_excl += $diff_price_tax_excl; $order->total_paid_tax_incl += $diff_price_tax_incl; $res &= $order->update(); } $old_quantity = PP::resolveQty($order_detail->product_quantity, $order_detail->product_quantity_fractional); if ($qty_behavior) { $order_detail->product_quantity_fractional = $product_quantity; } else { $order_detail->product_quantity = $product_quantity; } // update taxes $res &= $order_detail->updateTaxAmount($order); // Save order detail $res &= $order_detail->update(); // Update weight SUM $order_carrier = new OrderCarrier((int) $order->getIdOrderCarrier()); if (Validate::isLoadedObject($order_carrier)) { $order_carrier->weight = (double) $order->getTotalWeight(); $res &= $order_carrier->update(); if ($res) { $order->weight = sprintf('%.3f ' . Configuration::get('PS_WEIGHT_UNIT'), $order_carrier->weight); } } // Save order invoice if (isset($order_invoice)) { $res &= $order_invoice->update(); } // Update product available quantity StockAvailable::updateQuantity($order_detail->product_id, $order_detail->product_attribute_id, $old_quantity - PP::resolveQty($order_detail->product_quantity, $order_detail->product_quantity_fractional), $order->id_shop); $products = $this->getProducts($order); // Get the last product $product = $products[$order_detail->id]; $resume = OrderSlip::getProductSlipResume($order_detail->id); $product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity']; $product['amount_refundable'] = $product['total_price_tax_excl'] - $resume['amount_tax_excl']; $product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl']); $product['refund_history'] = OrderSlip::getProductSlipDetail($order_detail->id); if ($product['id_warehouse'] != 0) { $warehouse = new Warehouse((int) $product['id_warehouse']); $product['warehouse_name'] = $warehouse->name; } else { $product['warehouse_name'] = '--'; } // Get invoices collection $invoice_collection = $order->getInvoicesCollection(); $invoice_array = array(); foreach ($invoice_collection as $invoice) { $invoice->name = $invoice->getInvoiceNumberFormatted(Context::getContext()->language->id, (int) $order->id_shop); $invoice_array[] = $invoice; } // Assign to smarty informations in order to show the new product line $this->context->smarty->assign(array('product' => $product, 'order' => $order, 'currency' => new Currency($order->id_currency), 'can_edit' => $this->tabAccess['edit'], 'invoices_collection' => $invoice_collection, 'current_id_lang' => Context::getContext()->language->id, 'link' => Context::getContext()->link, 'current_index' => self::$currentIndex, 'display_warehouse' => (int) Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))); if (!$res) { die(Tools::jsonEncode(array('result' => $res, 'error' => Tools::displayError('An error occurred while editing the product line.')))); } if (is_array(Tools::getValue('product_quantity'))) { $view = $this->createTemplate('_customized_data.tpl')->fetch(); } else { $view = $this->createTemplate('_product_line.tpl')->fetch(); } $this->sendChangedNotification($order); die(Tools::jsonEncode(array('result' => $res, 'view' => $view, 'can_edit' => $this->tabAccess['add'], 'invoices_collection' => $invoice_collection, 'order' => $order, 'invoices' => $invoice_array, 'documents_html' => $this->createTemplate('_documents.tpl')->fetch(), 'shipping_html' => $this->createTemplate('_shipping.tpl')->fetch(), 'customized_product' => is_array(Tools::getValue('product_quantity'))))); }
private function resolveInputQty($properties, $default_qty) { return PP::resolveInputQty(Tools::getValue('qty'), $properties['pp_qty_policy'], $properties['pp_qty_step'], $default_qty); }
private function calcPrice($product, &$quantity) { $quantity = $product['cart_quantity']; if ($quantity > 1) { $price1 = PP::calcPrice($product['price_wt'], $quantity, $product['cart_quantity_fractional'], $product); $price2 = PP::calcPrice($product['price_wt'], $quantity, $product['cart_quantity_fractional'], null); if ($price1 != $price2) { $price = $price1; $quantity = 1; } else { $price = PP::calcPrice($product['price_wt'], 1, $product['cart_quantity_fractional'], null); } } else { $price = PP::calcPrice($product['price_wt'], 1, $product['cart_quantity_fractional'], $product); } return $price; }