Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php /** * Prestashop Modules & Themen End User License Agreement * * This End Us..
Decoded Output download
<?php
/**
* Prestashop Modules & Themen End User License Agreement
*
* This End User License Agreement ("EULA") is a legal agreement between you and Presta-Apps ltd.
* ( here in referred to as "we" or "us" ) with regard to Prestashop Modules & Themes
* (herein referred to as "Software Product" or "Software").
* By installing or using the Software Product you agree to be bound by the terms of this EULA.
*
* 1. Eligible Licensees. This Software is available for license solely to Software Owners,
* with no right of duplication or further distribution, licensing, or sub-licensing.
* A Software Owner is someone who legally obtained a copy of the Software Product via Prestashop Store.
*
* 2. License Grant. We grant you a personal/one commercial, non-transferable and non-exclusive right to use the copy
* of the Software obtained via Prestashop Store. Modifying, translating, renting, copying, transferring or assigning
* all or part of the Software, or any rights granted hereunder, to any other persons and removing any proprietary
* notices, labels or marks from the Software is strictly prohibited. Furthermore, you hereby agree not to create
* derivative works based on the Software. You may not transfer this Software.
*
* 3. Copyright. The Software is licensed, not sold. You acknowledge that no title to the intellectual property in the
* Software is transferred to you. You further acknowledge that title and full ownership rights to the Software will
* remain the exclusive property of Presta-Apps Mobile, and you will not acquire any rights to the Software,
* except as expressly set forth above.
*
* 4. Reverse Engineering. You agree that you will not attempt, and if you are a corporation,
* you will use your best efforts to prevent your employees and contractors from attempting to reverse compile, modify,
* translate or disassemble the Software in whole or in part. Any failure to comply with the above or any other terms
* and conditions contained herein will result in the automatic termination of this license.
*
* 5. Disclaimer of Warranty. The Software is provided "AS IS" without warranty of any kind. We disclaim and make no
* express or implied warranties and specifically disclaim the warranties of merchantability, fitness for a particular
* purpose and non-infringement of third-party rights. The entire risk as to the quality and performance of the Software
* is with you. We do not warrant that the functions contained in the Software will meet your requirements or that the
* operation of the Software will be error-free.
*
* 6. Limitation of Liability. Our entire liability and your exclusive remedy under this EULA shall not exceed the price
* paid for the Software, if any. In no event shall we be liable to you for any consequential, special, incidental or
* indirect damages of any kind arising out of the use or inability to use the software.
*
* 7. Rental. You may not loan, rent, or lease the Software.
*
* 8. Updates and Upgrades. All updates and upgrades of the Software from a previously released version are governed by
* the terms and conditions of this EULA.
*
* 9. Support. Support for the Software Product is provided by Presta-Apps ltd. For product support, please send an
* email to support at [email protected]
*
* 10. No Liability for Consequential Damages. In no event shall we be liable for any damages whatsoever
* (including, without limitation, incidental, direct, indirect special and consequential damages, damages for loss
* of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of
* the use or inability to use the Software Product. Because some states/countries do not allow the exclusion or
* limitation of liability for consequential or incidental damages, the above limitation may not apply to you.
*
* 11. Indemnification by You. You agree to indemnify, hold harmless and defend us from and against any claims or
* lawsuits, including attorney's fees that arise or result from the use or distribution of the Software in violation
* of this Agreement.
*
* @author Presta-Apps Limited
* @website www.presta-apps.com
* @contact [email protected]
* @copyright 2009-2016 Presta-Apps Ltd.
* @license Proprietary
*/
require dirname(__FILE__) . '/inixframe/loader.php'; include _PS_MODULE_DIR_ . '/inixframe/InixPaymentModule.php'; function CODFEEFloatVal($float) { return (float) str_replace(',', '.', $float); } class CODFeeiw extends Inix2PaymentModule { const MODE_FIXED = 1; const MODE_PERCENT = 2; const MODE_BOTH = 3; const DEBUG_MODE = _PS_MODE_DEV_; const PRODUCT_REFERENCE_ID = 'CODFee'; private $_settings = array( 'CODFEE_CHARGE_MODE' => 1, 'CODFEE_CHARGE_AMOUNT' => 0, 'CODFEE_CHARGE_PERCENT' => 0, 'CODFEE_MIN' => 0, 'CODFEE_MAX' => 0, 'CODFEE_TEXT' => '', ); public function __construct() { $this->name = 'codfeeiw'; $this->tab = 'payments_gateways'; $this->version = '2.1.3'; $this->author = 'presta-apps'; $this->need_instance = 1; $this->controllers = array('validation'); $this->displayName = $this->l('Fee with Cash on delivery (COD)'); $this->description = $this->l('Charge fee with cash on delivery payment option'); $this->currencies = false; $this->ps_versions_compliancy = array('min' => '1.6.0.0', 'max' => '1.7.9.9'); parent::__construct(); if(Tools::version_compare(_PS_VERSION_, '1.4.4')) { $updateConfig = array('PS_OS_CHEQUE', 'PS_OS_PAYMENT', 'PS_OS_PREPARATION', 'PS_OS_SHIPPING', 'PS_OS_CANCELED', 'PS_OS_REFUND', 'PS_OS_ERROR', 'PS_OS_OUTOFSTOCK', 'PS_OS_BANKWIRE', 'PS_OS_PAYPAL', 'PS_OS_WS_PAYMENT'); if ( ! Configuration::get('PS_OS_PAYMENT')) { foreach ($updateConfig as $u) { if ( ! Configuration::get($u) && defined('_' . $u . '_')) { Configuration::updateValue($u, constant('_' . $u . '_')); } } } } } public function install() { if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '<')) { if ( ! parent::install() || ! $this->registerHook('displayPayment') || ! $this->registerHook('displayPaymentReturn') || ! $this->registerHook('displayProductButtons') || ! $this->setupProductInstall() ) { return false; } } else { if ( ! parent::install() || ! $this->registerHook('paymentOptions') || ! $this->registerHook('displayPaymentReturn') || ! $this->registerHook('displayProductButtons') || ! $this->setupProductInstall() || ! $this->registerHook('displayHeader') ) { return false; } } return true; } public function hookDisplayHeader($params) { $this->context->controller->addJS($this->_path . 'views/js/codfeeiw_checkout.js', 'all'); } public function setupProductInstall() { return $this->initProductObject(); } private function initProductObject() { $old_product_id = Configuration::get('CODFEE_PRODUCT_ID'); $ps_lang_default = Configuration::get('PS_LANG_DEFAULT'); if (is_numeric($old_product_id)) { $p = new Product($old_product_id, false, $ps_lang_default); if ($p->reference !== self::PRODUCT_REFERENCE_ID) { $old_product_id = false; $p = new Product(null, false, $ps_lang_default); } } else { $p = new Product(null, false, $ps_lang_default); } $p->name = 'Cache on delivery fee'; $p->description = 'Cache on delivery fee'; $p->description_short = 'Cache on delivery fee'; $p->quantity = 100200300; $p->minimal_quantity = 1; $p->price = 1.0; $p->reference = self::PRODUCT_REFERENCE_ID; $p->visibility = 'none'; $p->is_virtual = 1; $p->active = true; $p->available_for_order = true; $p->redirect_type = '404'; $p->indexed = 0; $p->id_tax_rules_group = 0; $p->link_rewrite = 'cod-fee'; $default_categories = $p->getDefaultCategory(); $p->id_category_default = isset($default_categories['id_category_default']) ? $default_categories['id_category_default'] : $default_categories; $result = $p->save(); if ($result && ! empty($p->id)) { StockAvailable::setQuantity($p->id, 0, $p->quantity); StockAvailable::setProductOutOfStock($p->id, 1); if ( ! is_numeric($old_product_id)) { Configuration::updateValue('CODFEE_PRODUCT_ID', $p->id); } } return $result; } public function uninstall() { if ( ! parent::uninstall() OR ! $this->removeProductInstall() ) { return false; } return true; } private function removeProductInstall() { $product_id = Configuration::get('CODFEE_PRODUCT_ID'); if (is_numeric($product_id)) { $p = new Product((int) $product_id); $deleted = $p->delete(); if ($deleted) { Configuration::deleteByName('CODFEE_PRODUCT_ID'); } } return true; } public function hookDisplayProductButtons($params) { $codfee_product_id = Configuration::get('CODFEE_PRODUCT_ID'); if (empty($codfee_product_id)) { return ''; } if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '<')) { if ( isset($params['product']->id_product) && is_numeric($params['product']->id_product) && (int) $codfee_product_id == (int) $params['product']->id_product ) { Tools::redirect('index.php'); } } else { if ( isset($params['product']['id_product']) && is_numeric($params['product']['id_product']) && (int) $codfee_product_id == (int) $params['product']['id_product'] ) { Tools::redirect('index.php'); } } } public function hookDisplayPayment($params) { if ( ! $this->active) { return; } global $smarty; $i = 0; $products = $params['cart']->getProducts(); $total = count($products); foreach ($products as $key => $product) { $pd = ProductDownload::getIdFromIdProduct((int) ($product['id_product'])); if ($pd AND Validate::isUnsignedInt($pd)) { $i++; } } if ($i && $total == $i) { return false; } $smarty->assign( array( 'this_path' => $this->_path, 'this_path_cod' => $this->_path, 'cod_fee' => $this->getFee($params['cart']), 'codfee_text' => Configuration::get('CODFEE_TEXT', $this->context->language->id), 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/' )); return $this->display(__FILE__, 'payment.tpl'); } public function hookPaymentOptions($params) { if ( ! $this->active) { return; } global $smarty; $i = 0; $products = $params['cart']->getProducts(); $total = count($products); foreach ($products as $key => $product) { $pd = ProductDownload::getIdFromIdProduct((int) ($product['id_product'])); if ($pd AND Validate::isUnsignedInt($pd)) { $i++; } } if ($i && $total == $i) { return false; } $smarty->assign(array( 'this_path' => $this->_path, 'this_path_cod' => $this->_path, 'cod_fee' => Tools::displayPrice($this->getFee($params['cart'])), 'codfee_text' => Configuration::get('CODFEE_TEXT', $this->context->language->id), 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/' )); $newOption = new \PrestaShop\PrestaShop\Core\Payment\PaymentOption(); $newOption->setCallToActionText($this->l('Pay with Cash on delivery (COD)')) ->setAction($this->context->link->getModuleLink($this->name, 'validation', array(), true)) ->setAdditionalInformation($this->context->smarty->fetch('module:codfeeiw/views/templates/hook/ps17/payment.tpl')); $payment_options = [ $newOption, ]; return $payment_options; } public function getFee($cart, $with_tax = true) { $this->loadSettings(); if ($this->_settings['CODFEE_CHARGE_MODE'] == 0) { return false; } if ($this->_settings['CODFEE_CHARGE_AMOUNT'] == 0 AND $this->_settings['CODFEE_CHARGE_PERCENT'] == 0) { return false; } if ($this->_settings['CODFEE_CHARGE_MODE'] == self::MODE_FIXED) { return $this->_settings['CODFEE_CHARGE_AMOUNT']; } else { $cart_total = floatval($cart->getOrderTotal($with_tax, Cart::BOTH)); $percent = $this->_settings['CODFEE_CHARGE_PERCENT'] / 100; $fee = $cart_total * $percent; if ($this->_settings['CODFEE_CHARGE_MODE'] == self::MODE_BOTH) { $fee += $this->_settings['CODFEE_CHARGE_AMOUNT']; } if ($this->_settings['CODFEE_MIN'] != 0 AND $this->_settings['CODFEE_MIN'] > $fee) { $fee = $this->_settings['CODFEE_MIN']; } elseif ($this->_settings['CODFEE_MAX'] != 0 AND $this->_settings['CODFEE_MAX'] < $fee) { $fee = $this->_settings['CODFEE_MAX']; } } return floatval($fee); } public function hookPaymentReturn($params) { if ( ! $this->active) { return; } if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '<')) { return $this->display(__FILE__, 'confirmation.tpl'); } else { $total = Tools::displayPrice($params['order']->getOrdersTotalPaid(), new Currency($params['order']->id_currency), false); $this->context->smarty->assign( array( 'shop_name' => Configuration::get('PS_SHOP_NAME'), 'total' => $total )); return $this->display(__FILE__, 'ps17/confirmation.tpl'); } } public function getContent() { if (Configuration::get('CODFEE_TEXT', $this->context->language->id) === false) { $langs = Language::getLanguages(false); $vals = array(); foreach ($langs as $l) { $vals[$l['id_lang']] = 'You will pay additional fee of'; } Configuration::updateValue('CODFEE_TEXT', $vals); } $this->className = 'Configuration'; $this->object_table = 'configuration'; $this->fields_options = array( 'general' => array( 'title' => $this->l('Fee settings'), 'icon' => '', 'description' => $this->l('This module allows you to charge a extra fee when accepting payments by Cash on delivery.'), 'fields' => array( 'CODFEE_CHARGE_MODE' => array( 'title' => $this->l('Fee charging mode'), 'type' => 'select', 'list' => array( array('value' => self::MODE_FIXED, 'name' => $this->l('Fixed amount')), array('value' => self::MODE_PERCENT, 'name' => $this->l('Percentage')), array('value' => self::MODE_BOTH, 'name' => $this->l('Amount + Percentage')), ), 'identifier' => 'value', ), 'CODFEE_CHARGE_AMOUNT' => array( 'title' => $this->l('Fixed amount'), 'type' => 'text', 'size' => 10, 'cast' => 'CODFEEFloatVal', 'validation' => 'isFloat', 'defaultValue' => 0, ), 'CODFEE_CHARGE_PERCENT' => array( 'title' => $this->l('Percent of the order'), 'type' => 'text', 'size' => 4, 'cast' => 'CODFEEFloatVal', 'validation' => 'isFloat', 'suffix' => '%', 'defaultValue' => 0, ), 'CODFEE_MIN' => array( 'title' => $this->l('Minimum fee'), 'type' => 'text', 'size' => 10, 'cast' => 'CODFEEFloatVal', 'validation' => 'isFloat', 'defaultValue' => 0, 'desc' => $this->l('Set minimum fee that will be charged if the calculated fee is lower') ), 'CODFEE_MAX' => array( 'title' => $this->l('Maximum fee'), 'type' => 'text', 'size' => 10, 'cast' => 'CODFEEFloatVal', 'validation' => 'isFloat', 'defaultValue' => 0, 'desc' => $this->l('Set maximum fee that will be charged if the calculated fee is higher') ), 'CODFEE_TEXT' => array( 'title' => $this->l('Custom text'), 'type' => 'textLang', 'size' => 10, 'required' => true, 'validation' => 'isGenericName', 'defaultValue' => $this->l('You will pay additional fee of') ), 'image' => array( 'type' => 'file', 'title' => $this->l('Image'), 'name' => 'image', 'thumb' => $this->getPathUri() . 'cashondelivery.jpg', ), ), 'submit' => array('title' => $this->l('Update')), ), ); return parent::getContent(); } public function loadSettings() { foreach ($this->_settings as $key => $v) { if ($key == 'CODFEE_TEXT') { if (($val = Configuration::get($key, $this->context->language->id)) !== false) { $this->_settings[$key] = $val; } } else { if (($val = Configuration::get($key)) !== false) { $this->_settings[$key] = $val; } } } return $this->_settings; } public function beforeUpdateOptions() { if (Tools::isSubmit('CODFEE_CHARGE_AMOUNT')) $_POST['CODFEE_CHARGE_AMOUNT'] = str_replace(',', '.', Tools::getValue('CODFEE_CHARGE_AMOUNT')); if (Tools::isSubmit('CODFEE_CHARGE_PERCENT')) $_POST['CODFEE_CHARGE_PERCENT'] = str_replace(',', '.', Tools::getValue('CODFEE_CHARGE_PERCENT')); if (Tools::isSubmit('CODFEE_MIN')) $_POST['CODFEE_MIN'] = str_replace(',', '.', Tools::getValue('CODFEE_MIN')); if (Tools::isSubmit('CODFEE_MAX')) $_POST['CODFEE_MAX'] = str_replace(',', '.', Tools::getValue('CODFEE_MAX')); } public function updateOptionImage() { if ( ! isset($_FILES['image']['tmp_name']) OR empty($_FILES['image']['tmp_name'])) { return; } $up = new UploaderCore('image'); $up->setSavePath($this->getLocalPath()); $ret = $up->process(); foreach ($ret as $file) { if ($file['error']) { $this->errors[] = $file['error']; } else { unlink($this->getLocalPath() . 'cashondelivery.jpg'); ImageManager::resize($file['save_path'], $this->getLocalPath() . 'cashondelivery.jpg'); unlink($file['save_path']); } } } protected function getEmailTemplateContent($template_name, $mail_type, $var) { $email_configuration = Configuration::get('PS_MAIL_TYPE'); if ($email_configuration != $mail_type && $email_configuration != Mail::TYPE_BOTH) { return ''; } $theme_template_path = _PS_THEME_DIR_ . 'mails' . DIRECTORY_SEPARATOR . $this->context->language->iso_code . DIRECTORY_SEPARATOR . $template_name; $default_mail_template_path = _PS_MAIL_DIR_ . $this->context->language->iso_code . DIRECTORY_SEPARATOR . $template_name; if (Tools::file_exists_cache($theme_template_path)) { $default_mail_template_path = $theme_template_path; } if (Tools::file_exists_cache($default_mail_template_path)) { $this->context->smarty->assign('list', $var); return $this->context->smarty->fetch($default_mail_template_path); } return ''; } 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((int)$id_cart); $this->context->customer = new Customer((int)$this->context->cart->id_customer); $this->context->cart->setTaxCalculationMethod(); $this->context->language = new Language((int)$this->context->cart->id_lang); $this->context->shop = ($shop ? $shop : new Shop((int)$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((int)$id_currency, null, (int)$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()); } 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()); } $delivery_option_list = $this->context->cart->getDeliveryOptionList(); $package_list = $this->context->cart->getPackageList(); $cart_delivery_option = $this->context->cart->getDeliveryOption(); 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 = (float)Tools::ps_round((float)$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) { $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; } } } 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 = sprintf(Tools::displayError('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((int)$id_address); $this->context->country = new Country((int)$address->id_country, (int)$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((int)$package['id_carrier'], (int)$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((float)$amount_paid, 2) : $amount_paid; $order->total_paid_real = 0; $order->total_products = (float)$this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS, $order->product_list, $id_carrier); $order->total_products_wt = (float)$this->context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS, $order->product_list, $id_carrier); $order->total_discounts_tax_excl = (float)abs($this->context->cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS, $order->product_list, $id_carrier)); $order->total_discounts_tax_incl = (float)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 = (float)$this->context->cart->getPackageShippingCost((int)$id_carrier, false, null, $order->product_list); $order->total_shipping_tax_incl = (float)$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((int)$this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); } $order->total_wrapping_tax_excl = (float)abs($this->context->cart->getOrderTotal(false, Cart::ONLY_WRAPPING, $order->product_list, $id_carrier)); $order->total_wrapping_tax_incl = (float)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 = (float)Tools::ps_round((float)$this->context->cart->getOrderTotal(false, Cart::BOTH, $order->product_list, $id_carrier), _PS_PRICE_COMPUTE_PRECISION_); $order->total_paid_tax_incl = (float)Tools::ps_round((float)$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->round_type = Configuration::get('PS_ROUND_TYPE'); $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); } $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'); } 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); } $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); } 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 = (float)$order->getTotalWeight(); $order_carrier->shipping_cost_tax_excl = (float)$order->total_shipping_tax_excl; $order_carrier->shipping_cost_tax_incl = (float)$order->total_shipping_tax_incl; $order_carrier->add(); } } } 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); } if ($order_status->logable) { if (isset($extra_vars['transaction_id'])) { $transaction_id = $extra_vars['transaction_id']; } else { $transaction_id = null; } if ( ! isset($order) || ! Validate::isLoadedObject($order) || ! $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'); } } $only_one_gift = false; $cart_rule_used = array(); $products = $this->context->cart->getProducts(); 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'); } 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_cart = (int)$id_cart; $msg->id_customer = (int)($order->id_customer); $msg->id_order = (int)$order->id; $msg->private = 1; $msg->add(); } } $products_list = ''; $virtual_product = true; $product_var_tpl_list = array(); foreach ($order->product_list as $product) { $price = Product::getPriceStatic((int)$product['id_product'], false, ($product['id_product_attribute'] ? (int)$product['id_product_attribute'] : null), 6, null, false, true, $product['cart_quantity'], 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, $product['cart_quantity'], false, (int)$order->id_customer, (int)$order->id_cart, (int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $product_price = Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt; $product_var_tpl = array( 'reference' => $product['reference'], 'name' => $product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : ''), 'unit_price' => Tools::displayPrice($product_price, $this->context->currency, false), 'price' => Tools::displayPrice($product_price * $product['quantity'], $this->context->currency, false), 'quantity' => $product['quantity'], 'customization' => array() ); $customized_datas = Product::getAllCustomizedDatas((int)$order->id_cart); if (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) { $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' => $customization_quantity, 'quantity' => Tools::displayPrice($customization_quantity * $product_price, $this->context->currency, false) ); } } $product_var_tpl_list[] = $product_var_tpl; if (!$product['is_virtual']) { $virtual_product &= false; } } $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 (!$values['tax_excl']) { continue; } 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) { $voucher = new CartRule((int)$cart_rule['obj']->id); unset($voucher->id); $voucher->code = empty($voucher->code) ? 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].'$/', '-'.(intval($matches[1]) + 1), $voucher->code); } if ($voucher->reduction_tax) { $voucher->reduction_amount = ($total_reduction_value_ti + $values['tax_incl']) - $order->total_products_wt; 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; 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; } if ($this->context->customer->isGuest()) { $voucher->id_customer = 0; } else { $voucher->id_customer = $order->id_customer; } $voucher->quantity = 1; $voucher->reduction_currency = $order->id_currency; $voucher->quantity_per_user = 1; $voucher->free_shipping = 0; if ($voucher->add()) { 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; $cart_rule_to_update = new CartRule((int)$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.00 ? '-' : '').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); } $old_message = Message::getMessageByCartId((int)$this->context->cart->id); if ($old_message && !$old_message['private']) { $update_message = new Message((int)$old_message['id_message']); $update_message->id_order = (int)$order->id; $update_message->update(); $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::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); } $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); if (Configuration::get('PS_STOCK_MANAGEMENT') && ($order_detail->getStockState() || $order_detail->product_quantity_in_stock <= 0)) { $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 = new Order((int)$order->id); if ($id_order_state != Configuration::get('PS_OS_ERROR') && $id_order_state != Configuration::get('PS_OS_CANCELED') && $this->context->customer->id) { $invoice = new Address((int)$order->id_address_invoice); $delivery = new Address((int)$order->id_address_delivery); $delivery_state = $delivery->id_state ? new State((int)$delivery->id_state) : false; $invoice_state = $invoice->id_state ? new State((int)$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, "
"), '{invoice_block_txt}' => $this->_getFormatedAddress($invoice, "
"), '{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(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $order->total_products : $order->total_products_wt, $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); } if ((int)Configuration::get('PS_INVOICE') && $order_status->invoice && $order->invoice_number) { $order_invoice_list = $order->getInvoicesCollection(); Hook::exec('actionPDFInvoiceRender', array('order_invoice_list' => $order_invoice_list)); $pdf = new PDF($order_invoice_list, PDF::TEMPLATE_INVOICE, $this->context->smarty); $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 ); } } if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { $product_list = $order->getProducts(); foreach ($product_list as $product) { if (StockAvailable::dependsOnStock($product['product_id'])) { StockAvailable::synchronize($product['product_id'], $order->id_shop); } } } $order->updateOrderDetailTax(); } else { $error = Tools::displayError('Order creation failed'); PrestaShopLogger::addLog($error, 4, '0000002', 'Cart', intval($order->id_cart)); die($error); } } 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', intval($this->context->cart->id)); die($error); } } public function removeProduct($cart) { $product_id = (int) Configuration::get('CODFEE_PRODUCT_ID'); $product = $cart->getProducts(false, $product_id); if ( ! empty($product)) { $qauntity = (int) $product[0]['quantity']; $cart->updateQty($qauntity, $product_id, null, false, 'down'); $cart->update(); } } public function setupProduct($cart, $fee, $fee_wt, $product_id) { if ($product_id !== 0) { $p = new Product($product_id); if ((int)Configuration::get('PS_TAX')) { $price = $fee_wt; } else { $price = $fee; } $p->price = $price; $p->save(); $cart->updateQty(1, $product_id); $cart->update(); } } public function initProductUnit(Cart $cart) { $product_id = (int) Configuration::get('CODFEE_PRODUCT_ID'); $cart->getOrderTotal(true, Cart::BOTH); $this->removeProduct($cart); $order_total = $cart->getOrderTotal(true, Cart::BOTH); $fee = $this->getFee($cart, false); $fee_wt = $this->getFee($cart); $total = $order_total + $fee; $total_wt = $order_total + $fee_wt; $this->setupProduct($cart, $fee, $fee_wt, $product_id); return array( $order_total, $fee, $fee_wt, $total, $total_wt ); } } ?>
Did this file decode correctly?
Original Code
<?php
/**
* Prestashop Modules & Themen End User License Agreement
*
* This End User License Agreement ("EULA") is a legal agreement between you and Presta-Apps ltd.
* ( here in referred to as "we" or "us" ) with regard to Prestashop Modules & Themes
* (herein referred to as "Software Product" or "Software").
* By installing or using the Software Product you agree to be bound by the terms of this EULA.
*
* 1. Eligible Licensees. This Software is available for license solely to Software Owners,
* with no right of duplication or further distribution, licensing, or sub-licensing.
* A Software Owner is someone who legally obtained a copy of the Software Product via Prestashop Store.
*
* 2. License Grant. We grant you a personal/one commercial, non-transferable and non-exclusive right to use the copy
* of the Software obtained via Prestashop Store. Modifying, translating, renting, copying, transferring or assigning
* all or part of the Software, or any rights granted hereunder, to any other persons and removing any proprietary
* notices, labels or marks from the Software is strictly prohibited. Furthermore, you hereby agree not to create
* derivative works based on the Software. You may not transfer this Software.
*
* 3. Copyright. The Software is licensed, not sold. You acknowledge that no title to the intellectual property in the
* Software is transferred to you. You further acknowledge that title and full ownership rights to the Software will
* remain the exclusive property of Presta-Apps Mobile, and you will not acquire any rights to the Software,
* except as expressly set forth above.
*
* 4. Reverse Engineering. You agree that you will not attempt, and if you are a corporation,
* you will use your best efforts to prevent your employees and contractors from attempting to reverse compile, modify,
* translate or disassemble the Software in whole or in part. Any failure to comply with the above or any other terms
* and conditions contained herein will result in the automatic termination of this license.
*
* 5. Disclaimer of Warranty. The Software is provided "AS IS" without warranty of any kind. We disclaim and make no
* express or implied warranties and specifically disclaim the warranties of merchantability, fitness for a particular
* purpose and non-infringement of third-party rights. The entire risk as to the quality and performance of the Software
* is with you. We do not warrant that the functions contained in the Software will meet your requirements or that the
* operation of the Software will be error-free.
*
* 6. Limitation of Liability. Our entire liability and your exclusive remedy under this EULA shall not exceed the price
* paid for the Software, if any. In no event shall we be liable to you for any consequential, special, incidental or
* indirect damages of any kind arising out of the use or inability to use the software.
*
* 7. Rental. You may not loan, rent, or lease the Software.
*
* 8. Updates and Upgrades. All updates and upgrades of the Software from a previously released version are governed by
* the terms and conditions of this EULA.
*
* 9. Support. Support for the Software Product is provided by Presta-Apps ltd. For product support, please send an
* email to support at [email protected]
*
* 10. No Liability for Consequential Damages. In no event shall we be liable for any damages whatsoever
* (including, without limitation, incidental, direct, indirect special and consequential damages, damages for loss
* of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of
* the use or inability to use the Software Product. Because some states/countries do not allow the exclusion or
* limitation of liability for consequential or incidental damages, the above limitation may not apply to you.
*
* 11. Indemnification by You. You agree to indemnify, hold harmless and defend us from and against any claims or
* lawsuits, including attorney's fees that arise or result from the use or distribution of the Software in violation
* of this Agreement.
*
* @author Presta-Apps Limited
* @website www.presta-apps.com
* @contact [email protected]
* @copyright 2009-2016 Presta-Apps Ltd.
* @license Proprietary
*/
require dirname(__FILE__) . '/inixframe/loader.php'; include _PS_MODULE_DIR_ . '/inixframe/InixPaymentModule.php'; function CODFEEFloatVal($float) { return (float) str_replace(',', '.', $float); } class CODFeeiw extends Inix2PaymentModule { const MODE_FIXED = 1; const MODE_PERCENT = 2; const MODE_BOTH = 3; const DEBUG_MODE = _PS_MODE_DEV_; const PRODUCT_REFERENCE_ID = 'CODFee'; private $_settings = array( 'CODFEE_CHARGE_MODE' => 1, 'CODFEE_CHARGE_AMOUNT' => 0, 'CODFEE_CHARGE_PERCENT' => 0, 'CODFEE_MIN' => 0, 'CODFEE_MAX' => 0, 'CODFEE_TEXT' => '', ); public function __construct() { $this->name = 'codfeeiw'; $this->tab = 'payments_gateways'; $this->version = '2.1.3'; $this->author = 'presta-apps'; $this->need_instance = 1; $this->controllers = array('validation'); $this->displayName = $this->l('Fee with Cash on delivery (COD)'); $this->description = $this->l('Charge fee with cash on delivery payment option'); $this->currencies = false; $this->ps_versions_compliancy = array('min' => '1.6.0.0', 'max' => '1.7.9.9'); parent::__construct(); if(Tools::version_compare(_PS_VERSION_, '1.4.4')) { $updateConfig = array('PS_OS_CHEQUE', 'PS_OS_PAYMENT', 'PS_OS_PREPARATION', 'PS_OS_SHIPPING', 'PS_OS_CANCELED', 'PS_OS_REFUND', 'PS_OS_ERROR', 'PS_OS_OUTOFSTOCK', 'PS_OS_BANKWIRE', 'PS_OS_PAYPAL', 'PS_OS_WS_PAYMENT'); if ( ! Configuration::get('PS_OS_PAYMENT')) { foreach ($updateConfig as $u) { if ( ! Configuration::get($u) && defined('_' . $u . '_')) { Configuration::updateValue($u, constant('_' . $u . '_')); } } } } } public function install() { if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '<')) { if ( ! parent::install() || ! $this->registerHook('displayPayment') || ! $this->registerHook('displayPaymentReturn') || ! $this->registerHook('displayProductButtons') || ! $this->setupProductInstall() ) { return false; } } else { if ( ! parent::install() || ! $this->registerHook('paymentOptions') || ! $this->registerHook('displayPaymentReturn') || ! $this->registerHook('displayProductButtons') || ! $this->setupProductInstall() || ! $this->registerHook('displayHeader') ) { return false; } } return true; } public function hookDisplayHeader($params) { $this->context->controller->addJS($this->_path . 'views/js/codfeeiw_checkout.js', 'all'); } public function setupProductInstall() { return $this->initProductObject(); } private function initProductObject() { $old_product_id = Configuration::get('CODFEE_PRODUCT_ID'); $ps_lang_default = Configuration::get('PS_LANG_DEFAULT'); if (is_numeric($old_product_id)) { $p = new Product($old_product_id, false, $ps_lang_default); if ($p->reference !== self::PRODUCT_REFERENCE_ID) { $old_product_id = false; $p = new Product(null, false, $ps_lang_default); } } else { $p = new Product(null, false, $ps_lang_default); } $p->name = 'Cache on delivery fee'; $p->description = 'Cache on delivery fee'; $p->description_short = 'Cache on delivery fee'; $p->quantity = 100200300; $p->minimal_quantity = 1; $p->price = 1.0; $p->reference = self::PRODUCT_REFERENCE_ID; $p->visibility = 'none'; $p->is_virtual = 1; $p->active = true; $p->available_for_order = true; $p->redirect_type = '404'; $p->indexed = 0; $p->id_tax_rules_group = 0; $p->link_rewrite = 'cod-fee'; $default_categories = $p->getDefaultCategory(); $p->id_category_default = isset($default_categories['id_category_default']) ? $default_categories['id_category_default'] : $default_categories; $result = $p->save(); if ($result && ! empty($p->id)) { StockAvailable::setQuantity($p->id, 0, $p->quantity); StockAvailable::setProductOutOfStock($p->id, 1); if ( ! is_numeric($old_product_id)) { Configuration::updateValue('CODFEE_PRODUCT_ID', $p->id); } } return $result; } public function uninstall() { if ( ! parent::uninstall() OR ! $this->removeProductInstall() ) { return false; } return true; } private function removeProductInstall() { $product_id = Configuration::get('CODFEE_PRODUCT_ID'); if (is_numeric($product_id)) { $p = new Product((int) $product_id); $deleted = $p->delete(); if ($deleted) { Configuration::deleteByName('CODFEE_PRODUCT_ID'); } } return true; } public function hookDisplayProductButtons($params) { $codfee_product_id = Configuration::get('CODFEE_PRODUCT_ID'); if (empty($codfee_product_id)) { return ''; } if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '<')) { if ( isset($params['product']->id_product) && is_numeric($params['product']->id_product) && (int) $codfee_product_id == (int) $params['product']->id_product ) { Tools::redirect('index.php'); } } else { if ( isset($params['product']['id_product']) && is_numeric($params['product']['id_product']) && (int) $codfee_product_id == (int) $params['product']['id_product'] ) { Tools::redirect('index.php'); } } } public function hookDisplayPayment($params) { if ( ! $this->active) { return; } global $smarty; $i = 0; $products = $params['cart']->getProducts(); $total = count($products); foreach ($products as $key => $product) { $pd = ProductDownload::getIdFromIdProduct((int) ($product['id_product'])); if ($pd AND Validate::isUnsignedInt($pd)) { $i++; } } if ($i && $total == $i) { return false; } $smarty->assign( array( 'this_path' => $this->_path, 'this_path_cod' => $this->_path, 'cod_fee' => $this->getFee($params['cart']), 'codfee_text' => Configuration::get('CODFEE_TEXT', $this->context->language->id), 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/' )); return $this->display(__FILE__, 'payment.tpl'); } public function hookPaymentOptions($params) { if ( ! $this->active) { return; } global $smarty; $i = 0; $products = $params['cart']->getProducts(); $total = count($products); foreach ($products as $key => $product) { $pd = ProductDownload::getIdFromIdProduct((int) ($product['id_product'])); if ($pd AND Validate::isUnsignedInt($pd)) { $i++; } } if ($i && $total == $i) { return false; } $smarty->assign(array( 'this_path' => $this->_path, 'this_path_cod' => $this->_path, 'cod_fee' => Tools::displayPrice($this->getFee($params['cart'])), 'codfee_text' => Configuration::get('CODFEE_TEXT', $this->context->language->id), 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/' )); $newOption = new \PrestaShop\PrestaShop\Core\Payment\PaymentOption(); $newOption->setCallToActionText($this->l('Pay with Cash on delivery (COD)')) ->setAction($this->context->link->getModuleLink($this->name, 'validation', array(), true)) ->setAdditionalInformation($this->context->smarty->fetch('module:codfeeiw/views/templates/hook/ps17/payment.tpl')); $payment_options = [ $newOption, ]; return $payment_options; } public function getFee($cart, $with_tax = true) { $this->loadSettings(); if ($this->_settings['CODFEE_CHARGE_MODE'] == 0) { return false; } if ($this->_settings['CODFEE_CHARGE_AMOUNT'] == 0 AND $this->_settings['CODFEE_CHARGE_PERCENT'] == 0) { return false; } if ($this->_settings['CODFEE_CHARGE_MODE'] == self::MODE_FIXED) { return $this->_settings['CODFEE_CHARGE_AMOUNT']; } else { $cart_total = floatval($cart->getOrderTotal($with_tax, Cart::BOTH)); $percent = $this->_settings['CODFEE_CHARGE_PERCENT'] / 100; $fee = $cart_total * $percent; if ($this->_settings['CODFEE_CHARGE_MODE'] == self::MODE_BOTH) { $fee += $this->_settings['CODFEE_CHARGE_AMOUNT']; } if ($this->_settings['CODFEE_MIN'] != 0 AND $this->_settings['CODFEE_MIN'] > $fee) { $fee = $this->_settings['CODFEE_MIN']; } elseif ($this->_settings['CODFEE_MAX'] != 0 AND $this->_settings['CODFEE_MAX'] < $fee) { $fee = $this->_settings['CODFEE_MAX']; } } return floatval($fee); } public function hookPaymentReturn($params) { if ( ! $this->active) { return; } if (Tools::version_compare(_PS_VERSION_, '1.7.0.0', '<')) { return $this->display(__FILE__, 'confirmation.tpl'); } else { $total = Tools::displayPrice($params['order']->getOrdersTotalPaid(), new Currency($params['order']->id_currency), false); $this->context->smarty->assign( array( 'shop_name' => Configuration::get('PS_SHOP_NAME'), 'total' => $total )); return $this->display(__FILE__, 'ps17/confirmation.tpl'); } } public function getContent() { if (Configuration::get('CODFEE_TEXT', $this->context->language->id) === false) { $langs = Language::getLanguages(false); $vals = array(); foreach ($langs as $l) { $vals[$l['id_lang']] = 'You will pay additional fee of'; } Configuration::updateValue('CODFEE_TEXT', $vals); } $this->className = 'Configuration'; $this->object_table = 'configuration'; $this->fields_options = array( 'general' => array( 'title' => $this->l('Fee settings'), 'icon' => '', 'description' => $this->l('This module allows you to charge a extra fee when accepting payments by Cash on delivery.'), 'fields' => array( 'CODFEE_CHARGE_MODE' => array( 'title' => $this->l('Fee charging mode'), 'type' => 'select', 'list' => array( array('value' => self::MODE_FIXED, 'name' => $this->l('Fixed amount')), array('value' => self::MODE_PERCENT, 'name' => $this->l('Percentage')), array('value' => self::MODE_BOTH, 'name' => $this->l('Amount + Percentage')), ), 'identifier' => 'value', ), 'CODFEE_CHARGE_AMOUNT' => array( 'title' => $this->l('Fixed amount'), 'type' => 'text', 'size' => 10, 'cast' => 'CODFEEFloatVal', 'validation' => 'isFloat', 'defaultValue' => 0, ), 'CODFEE_CHARGE_PERCENT' => array( 'title' => $this->l('Percent of the order'), 'type' => 'text', 'size' => 4, 'cast' => 'CODFEEFloatVal', 'validation' => 'isFloat', 'suffix' => '%', 'defaultValue' => 0, ), 'CODFEE_MIN' => array( 'title' => $this->l('Minimum fee'), 'type' => 'text', 'size' => 10, 'cast' => 'CODFEEFloatVal', 'validation' => 'isFloat', 'defaultValue' => 0, 'desc' => $this->l('Set minimum fee that will be charged if the calculated fee is lower') ), 'CODFEE_MAX' => array( 'title' => $this->l('Maximum fee'), 'type' => 'text', 'size' => 10, 'cast' => 'CODFEEFloatVal', 'validation' => 'isFloat', 'defaultValue' => 0, 'desc' => $this->l('Set maximum fee that will be charged if the calculated fee is higher') ), 'CODFEE_TEXT' => array( 'title' => $this->l('Custom text'), 'type' => 'textLang', 'size' => 10, 'required' => true, 'validation' => 'isGenericName', 'defaultValue' => $this->l('You will pay additional fee of') ), 'image' => array( 'type' => 'file', 'title' => $this->l('Image'), 'name' => 'image', 'thumb' => $this->getPathUri() . 'cashondelivery.jpg', ), ), 'submit' => array('title' => $this->l('Update')), ), ); return parent::getContent(); } public function loadSettings() { foreach ($this->_settings as $key => $v) { if ($key == 'CODFEE_TEXT') { if (($val = Configuration::get($key, $this->context->language->id)) !== false) { $this->_settings[$key] = $val; } } else { if (($val = Configuration::get($key)) !== false) { $this->_settings[$key] = $val; } } } return $this->_settings; } public function beforeUpdateOptions() { if (Tools::isSubmit('CODFEE_CHARGE_AMOUNT')) $_POST['CODFEE_CHARGE_AMOUNT'] = str_replace(',', '.', Tools::getValue('CODFEE_CHARGE_AMOUNT')); if (Tools::isSubmit('CODFEE_CHARGE_PERCENT')) $_POST['CODFEE_CHARGE_PERCENT'] = str_replace(',', '.', Tools::getValue('CODFEE_CHARGE_PERCENT')); if (Tools::isSubmit('CODFEE_MIN')) $_POST['CODFEE_MIN'] = str_replace(',', '.', Tools::getValue('CODFEE_MIN')); if (Tools::isSubmit('CODFEE_MAX')) $_POST['CODFEE_MAX'] = str_replace(',', '.', Tools::getValue('CODFEE_MAX')); } public function updateOptionImage() { if ( ! isset($_FILES['image']['tmp_name']) OR empty($_FILES['image']['tmp_name'])) { return; } $up = new UploaderCore('image'); $up->setSavePath($this->getLocalPath()); $ret = $up->process(); foreach ($ret as $file) { if ($file['error']) { $this->errors[] = $file['error']; } else { unlink($this->getLocalPath() . 'cashondelivery.jpg'); ImageManager::resize($file['save_path'], $this->getLocalPath() . 'cashondelivery.jpg'); unlink($file['save_path']); } } } protected function getEmailTemplateContent($template_name, $mail_type, $var) { $email_configuration = Configuration::get('PS_MAIL_TYPE'); if ($email_configuration != $mail_type && $email_configuration != Mail::TYPE_BOTH) { return ''; } $theme_template_path = _PS_THEME_DIR_ . 'mails' . DIRECTORY_SEPARATOR . $this->context->language->iso_code . DIRECTORY_SEPARATOR . $template_name; $default_mail_template_path = _PS_MAIL_DIR_ . $this->context->language->iso_code . DIRECTORY_SEPARATOR . $template_name; if (Tools::file_exists_cache($theme_template_path)) { $default_mail_template_path = $theme_template_path; } if (Tools::file_exists_cache($default_mail_template_path)) { $this->context->smarty->assign('list', $var); return $this->context->smarty->fetch($default_mail_template_path); } return ''; } 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((int)$id_cart); $this->context->customer = new Customer((int)$this->context->cart->id_customer); $this->context->cart->setTaxCalculationMethod(); $this->context->language = new Language((int)$this->context->cart->id_lang); $this->context->shop = ($shop ? $shop : new Shop((int)$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((int)$id_currency, null, (int)$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()); } 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()); } $delivery_option_list = $this->context->cart->getDeliveryOptionList(); $package_list = $this->context->cart->getPackageList(); $cart_delivery_option = $this->context->cart->getDeliveryOption(); 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 = (float)Tools::ps_round((float)$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) { $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; } } } 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 = sprintf(Tools::displayError('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((int)$id_address); $this->context->country = new Country((int)$address->id_country, (int)$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((int)$package['id_carrier'], (int)$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((float)$amount_paid, 2) : $amount_paid; $order->total_paid_real = 0; $order->total_products = (float)$this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS, $order->product_list, $id_carrier); $order->total_products_wt = (float)$this->context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS, $order->product_list, $id_carrier); $order->total_discounts_tax_excl = (float)abs($this->context->cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS, $order->product_list, $id_carrier)); $order->total_discounts_tax_incl = (float)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 = (float)$this->context->cart->getPackageShippingCost((int)$id_carrier, false, null, $order->product_list); $order->total_shipping_tax_incl = (float)$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((int)$this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); } $order->total_wrapping_tax_excl = (float)abs($this->context->cart->getOrderTotal(false, Cart::ONLY_WRAPPING, $order->product_list, $id_carrier)); $order->total_wrapping_tax_incl = (float)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 = (float)Tools::ps_round((float)$this->context->cart->getOrderTotal(false, Cart::BOTH, $order->product_list, $id_carrier), _PS_PRICE_COMPUTE_PRECISION_); $order->total_paid_tax_incl = (float)Tools::ps_round((float)$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->round_type = Configuration::get('PS_ROUND_TYPE'); $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); } $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'); } 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); } $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); } 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 = (float)$order->getTotalWeight(); $order_carrier->shipping_cost_tax_excl = (float)$order->total_shipping_tax_excl; $order_carrier->shipping_cost_tax_incl = (float)$order->total_shipping_tax_incl; $order_carrier->add(); } } } 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); } if ($order_status->logable) { if (isset($extra_vars['transaction_id'])) { $transaction_id = $extra_vars['transaction_id']; } else { $transaction_id = null; } if ( ! isset($order) || ! Validate::isLoadedObject($order) || ! $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'); } } $only_one_gift = false; $cart_rule_used = array(); $products = $this->context->cart->getProducts(); 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'); } 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_cart = (int)$id_cart; $msg->id_customer = (int)($order->id_customer); $msg->id_order = (int)$order->id; $msg->private = 1; $msg->add(); } } $products_list = ''; $virtual_product = true; $product_var_tpl_list = array(); foreach ($order->product_list as $product) { $price = Product::getPriceStatic((int)$product['id_product'], false, ($product['id_product_attribute'] ? (int)$product['id_product_attribute'] : null), 6, null, false, true, $product['cart_quantity'], 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, $product['cart_quantity'], false, (int)$order->id_customer, (int)$order->id_cart, (int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $product_price = Product::getTaxCalculationMethod() == PS_TAX_EXC ? Tools::ps_round($price, 2) : $price_wt; $product_var_tpl = array( 'reference' => $product['reference'], 'name' => $product['name'].(isset($product['attributes']) ? ' - '.$product['attributes'] : ''), 'unit_price' => Tools::displayPrice($product_price, $this->context->currency, false), 'price' => Tools::displayPrice($product_price * $product['quantity'], $this->context->currency, false), 'quantity' => $product['quantity'], 'customization' => array() ); $customized_datas = Product::getAllCustomizedDatas((int)$order->id_cart); if (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) { $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' => $customization_quantity, 'quantity' => Tools::displayPrice($customization_quantity * $product_price, $this->context->currency, false) ); } } $product_var_tpl_list[] = $product_var_tpl; if (!$product['is_virtual']) { $virtual_product &= false; } } $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 (!$values['tax_excl']) { continue; } 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) { $voucher = new CartRule((int)$cart_rule['obj']->id); unset($voucher->id); $voucher->code = empty($voucher->code) ? 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].'$/', '-'.(intval($matches[1]) + 1), $voucher->code); } if ($voucher->reduction_tax) { $voucher->reduction_amount = ($total_reduction_value_ti + $values['tax_incl']) - $order->total_products_wt; 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; 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; } if ($this->context->customer->isGuest()) { $voucher->id_customer = 0; } else { $voucher->id_customer = $order->id_customer; } $voucher->quantity = 1; $voucher->reduction_currency = $order->id_currency; $voucher->quantity_per_user = 1; $voucher->free_shipping = 0; if ($voucher->add()) { 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; $cart_rule_to_update = new CartRule((int)$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.00 ? '-' : '').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); } $old_message = Message::getMessageByCartId((int)$this->context->cart->id); if ($old_message && !$old_message['private']) { $update_message = new Message((int)$old_message['id_message']); $update_message->id_order = (int)$order->id; $update_message->update(); $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::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); } $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); if (Configuration::get('PS_STOCK_MANAGEMENT') && ($order_detail->getStockState() || $order_detail->product_quantity_in_stock <= 0)) { $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 = new Order((int)$order->id); if ($id_order_state != Configuration::get('PS_OS_ERROR') && $id_order_state != Configuration::get('PS_OS_CANCELED') && $this->context->customer->id) { $invoice = new Address((int)$order->id_address_invoice); $delivery = new Address((int)$order->id_address_delivery); $delivery_state = $delivery->id_state ? new State((int)$delivery->id_state) : false; $invoice_state = $invoice->id_state ? new State((int)$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(Product::getTaxCalculationMethod() == PS_TAX_EXC ? $order->total_products : $order->total_products_wt, $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); } if ((int)Configuration::get('PS_INVOICE') && $order_status->invoice && $order->invoice_number) { $order_invoice_list = $order->getInvoicesCollection(); Hook::exec('actionPDFInvoiceRender', array('order_invoice_list' => $order_invoice_list)); $pdf = new PDF($order_invoice_list, PDF::TEMPLATE_INVOICE, $this->context->smarty); $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 ); } } if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { $product_list = $order->getProducts(); foreach ($product_list as $product) { if (StockAvailable::dependsOnStock($product['product_id'])) { StockAvailable::synchronize($product['product_id'], $order->id_shop); } } } $order->updateOrderDetailTax(); } else { $error = Tools::displayError('Order creation failed'); PrestaShopLogger::addLog($error, 4, '0000002', 'Cart', intval($order->id_cart)); die($error); } } 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', intval($this->context->cart->id)); die($error); } } public function removeProduct($cart) { $product_id = (int) Configuration::get('CODFEE_PRODUCT_ID'); $product = $cart->getProducts(false, $product_id); if ( ! empty($product)) { $qauntity = (int) $product[0]['quantity']; $cart->updateQty($qauntity, $product_id, null, false, 'down'); $cart->update(); } } public function setupProduct($cart, $fee, $fee_wt, $product_id) { if ($product_id !== 0) { $p = new Product($product_id); if ((int)Configuration::get('PS_TAX')) { $price = $fee_wt; } else { $price = $fee; } $p->price = $price; $p->save(); $cart->updateQty(1, $product_id); $cart->update(); } } public function initProductUnit(Cart $cart) { $product_id = (int) Configuration::get('CODFEE_PRODUCT_ID'); $cart->getOrderTotal(true, Cart::BOTH); $this->removeProduct($cart); $order_total = $cart->getOrderTotal(true, Cart::BOTH); $fee = $this->getFee($cart, false); $fee_wt = $this->getFee($cart); $total = $order_total + $fee; $total_wt = $order_total + $fee_wt; $this->setupProduct($cart, $fee, $fee_wt, $product_id); return array( $order_total, $fee, $fee_wt, $total, $total_wt ); } }
Function Calls
| None |
Stats
| MD5 | 4f812c1bb38360b23d79dfe478be0a97 |
| Eval Count | 0 |
| Decode Time | 153 ms |