public function postProcess()
 {
     $sid = Configuration::get('TWOCHECKOUTPP_SID');
     $secret_word = Configuration::get('TWOCHECKOUTPP_SECRET');
     $credit_card_processed = $_REQUEST['credit_card_processed'];
     $order_number = $_REQUEST['order_number'];
     $cart_id = $_REQUEST['merchant_order_id'];
     $cart = new Cart($cart_id);
     $checkout = new twocheckoutpp();
     if (Configuration::get('TWOCHECKOUTPP_CURRENCY') > 0) {
         $amount = number_format($cart->getOrderTotal(true, 3), 2, '.', '');
         $currency_from = Currency::getCurrency($cart->id_currency);
         $currency_to = Currency::getCurrency(Configuration::get('TWOCHECKOUTPP_CURRENCY'));
         $amount = Tools::ps_round($amount / $currency_from['conversion_rate'], 2);
         $total = number_format(Tools::ps_round($amount *= $currency_to['conversion_rate'], 2), 2, '.', '');
     } else {
         $total = number_format($cart->getOrderTotal(true, 3), 2, '.', '');
     }
     //Check the hash
     $compare_string = $secret_word . $sid . $order_number . $total;
     $compare_hash1 = strtoupper(md5($compare_string));
     $compare_hash2 = $_REQUEST['key'];
     if ($compare_hash1 == $compare_hash2) {
         $customer = new Customer($cart->id_customer);
         $total = (double) $cart->getOrderTotal(true, Cart::BOTH);
         $checkout->validateOrder($cart_id, _PS_OS_PAYMENT_, $total, $checkout->displayName, '', array(), NULL, false, $customer->secure_key);
         $order = new Order($checkout->currentOrder);
         Tools::redirect('index.php?controller=order-confirmation&id_cart=' . (int) $cart->id . '&id_module=' . (int) $this->module->id . '&id_order=' . $checkout->currentOrder);
     } else {
         echo 'Hash Mismatch! Please contact the seller directly for assistance.</br>';
         echo 'Total: ' . $total . '</br>';
         echo '2CO Total: ' . $_REQUEST['total'];
     }
 }
Exemplo n.º 2
0
 function hookRightColumn($params)
 {
     global $smarty;
     if ($special = Product::getRandomSpecial(intval($params['cookie']->id_lang))) {
         $smarty->assign(array('special' => $special, 'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'] / (1 + $special['rate'] / 100), 2), 'oldPrice' => $special['price'] + $special['reduction'], 'mediumSize' => Image::getSize('medium')));
     }
     return $this->display(__FILE__, 'blockspecials.tpl');
 }
Exemplo n.º 3
0
 protected function _assignSummaryInformations()
 {
     $summary = $this->context->cart->getSummaryDetails();
     $customizedDatas = Product::getAllCustomizedDatas($this->context->cart->id);
     // override customization tax rate with real tax (tax rules)
     if ($customizedDatas) {
         foreach ($summary['products'] as &$productUpdate) {
             $productId = (int) isset($productUpdate['id_product']) ? $productUpdate['id_product'] : $productUpdate['product_id'];
             $productAttributeId = (int) isset($productUpdate['id_product_attribute']) ? $productUpdate['id_product_attribute'] : $productUpdate['product_attribute_id'];
             if (isset($customizedDatas[$productId][$productAttributeId])) {
                 $productUpdate['tax_rate'] = Tax::getProductTaxRate($productId, $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
             }
         }
         Product::addCustomizationPrice($summary['products'], $customizedDatas);
     }
     $cart_product_context = Context::getContext()->cloneContext();
     foreach ($summary['products'] as $key => &$product) {
         $product['quantity'] = $product['cart_quantity'];
         // for compatibility with 1.2 themes
         if ($cart_product_context->shop->id != $product['id_shop']) {
             $cart_product_context->shop = new Shop((int) $product['id_shop']);
         }
         $product['price_without_specific_price'] = Product::getPriceStatic($product['id_product'], !Product::getTaxCalculationMethod(), $product['id_product_attribute'], _PS_PRICE_COMPUTE_PRECISION_, null, false, false, 1, false, null, null, null, $null, true, true, $cart_product_context);
         /**
          * ABU edit: variable is_discount set à 1 à tord, calcul foireux de presta
          * @bugfix: https://github.com/PrestaShop/PrestaShop/commit/379e28b341730ea95c0b2d6567817305ea841b23
          * @perso: soustraction de l'ecotax au price_without_specific_price @else
          */
         if (Product::getTaxCalculationMethod()) {
             // $product['is_discounted'] = $product['price_without_specific_price'] != Tools::ps_round($product['price'], _PS_PRICE_COMPUTE_PRECISION_);
             $product['is_discounted'] = Tools::ps_round($product['price_without_specific_price'], _PS_PRICE_COMPUTE_PRECISION_) != Tools::ps_round($product['price'], _PS_PRICE_COMPUTE_PRECISION_);
         } else {
             // $product['is_discounted'] = $product['price_without_specific_price'] != Tools::ps_round($product['price_wt'], _PS_PRICE_COMPUTE_PRECISION_);
             $product['is_discounted'] = Tools::ps_round($product['price_without_specific_price'] - $product['ecotax'], _PS_PRICE_COMPUTE_PRECISION_) != Tools::ps_round($product['price_wt'], _PS_PRICE_COMPUTE_PRECISION_);
         }
     }
     // Get available cart rules and unset the cart rules already in the cart
     $available_cart_rules = CartRule::getCustomerCartRules($this->context->language->id, isset($this->context->customer->id) ? $this->context->customer->id : 0, true, true, true, $this->context->cart);
     $cart_cart_rules = $this->context->cart->getCartRules();
     foreach ($available_cart_rules as $key => $available_cart_rule) {
         if (!$available_cart_rule['highlight'] || strpos($available_cart_rule['code'], CartRule::BO_ORDER_CODE_PREFIX) === 0) {
             unset($available_cart_rules[$key]);
             continue;
         }
         foreach ($cart_cart_rules as $cart_cart_rule) {
             if ($available_cart_rule['id_cart_rule'] == $cart_cart_rule['id_cart_rule']) {
                 unset($available_cart_rules[$key]);
                 continue 2;
             }
         }
     }
     $show_option_allow_separate_package = !$this->context->cart->isAllProductsInStock(true) && Configuration::get('PS_SHIP_WHEN_AVAILABLE');
     $this->context->smarty->assign($summary);
     $this->context->smarty->assign(array('token_cart' => Tools::getToken(false), 'isLogged' => $this->isLogged, 'isVirtualCart' => $this->context->cart->isVirtualCart(), 'productNumber' => $this->context->cart->nbProducts(), 'voucherAllowed' => CartRule::isFeatureActive(), 'shippingCost' => $this->context->cart->getOrderTotal(true, Cart::ONLY_SHIPPING), 'shippingCostTaxExc' => $this->context->cart->getOrderTotal(false, Cart::ONLY_SHIPPING), 'customizedDatas' => $customizedDatas, 'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE, 'CUSTOMIZE_TEXTFIELD' => Product::CUSTOMIZE_TEXTFIELD, 'lastProductAdded' => $this->context->cart->getLastProduct(), 'displayVouchers' => $available_cart_rules, 'show_option_allow_separate_package' => $show_option_allow_separate_package, 'smallSize' => Image::getSize(ImageType::getFormatedName('small'))));
     $this->context->smarty->assign(array('HOOK_SHOPPING_CART' => Hook::exec('displayShoppingCartFooter', $summary), 'HOOK_SHOPPING_CART_EXTRA' => Hook::exec('displayShoppingCart', $summary)));
 }
function update_order_canada()
{
    $sql = 'SHOW TABLES LIKE \'' . _DB_PREFIX_ . 'order_tax\'';
    $table = Db::getInstance()->ExecuteS($sql);
    if (!count($table)) {
        Db::getInstance()->Execute('
		CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'order_tax` (
		  `id_order` int(11) NOT NULL,
		  `tax_name` varchar(40) NOT NULL,
		  `tax_rate` decimal(6,3) NOT NULL,
		  `amount` decimal(20,6) NOT NULL
		) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8');
        $address_field = Configuration::get('PS_TAX_ADDRESS_TYPE');
        $sql = 'SELECT `id_order`
					FROM `' . _DB_PREFIX_ . 'orders` o
					LEFT JOIN `' . _DB_PREFIX_ . 'address` a ON (a.`id_address` = o.`' . bqSQL($address_field) . '`)
					LEFT JOIN `' . _DB_PREFIX_ . 'country` c ON (c.`id_country` = a.`id_country`)
					WHERE c.`iso_code` = "CA"';
        $id_order_list = Db::getInstance()->ExecuteS($sql);
        $values = '';
        foreach ($id_order_list as $id_order) {
            $amount = array();
            $id_order = $id_order['id_order'];
            $order = new Order((int) $id_order);
            if (!Validate::isLoadedObject($order)) {
                continue;
            }
            $products = $order->getProducts();
            foreach ($products as $product) {
                if (!array_key_exists($product['tax_name'], $amount)) {
                    $amount[$product['tax_name']] = array('amount' => 0, 'rate' => $product['tax_rate']);
                }
                if ($order->getTaxCalculationMethod() == PS_TAX_EXC) {
                    $total_product = $product['product_price'] * $product['product_quantity'];
                    $amount_tmp = Tools::ps_round($total_product * ($product['tax_rate'] / 100), 2);
                    $amount[$product['tax_name']]['amount'] += Tools::ps_round($total_product * ($product['tax_rate'] / 100), 2);
                } else {
                    $total_product = $product['product_price'] * $product['product_quantity'];
                    $amount_tmp = Tools::ps_round($total_product - $total_product / (1 + $product['tax_rate'] / 100), 2);
                    $amount[$product['tax_name']]['amount'] += Tools::ps_round($total_product - $total_product / (1 + $product['tax_rate'] / 100), 2);
                }
            }
            foreach ($amount as $tax_name => $tax_infos) {
                $values .= '(' . (int) $order->id . ', \'' . pSQL($tax_name) . '\', \'' . pSQL($tax_infos['rate']) . '\', ' . (double) $tax_infos['amount'] . '),';
            }
            unset($order);
        }
        if (!empty($values)) {
            $values = rtrim($values, ",");
            Db::getInstance()->Execute('
			INSERT INTO `' . _DB_PREFIX_ . 'order_tax` (id_order, tax_name, tax_rate, amount)
			VALUES ' . $values);
        }
    }
}
Exemplo n.º 5
0
 public function assignContentVars($params)
 {
     global $errors;
     // Set currency
     if ((int) $params['cart']->id_currency && (int) $params['cart']->id_currency != $this->context->currency->id) {
         $currency = new Currency((int) $params['cart']->id_currency);
     } else {
         $currency = $this->context->currency;
     }
     $taxCalculationMethod = Group::getPriceDisplayMethod((int) Group::getCurrent()->id);
     $useTax = !($taxCalculationMethod == PS_TAX_EXC);
     $products = $params['cart']->getProducts(true);
     $nbTotalProducts = 0;
     foreach ($products as $product) {
         $nbTotalProducts += (int) $product['cart_quantity'];
     }
     $cart_rules = $params['cart']->getCartRules();
     $base_shipping = $params['cart']->getOrderTotal($useTax, Cart::ONLY_SHIPPING);
     $shipping_cost = Tools::displayPrice($base_shipping, $currency);
     $shipping_cost_float = Tools::convertPrice($base_shipping, $currency);
     $wrappingCost = (double) $params['cart']->getOrderTotal($useTax, Cart::ONLY_WRAPPING);
     $totalToPay = $params['cart']->getOrderTotal($useTax);
     if ($useTax && Configuration::get('PS_TAX_DISPLAY') == 1) {
         $totalToPayWithoutTaxes = $params['cart']->getOrderTotal(false);
         $this->smarty->assign('tax_cost', Tools::displayPrice($totalToPay - $totalToPayWithoutTaxes, $currency));
     }
     // The cart content is altered for display
     foreach ($cart_rules as &$cart_rule) {
         if ($cart_rule['free_shipping']) {
             $shipping_cost = Tools::displayPrice(0, $currency);
             $shipping_cost_float = 0;
             $cart_rule['value_real'] -= Tools::convertPrice($params['cart']->getOrderTotal(true, Cart::ONLY_SHIPPING), $currency);
             $cart_rule['value_tax_exc'] = Tools::convertPrice($params['cart']->getOrderTotal(false, Cart::ONLY_SHIPPING), $currency);
         }
         if ($cart_rule['gift_product']) {
             foreach ($products as &$product) {
                 if ($product['id_product'] == $cart_rule['gift_product'] && $product['id_product_attribute'] == $cart_rule['gift_product_attribute']) {
                     $product['is_gift'] = 1;
                     $product['total_wt'] = Tools::ps_round($product['total_wt'] - $product['price_wt'], (int) $currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     $product['total'] = Tools::ps_round($product['total'] - $product['price'], (int) $currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     $cart_rule['value_real'] = Tools::ps_round($cart_rule['value_real'] - $product['price_wt'], (int) $currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     $cart_rule['value_tax_exc'] = Tools::ps_round($cart_rule['value_tax_exc'] - $product['price'], (int) $currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                 }
             }
         }
     }
     $this->smarty->assign(array('products' => $products, 'customizedDatas' => Product::getAllCustomizedDatas((int) $params['cart']->id), 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'discounts' => $cart_rules, 'nb_total_products' => (int) $nbTotalProducts, 'shipping_cost' => $shipping_cost, 'shipping_cost_float' => $shipping_cost_float, 'show_wrapping' => $wrappingCost > 0 ? true : false, 'show_tax' => (int) (Configuration::get('PS_TAX_DISPLAY') == 1 && (int) Configuration::get('PS_TAX')), 'wrapping_cost' => Tools::displayPrice($wrappingCost, $currency), 'product_total' => Tools::displayPrice($params['cart']->getOrderTotal($useTax, Cart::BOTH_WITHOUT_SHIPPING), $currency), 'total' => Tools::displayPrice($totalToPay, $currency), 'order_process' => Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc' : 'order', 'ajax_allowed' => (int) Configuration::get('PS_BLOCK_CART_AJAX') == 1 ? true : false, 'static_token' => Tools::getToken(false)));
     if (count($errors)) {
         $this->smarty->assign('errors', $errors);
     }
     if (isset($this->context->cookie->ajax_blockcart_display)) {
         $this->smarty->assign('colapseExpandStatus', $this->context->cookie->ajax_blockcart_display);
     }
 }
Exemplo n.º 6
0
 public function hookRightColumn($params)
 {
     if (Configuration::get('PS_CATALOG_MODE')) {
         return;
     }
     if (!($special = Product::getRandomSpecial((int) $params['cookie']->id_lang)) && !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')) {
         return;
     }
     $this->smarty->assign(array('special' => $special, 'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2), 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium'))));
     return $this->display(__FILE__, 'blockspecials.tpl');
 }
Exemplo n.º 7
0
 public function hookRightColumn($params)
 {
     if (Configuration::get('PS_CATALOG_MODE')) {
         return;
     }
     // We need to create multiple caches because the products are sorted randomly
     $random = date('Ymd') . '|' . round(rand(1, max(Configuration::get('BLOCKSPECIALS_NB_CACHES'), 1)));
     if (!Configuration::get('BLOCKSPECIALS_NB_CACHES') || !$this->isCached('blockspecials.tpl', $this->getCacheId('blockspecials|' . $random))) {
         $countSpecial = Product::getCountSpecial((int) $params['cookie']->id_lang, 4);
         $this->smarty->assign(array('special' => $countSpecial, 'priceWithoutReduction_tax_excl' => Tools::ps_round(isset($special) ? $special['price_without_reduction'] : 0, 2), 'mediumSize' => Image::getSize(ImageType::getFormatedName('medium'))));
     }
     return $this->display(__FILE__, 'blockspecials.tpl', Configuration::get('BLOCKSPECIALS_NB_CACHES') ? $this->getCacheId('blockspecials|' . $random) : null);
 }
Exemplo n.º 8
0
 public function hookHome($params)
 {
     if (Configuration::get('PS_CATALOG_MODE')) {
         return;
     }
     global $smarty;
     $tmp = Product::getPricesDrop(intval($params['cookie']->id_lang));
     asort($tmp);
     if (!($special = Product::getRandomSpecial((int) $params['cookie']->id_lang)) && !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')) {
         return;
     }
     $this->smarty->assign(array('special' => $special, 'specials' => $tmp, 'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2), 'mediumSize' => Image::getSize('medium_default')));
     return $this->display(__FILE__, 'tmspecials.tpl');
 }
Exemplo n.º 9
0
 public function confirmOrder($custom)
 {
     $cart = new Cart((int) $custom['id_cart']);
     $cart_details = $cart->getSummaryDetails(null, true);
     $cart_hash = sha1(serialize($cart->nbProducts()));
     $this->context->cart = $cart;
     $address = new Address((int) $cart->id_address_invoice);
     $this->context->country = new Country((int) $address->id_country);
     $this->context->customer = new Customer((int) $cart->id_customer);
     $this->context->language = new Language((int) $cart->id_lang);
     $this->context->currency = new Currency((int) $cart->id_currency);
     if (isset($cart->id_shop)) {
         $this->context->shop = new Shop($cart->id_shop);
     }
     $res = $this->getResult();
     if (strcmp($res, "VERIFIED") == 0) {
         $currency_decimals = is_array($this->context->currency) ? (int) $this->context->currency['decimals'] : (int) $this->context->currency->decimals;
         $this->decimals = $currency_decimals * _PS_PRICE_DISPLAY_PRECISION_;
         $message = null;
         $mc_gross = Tools::ps_round(Tools::getValue('mc_gross'), $this->decimals);
         $cart_details = $cart->getSummaryDetails(null, true);
         $shipping = $cart_details['total_shipping_tax_exc'];
         $subtotal = $cart_details['total_price_without_tax'] - $cart_details['total_shipping_tax_exc'];
         $tax = $cart_details['total_tax'];
         $total_price = Tools::ps_round($shipping + $subtotal + $tax, $this->decimals);
         if (bccomp($mc_gross, $total_price, 2) !== 0) {
             $payment = (int) Configuration::get('PS_OS_ERROR');
             $message = $this->l('Price paid on paypal is not the same that on PrestaShop.') . '<br />';
         } elseif ($custom['hash'] != $cart_hash) {
             $payment = (int) Configuration::get('PS_OS_ERROR');
             $message = $this->l('Cart changed, please retry.') . '<br />';
         } else {
             $payment = (int) Configuration::get('PS_OS_PAYMENT');
             $message = $this->l('Payment accepted.') . '<br />';
         }
         $customer = new Customer((int) $cart->id_customer);
         $transaction = PayPalOrder::getTransactionDetails(false);
         if (_PS_VERSION_ < '1.5') {
             $shop = null;
         } else {
             $shop_id = $this->context->shop->id;
             $shop = new Shop($shop_id);
         }
         $this->validateOrder($cart->id, $payment, $total_price, $this->displayName, $message, $transaction, $cart->id_currency, false, $customer->secure_key, $shop);
     }
 }
 /**
  * Assign price and tax to the template
  */
 protected function assignPriceAndTax()
 {
     die('coucou');
     $id_customer = isset($this->context->customer) ? (int) $this->context->customer->id : 0;
     $id_group = (int) Group::getCurrent()->id;
     $id_country = $id_customer ? (int) Customer::getCurrentCountry($id_customer) : (int) Tools::getCountry();
     $group_reduction = GroupReduction::getValueForProduct($this->product->id, $id_group);
     if ($group_reduction === false) {
         $group_reduction = Group::getReduction((int) $this->context->cookie->id_customer) / 100;
     }
     // Tax
     $tax = (double) $this->product->getTaxesRate(new Address((int) $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
     $this->context->smarty->assign('tax_rate', $tax);
     $product_price_with_tax = Product::getPriceStatic($this->product->id, true, null, 6) * 10;
     if (Product::$_taxCalculationMethod == PS_TAX_INC) {
         $product_price_with_tax = Tools::ps_round($product_price_with_tax, 2);
     }
     $product_price_without_eco_tax = (double) $product_price_with_tax - $this->product->ecotax;
     $ecotax_rate = (double) Tax::getProductEcotaxRate($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
     $ecotax_tax_amount = Tools::ps_round($this->product->ecotax, 2);
     if (Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX')) {
         $ecotax_tax_amount = Tools::ps_round($ecotax_tax_amount * (1 + $ecotax_rate / 100), 2);
     }
     $id_currency = (int) $this->context->cookie->id_currency;
     $id_product = (int) $this->product->id;
     $id_shop = $this->context->shop->id;
     $quantity_discounts = SpecificPrice::getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, null, true, (int) $this->context->customer->id);
     foreach ($quantity_discounts as &$quantity_discount) {
         if ($quantity_discount['id_product_attribute']) {
             $combination = new Combination((int) $quantity_discount['id_product_attribute']);
             $attributes = $combination->getAttributesName((int) $this->context->language->id);
             foreach ($attributes as $attribute) {
                 $quantity_discount['attributes'] = $attribute['name'] . ' - ';
             }
             $quantity_discount['attributes'] = rtrim($quantity_discount['attributes'], ' - ');
         }
         if ((int) $quantity_discount['id_currency'] == 0 && $quantity_discount['reduction_type'] == 'amount') {
             $quantity_discount['reduction'] = Tools::convertPriceFull($quantity_discount['reduction'], null, Context::getContext()->currency);
         }
     }
     $product_price = $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false) * 10;
     $address = new Address($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
     $this->context->smarty->assign(array('quantity_discounts' => $this->formatQuantityDiscounts($quantity_discounts, $product_price, (double) $tax, $ecotax_tax_amount), 'ecotax_tax_inc' => $ecotax_tax_amount, 'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2), 'ecotaxTax_rate' => $ecotax_rate, 'productPriceWithoutEcoTax' => (double) $product_price_without_eco_tax, 'group_reduction' => $group_reduction, 'no_tax' => Tax::excludeTaxeOption() || !$this->product->getTaxesRate($address), 'ecotax' => !count($this->errors) && $this->product->ecotax > 0 ? Tools::convertPrice((double) $this->product->ecotax) : 0, 'tax_enabled' => Configuration::get('PS_TAX') && !Configuration::get('AEUC_LABEL_TAX_INC_EXC'), 'customer_group_without_tax' => Group::getPriceDisplayMethod($this->context->customer->id_default_group)));
 }
 public function hookOrderConfirmation($params)
 {
     // Setting parameters
     $parameters = Configuration::getMultiple(array('PS_LANG_DEFAULT'));
     $order = $params['objOrder'];
     if (Validate::isLoadedObject($order)) {
         $conversion_rate = 1;
         $amount = isset($order->total_paid_tax_excl) ? $order->total_paid_tax_excl : 0;
         $shipping = isset($order->total_shipping_tax_incl) ? $order->total_shipping_tax_incl : 0;
         $conversionAmount = $amount - $shipping;
         // Order general information
         $trans = array('id' => (int) $order->id, 'total' => Tools::ps_round((double) $conversionAmount / (double) $conversion_rate, 2));
         $tapfiliate_id = Configuration::get('TAPFILIATE_ID');
         $this->context->smarty->assign('trans', $trans);
         $this->context->smarty->assign('tapfiliate_id', $tapfiliate_id);
         $this->context->smarty->assign('isOrder', true);
         return $this->display(__FILE__, 'views/templates/hook/footer.tpl');
     }
 }
Exemplo n.º 12
0
 public function confirmOrder($custom)
 {
     $cart = new Cart((int) $custom['id_cart']);
     $cart_details = $cart->getSummaryDetails(null, true);
     $cart_hash = sha1(serialize($cart->nbProducts()));
     $this->context->cart = $cart;
     $address = new Address((int) $cart->id_address_invoice);
     $this->context->country = new Country((int) $address->id_country);
     $this->context->customer = new Customer((int) $cart->id_customer);
     $this->context->language = new Language((int) $cart->id_lang);
     $this->context->currency = new Currency((int) $cart->id_currency);
     if (isset($cart->id_shop)) {
         $this->context->shop = new Shop($cart->id_shop);
     }
     $this->createLog($cart->getProducts(true));
     $mc_gross = Tools::getValue('mc_gross');
     $total_price = Tools::ps_round($cart_details['total_price'], 2);
     $message = null;
     $result = $this->verify();
     if (strcmp($result, VERIFIED) == 0) {
         if ($mc_gross != $total_price) {
             $payment = (int) Configuration::get('PS_OS_ERROR');
             $message = $this->l('Price payed on paypal is not the same that on PrestaShop.') . '<br />';
         } elseif ($custom['hash'] != $cart_hash) {
             $payment = (int) Configuration::get('PS_OS_ERROR');
             $message = $this->l('Cart changed, please retry.') . '<br />';
         } else {
             $payment = (int) Configuration::get('PS_OS_WS_PAYMENT');
             $message = $this->l('Payment accepted.') . '<br />';
         }
         $customer = new Customer((int) $cart->id_customer);
         $id_order = (int) Order::getOrderByCartId((int) $cart->id);
         $transaction = array('currency' => pSQL(Tools::getValue(CURRENCY)), 'id_invoice' => pSQL(Tools::getValue(ID_INVOICE)), 'id_transaction' => pSQL(Tools::getValue(ID_TRANSACTION)), 'payment_date' => pSQL(Tools::getValue(PAYMENT_DATE)), 'shipping' => (double) Tools::getValue(SHIPPING), 'total_paid' => (double) Tools::getValue(TOTAL_PAID));
         $this->validateOrder($cart->id, $payment, $total_price, $this->displayName, $message, $transaction, $cart->id_currency, false, $customer->secure_key);
         $history = new OrderHistory();
         $history->id_order = (int) $id_order;
         $history->changeIdOrderState((int) $payment, (int) $id_order);
         $history->addWithemail();
         $history->add();
     }
 }
 /**
  * Convert the entities data into an xml object and return the xml object as a string
  *
  * @param array $aEntity Entity data
  */
 public function formatEntityToXML($aEntity)
 {
     $dom = new DOMDocument('1.0', 'utf-8');
     // Set the root of the XML
     $root = $dom->createElement($this->sEntity);
     $dom->appendChild($root);
     $oOrder = new Order((int) $aEntity['id_order']);
     $root->setAttribute("isodate", date('c', strtotime($oOrder->invoice_date)));
     $userid = $dom->createElement('userid', (int) $oOrder->id_customer);
     $root->appendChild($userid);
     $transactionid = $dom->createElement('transactionid', (int) $oOrder->id);
     $root->appendChild($transactionid);
     $aOrderProducts = $oOrder->getProducts();
     $sReturn = false;
     if (is_array($aOrderProducts) && count($aOrderProducts) > 0) {
         foreach ($aOrderProducts as $aOrderProduct) {
             $item = $dom->createElement('item');
             $root->appendChild($item);
             $itemid = $dom->createElement('itemid', (int) $aOrderProduct['product_id']);
             $item->appendChild($itemid);
             $profile = $dom->createElement('profile', (int) $oOrder->id_lang);
             $item->appendChild($profile);
             if ($oOrder->getTaxCalculationMethod() == PS_TAX_EXC) {
                 $product_price = $aOrderProduct['product_price'] + $aOrderProduct['ecotax'];
             } else {
                 $product_price = $aOrderProduct['product_price_wt'];
             }
             $price = $dom->createElement('price', number_format(Tools::ps_round($product_price, 2), 2, '.', ''));
             $item->appendChild($price);
             $quantity = $dom->createElement('quantity', (int) $aOrderProduct['product_quantity']);
             $item->appendChild($quantity);
         }
         $sReturn = $dom->saveHTML();
     }
     unset($dom);
     unset($oOrder);
     unset($aOrderProducts);
     return $sReturn;
 }
 public function getTaxesAmount($price_before_tax, $price_after_tax = null, $round_precision = 2, $round_mode = null)
 {
     $amounts = array();
     $total_base = 0;
     foreach ($this->getProductTaxes() as $row) {
         if (!array_key_exists($row['id_tax'], $amounts)) {
             $amounts[$row['id_tax']] = array('rate' => $row['rate'], 'base' => 0);
         }
         $amounts[$row['id_tax']]['base'] += $row['total_price_tax_excl'];
         $total_base += $row['total_price_tax_excl'];
     }
     $actual_tax = 0;
     foreach ($amounts as &$data) {
         $data = Tools::ps_round($price_before_tax * ($data['base'] / $total_base) * $data['rate'] / 100, $round_precision, $round_mode);
         $actual_tax += $data;
     }
     unset($data);
     if ($price_after_tax) {
         Tools::spreadAmount($price_after_tax - $price_before_tax - $actual_tax, $round_precision, $amounts, 'id_tax');
     }
     return $amounts;
 }
Exemplo n.º 15
0
 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;
 }
 /**
  * Récupération du prix de shipping pour un produit id
  * @param $shipping
  * @return float
  */
 public function getShippingPrice($product_id, $attribute_id, $id_carrier = 0, $id_zone = 0)
 {
     $product = new Product($product_id);
     $shipping = 0;
     $carrier = new Carrier((int) $id_carrier);
     if ($id_zone == 0) {
         $defaultCountry = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
         $id_zone = (int) $defaultCountry->id_zone;
     }
     $carrierTax = Tax::getCarrierTaxRate((int) $carrier->id);
     $free_weight = Configuration::get('PS_SHIPPING_FREE_WEIGHT');
     $shipping_handling = Configuration::get('PS_SHIPPING_HANDLING');
     if ($product->getPrice(true, $attribute_id, 2, NULL, false, true, 1) >= (double) $free_weight and (double) $free_weight > 0) {
         $shipping = 0;
     } elseif (isset($free_weight) and $product->weight >= (double) $free_weight and (double) $free_weight > 0) {
         $shipping = 0;
     } else {
         if (isset($shipping_handling) and $carrier->shipping_handling) {
             $shipping = (double) $shipping_handling;
         }
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
             $shipping += $carrier->getDeliveryPriceByWeight($product->weight, $id_zone);
         } else {
             $shipping += $carrier->getDeliveryPriceByPrice($product->getPrice(true, $attribute_id, 2, NULL, false, true, 1), $id_zone);
         }
         $shipping *= 1 + $carrierTax / 100;
         $shipping = (double) Tools::ps_round((double) $shipping, 2);
     }
     unset($product);
     return $shipping;
 }
    function content_5590d87d4ca0e9_00902120($_smarty_tpl)
    {
        if ($_smarty_tpl->tpl_vars['product']->value['customizedDatas']) {
            ?>

<?php 
            if ($_smarty_tpl->tpl_vars['order']->value->getTaxCalculationMethod() == @constant('PS_TAX_EXC')) {
                ?>
	<?php 
                $_smarty_tpl->tpl_vars['product_price'] = new Smarty_variable($_smarty_tpl->tpl_vars['product']->value['unit_price_tax_excl'] + $_smarty_tpl->tpl_vars['product']->value['ecotax'], null, 0);
            } else {
                ?>
	<?php 
                $_smarty_tpl->tpl_vars['product_price'] = new Smarty_variable($_smarty_tpl->tpl_vars['product']->value['unit_price_tax_incl'], null, 0);
            }
            ?>
	<tr class="customized customized-<?php 
            echo intval($_smarty_tpl->tpl_vars['product']->value['id_order_detail']);
            ?>
 product-line-row">
		<td>
			<input type="hidden" class="edit_product_id_order_detail" value="<?php 
            echo intval($_smarty_tpl->tpl_vars['product']->value['id_order_detail']);
            ?>
" />
			<?php 
            if (isset($_smarty_tpl->tpl_vars['product']->value['image']) && intval($_smarty_tpl->tpl_vars['product']->value['image']->id)) {
                echo $_smarty_tpl->tpl_vars['product']->value['image_tag'];
            } else {
                ?>
--<?php 
            }
            ?>
		</td>
		<td>
			<a href="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['link']->value->getAdminLink('AdminProducts'), ENT_QUOTES, 'UTF-8', true);
            ?>
&amp;id_product=<?php 
            echo intval($_smarty_tpl->tpl_vars['product']->value['product_id']);
            ?>
&amp;updateproduct&amp;token=<?php 
            echo $_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['getAdminToken'][0][0]->getAdminTokenLiteSmarty(array('tab' => 'AdminProducts'), $_smarty_tpl);
            ?>
">
			<span class="productName"><?php 
            echo $_smarty_tpl->tpl_vars['product']->value['product_name'];
            ?>
 - <?php 
            echo smartyTranslate(array('s' => 'Customized'), $_smarty_tpl);
            ?>
</span><br />
			<?php 
            if ($_smarty_tpl->tpl_vars['product']->value['product_reference']) {
                echo smartyTranslate(array('s' => 'Reference number:'), $_smarty_tpl);
                ?>
 <?php 
                echo $_smarty_tpl->tpl_vars['product']->value['product_reference'];
                ?>
<br /><?php 
            }
            ?>
			<?php 
            if ($_smarty_tpl->tpl_vars['product']->value['product_supplier_reference']) {
                echo smartyTranslate(array('s' => 'Supplier reference:'), $_smarty_tpl);
                ?>
 <?php 
                echo $_smarty_tpl->tpl_vars['product']->value['product_supplier_reference'];
            }
            ?>
			</a>
		</td>
		<td>
			<span class="product_price_show"><?php 
            echo $_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['displayPrice'][0][0]->displayPriceSmarty(array('price' => $_smarty_tpl->tpl_vars['product_price']->value, 'currency' => intval($_smarty_tpl->tpl_vars['currency']->value->id)), $_smarty_tpl);
            ?>
</span>
			<?php 
            if ($_smarty_tpl->tpl_vars['can_edit']->value) {
                ?>
			<div class="product_price_edit" style="display:none;">
				<input type="hidden" name="product_id_order_detail" class="edit_product_id_order_detail" value="<?php 
                echo intval($_smarty_tpl->tpl_vars['product']->value['id_order_detail']);
                ?>
" />
				<div class="form-group">
					<div class="fixed-width-xl">
						<div class="input-group">
							<?php 
                if ($_smarty_tpl->tpl_vars['currency']->value->format % 2) {
                    ?>
<div class="input-group-addon"><?php 
                    echo $_smarty_tpl->tpl_vars['currency']->value->sign;
                    ?>
 <?php 
                    echo smartyTranslate(array('s' => 'tax excl.'), $_smarty_tpl);
                    ?>
</div><?php 
                }
                ?>
							<input type="text" name="product_price_tax_excl" class="edit_product_price_tax_excl edit_product_price" value="<?php 
                echo Tools::ps_round($_smarty_tpl->tpl_vars['product']->value['unit_price_tax_excl'], 2);
                ?>
" size="5" />
							<?php 
                if (!$_smarty_tpl->tpl_vars['currency']->value->format % 2) {
                    ?>
<div class="input-group-addon"><?php 
                    echo $_smarty_tpl->tpl_vars['currency']->value->sign;
                    ?>
 <?php 
                    echo smartyTranslate(array('s' => 'tax excl.'), $_smarty_tpl);
                    ?>
</div><?php 
                }
                ?>
						</div>
					</div>
					<br/>
					<div class="fixed-width-xl">
						<div class="input-group">
							<?php 
                if ($_smarty_tpl->tpl_vars['currency']->value->format % 2) {
                    ?>
<div class="input-group-addon"><?php 
                    echo $_smarty_tpl->tpl_vars['currency']->value->sign;
                    ?>
 <?php 
                    echo smartyTranslate(array('s' => 'tax incl.'), $_smarty_tpl);
                    ?>
</div><?php 
                }
                ?>
							<input type="text" name="product_price_tax_incl" class="edit_product_price_tax_incl edit_product_price" value="<?php 
                echo Tools::ps_round($_smarty_tpl->tpl_vars['product']->value['unit_price_tax_incl'], 2);
                ?>
" size="5" />
							<?php 
                if (!$_smarty_tpl->tpl_vars['currency']->value->format % 2) {
                    ?>
<div class="input-group-addon"><?php 
                    echo $_smarty_tpl->tpl_vars['currency']->value->sign;
                    ?>
 <?php 
                    echo smartyTranslate(array('s' => 'tax incl.'), $_smarty_tpl);
                    ?>
</div><?php 
                }
                ?>
						</div>
					</div>
				</div>
			</div>
			<?php 
            }
            ?>
		</td>
		<td class="productQuantity text-center"><?php 
            echo $_smarty_tpl->tpl_vars['product']->value['customizationQuantityTotal'];
            ?>
</td>
		<?php 
            if ($_smarty_tpl->tpl_vars['display_warehouse']->value) {
                ?>
<td>&nbsp;</td><?php 
            }
            ?>
		<?php 
            if ($_smarty_tpl->tpl_vars['order']->value->hasBeenPaid()) {
                ?>
<td class="productQuantity text-center"><?php 
                echo $_smarty_tpl->tpl_vars['product']->value['customizationQuantityRefunded'];
                ?>
</td><?php 
            }
            ?>
		<?php 
            if ($_smarty_tpl->tpl_vars['order']->value->hasBeenDelivered() || $_smarty_tpl->tpl_vars['order']->value->hasProductReturned()) {
                ?>
<td class="productQuantity text-center"><?php 
                echo $_smarty_tpl->tpl_vars['product']->value['customizationQuantityReturned'];
                ?>
</td><?php 
            }
            ?>
		<?php 
            if ($_smarty_tpl->tpl_vars['stock_management']->value) {
                ?>
<td class="text-center"><?php 
                echo $_smarty_tpl->tpl_vars['product']->value['current_stock'];
                ?>
</td><?php 
            }
            ?>
		<td class="total_product">
		<?php 
            if ($_smarty_tpl->tpl_vars['order']->value->getTaxCalculationMethod() == @constant('PS_TAX_EXC')) {
                ?>
			<?php 
                echo $_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['displayPrice'][0][0]->displayPriceSmarty(array('price' => Tools::ps_round($_smarty_tpl->tpl_vars['product']->value['product_price'] * $_smarty_tpl->tpl_vars['product']->value['customizationQuantityTotal'], 2), 'currency' => intval($_smarty_tpl->tpl_vars['currency']->value->id)), $_smarty_tpl);
                ?>

		<?php 
            } else {
                ?>
			<?php 
                echo $_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['displayPrice'][0][0]->displayPriceSmarty(array('price' => Tools::ps_round($_smarty_tpl->tpl_vars['product']->value['product_price_wt'] * $_smarty_tpl->tpl_vars['product']->value['customizationQuantityTotal'], 2), 'currency' => intval($_smarty_tpl->tpl_vars['currency']->value->id)), $_smarty_tpl);
                ?>

		<?php 
            }
            ?>
		</td>
		<td class="cancelQuantity standard_refund_fields current-edit" style="display:none" colspan="2">
			&nbsp;
		</td>
		<td class="edit_product_fields" colspan="2" style="display:none">&nbsp;</td>
		<td class="partial_refund_fields current-edit" style="text-align:left;display:none;"></td>
		<?php 
            if ($_smarty_tpl->tpl_vars['can_edit']->value && !$_smarty_tpl->tpl_vars['order']->value->hasBeenDelivered()) {
                ?>
			<td class="product_action text-right">
				
				<div class="btn-group">
					<button type="button" class="btn btn-default edit_product_change_link">
						<i class="icon-pencil"></i>
						<?php 
                echo smartyTranslate(array('s' => 'Edit'), $_smarty_tpl);
                ?>

					</button>
					<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
						<span class="caret"></span>
					</button>
					<ul class="dropdown-menu" role="menu">
						<li>
							<a href="#" class="delete_product_line">
								<i class="icon-trash"></i>
								<?php 
                echo smartyTranslate(array('s' => 'Delete'), $_smarty_tpl);
                ?>

							</a>
						</li>
					</ul>
				</div>
				
				<button type="button" class="btn btn-default submitProductChange" style="display: none;">
					<i class="icon-ok"></i>
					<?php 
                echo smartyTranslate(array('s' => 'Update'), $_smarty_tpl);
                ?>

				</button>
				<button type="button" class="btn btn-default cancel_product_change_link" style="display: none;">
					<i class="icon-remove"></i>
					<?php 
                echo smartyTranslate(array('s' => 'Cancel'), $_smarty_tpl);
                ?>

				</button>
			</td>
		<?php 
            }
            ?>
	</tr>
	<?php 
            $_smarty_tpl->tpl_vars['customizationPerAddress'] = new Smarty_Variable();
            $_smarty_tpl->tpl_vars['customizationPerAddress']->_loop = false;
            $_from = $_smarty_tpl->tpl_vars['product']->value['customizedDatas'];
            if (!is_array($_from) && !is_object($_from)) {
                settype($_from, 'array');
            }
            foreach ($_from as $_smarty_tpl->tpl_vars['customizationPerAddress']->key => $_smarty_tpl->tpl_vars['customizationPerAddress']->value) {
                $_smarty_tpl->tpl_vars['customizationPerAddress']->_loop = true;
                ?>
		<?php 
                $_smarty_tpl->tpl_vars['customization'] = new Smarty_Variable();
                $_smarty_tpl->tpl_vars['customization']->_loop = false;
                $_smarty_tpl->tpl_vars['customizationId'] = new Smarty_Variable();
                $_from = $_smarty_tpl->tpl_vars['customizationPerAddress']->value;
                if (!is_array($_from) && !is_object($_from)) {
                    settype($_from, 'array');
                }
                foreach ($_from as $_smarty_tpl->tpl_vars['customization']->key => $_smarty_tpl->tpl_vars['customization']->value) {
                    $_smarty_tpl->tpl_vars['customization']->_loop = true;
                    $_smarty_tpl->tpl_vars['customizationId']->value = $_smarty_tpl->tpl_vars['customization']->key;
                    ?>
			<tr class="customized customized-<?php 
                    echo intval($_smarty_tpl->tpl_vars['product']->value['id_order_detail']);
                    ?>
">
				<td colspan="2">
				<input type="hidden" class="edit_product_id_order_detail" value="<?php 
                    echo intval($_smarty_tpl->tpl_vars['product']->value['id_order_detail']);
                    ?>
" />
					<div class="form-horizontal">
						<?php 
                    $_smarty_tpl->tpl_vars['datas'] = new Smarty_Variable();
                    $_smarty_tpl->tpl_vars['datas']->_loop = false;
                    $_smarty_tpl->tpl_vars['type'] = new Smarty_Variable();
                    $_from = $_smarty_tpl->tpl_vars['customization']->value['datas'];
                    if (!is_array($_from) && !is_object($_from)) {
                        settype($_from, 'array');
                    }
                    foreach ($_from as $_smarty_tpl->tpl_vars['datas']->key => $_smarty_tpl->tpl_vars['datas']->value) {
                        $_smarty_tpl->tpl_vars['datas']->_loop = true;
                        $_smarty_tpl->tpl_vars['type']->value = $_smarty_tpl->tpl_vars['datas']->key;
                        ?>
							<?php 
                        if ($_smarty_tpl->tpl_vars['type']->value == Product::CUSTOMIZE_FILE) {
                            ?>
								<?php 
                            $_smarty_tpl->tpl_vars['data'] = new Smarty_Variable();
                            $_smarty_tpl->tpl_vars['data']->_loop = false;
                            $_from = $_smarty_tpl->tpl_vars['datas']->value;
                            if (!is_array($_from) && !is_object($_from)) {
                                settype($_from, 'array');
                            }
                            $_smarty_tpl->tpl_vars['data']->iteration = 0;
                            foreach ($_from as $_smarty_tpl->tpl_vars['data']->key => $_smarty_tpl->tpl_vars['data']->value) {
                                $_smarty_tpl->tpl_vars['data']->_loop = true;
                                $_smarty_tpl->tpl_vars['data']->iteration++;
                                ?>
									<div class="form-group">
										<span class="col-lg-4 control-label"><strong><?php 
                                if ($_smarty_tpl->tpl_vars['data']->value['name']) {
                                    echo $_smarty_tpl->tpl_vars['data']->value['name'];
                                } else {
                                    echo smartyTranslate(array('s' => 'Picture #'), $_smarty_tpl);
                                    echo $_smarty_tpl->tpl_vars['data']->iteration;
                                }
                                ?>
</strong></span>
										<div class="col-lg-8">
											<a href="displayImage.php?img=<?php 
                                echo $_smarty_tpl->tpl_vars['data']->value['value'];
                                ?>
&amp;name=<?php 
                                echo intval($_smarty_tpl->tpl_vars['order']->value->id);
                                ?>
-file<?php 
                                echo $_smarty_tpl->tpl_vars['data']->iteration;
                                ?>
" class="_blank">
												<img class="img-thumbnail" src="<?php 
                                echo @constant('_THEME_PROD_PIC_DIR_');
                                echo $_smarty_tpl->tpl_vars['data']->value['value'];
                                ?>
_small" alt=""/>
											</a>
										</div>
									</div>
								<?php 
                            }
                            ?>
							<?php 
                        } elseif ($_smarty_tpl->tpl_vars['type']->value == Product::CUSTOMIZE_TEXTFIELD) {
                            ?>
								<?php 
                            $_smarty_tpl->tpl_vars['data'] = new Smarty_Variable();
                            $_smarty_tpl->tpl_vars['data']->_loop = false;
                            $_from = $_smarty_tpl->tpl_vars['datas']->value;
                            if (!is_array($_from) && !is_object($_from)) {
                                settype($_from, 'array');
                            }
                            $_smarty_tpl->tpl_vars['data']->iteration = 0;
                            foreach ($_from as $_smarty_tpl->tpl_vars['data']->key => $_smarty_tpl->tpl_vars['data']->value) {
                                $_smarty_tpl->tpl_vars['data']->_loop = true;
                                $_smarty_tpl->tpl_vars['data']->iteration++;
                                ?>
									<div class="form-group">
										<span class="col-lg-4 control-label"><strong><?php 
                                if ($_smarty_tpl->tpl_vars['data']->value['name']) {
                                    echo smartyTranslate(array('s' => '%s', 'sprintf' => $_smarty_tpl->tpl_vars['data']->value['name']), $_smarty_tpl);
                                } else {
                                    echo smartyTranslate(array('s' => 'Text #%s', 'sprintf' => $_smarty_tpl->tpl_vars['data']->iteration), $_smarty_tpl);
                                }
                                ?>
</strong></span>
										<div class="col-lg-8">
											<p class="form-control-static"><?php 
                                echo $_smarty_tpl->tpl_vars['data']->value['value'];
                                ?>
</p>
										</div>
									</div>
								<?php 
                            }
                            ?>
							<?php 
                        }
                        ?>
						<?php 
                    }
                    ?>
					</div>
				</td>
				<td>-</td>
				<td class="productQuantity text-center">
					<span class="product_quantity_show<?php 
                    if ((int) $_smarty_tpl->tpl_vars['customization']->value['quantity'] > 1) {
                        ?>
 red bold<?php 
                    }
                    ?>
"><?php 
                    echo $_smarty_tpl->tpl_vars['customization']->value['quantity'];
                    ?>
</span>
					<?php 
                    if ($_smarty_tpl->tpl_vars['can_edit']->value) {
                        ?>
					<span class="product_quantity_edit" style="display:none;">
						<input type="text" name="product_quantity[<?php 
                        echo intval($_smarty_tpl->tpl_vars['customizationId']->value);
                        ?>
]" class="edit_product_quantity" value="<?php 
                        echo htmlentities($_smarty_tpl->tpl_vars['customization']->value['quantity']);
                        ?>
" size="2" />
					</span>
					<?php 
                    }
                    ?>
				</td>
				<?php 
                    if ($_smarty_tpl->tpl_vars['display_warehouse']->value) {
                        ?>
<td>&nbsp;</td><?php 
                    }
                    ?>
				<?php 
                    if ($_smarty_tpl->tpl_vars['order']->value->hasBeenPaid()) {
                        ?>
				<td class="text-center">
					<?php 
                        if (!empty($_smarty_tpl->tpl_vars['product']->value['amount_refund'])) {
                            ?>
					<?php 
                            echo smartyTranslate(array('s' => '%s (%s refund)', 'sprintf' => array($_smarty_tpl->tpl_vars['customization']->value['quantity_refunded'], $_smarty_tpl->tpl_vars['product']->value['amount_refund'])), $_smarty_tpl);
                            ?>

					<?php 
                        }
                        ?>
					<input type="hidden" value="<?php 
                        echo $_smarty_tpl->tpl_vars['product']->value['quantity_refundable'];
                        ?>
" class="partialRefundProductQuantity" />
					<input type="hidden" value="<?php 
                        echo Tools::ps_round($_smarty_tpl->tpl_vars['product_price']->value, 2) * ($_smarty_tpl->tpl_vars['product']->value['product_quantity'] - $_smarty_tpl->tpl_vars['product']->value['customizationQuantityTotal']);
                        ?>
" class="partialRefundProductAmount" />
				</td>
				<?php 
                    }
                    ?>
				<?php 
                    if ($_smarty_tpl->tpl_vars['order']->value->hasBeenDelivered()) {
                        ?>
<td class="text-center"><?php 
                        echo $_smarty_tpl->tpl_vars['customization']->value['quantity_returned'];
                        ?>
</td><?php 
                    }
                    ?>
				<td class="text-center">-</td>
				<td class="total_product">
					<?php 
                    if ($_smarty_tpl->tpl_vars['order']->value->getTaxCalculationMethod() == @constant('PS_TAX_EXC')) {
                        ?>
						<?php 
                        echo $_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['displayPrice'][0][0]->displayPriceSmarty(array('price' => Tools::ps_round($_smarty_tpl->tpl_vars['product']->value['product_price'] * $_smarty_tpl->tpl_vars['customization']->value['quantity'], 2), 'currency' => intval($_smarty_tpl->tpl_vars['currency']->value->id)), $_smarty_tpl);
                        ?>

					<?php 
                    } else {
                        ?>
						<?php 
                        echo $_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['displayPrice'][0][0]->displayPriceSmarty(array('price' => Tools::ps_round($_smarty_tpl->tpl_vars['product']->value['product_price_wt'] * $_smarty_tpl->tpl_vars['customization']->value['quantity'], 2), 'currency' => intval($_smarty_tpl->tpl_vars['currency']->value->id)), $_smarty_tpl);
                        ?>

					<?php 
                    }
                    ?>
				</td>
				<td class="cancelCheck standard_refund_fields current-edit" style="display:none">
					<input type="hidden" name="totalQtyReturn" id="totalQtyReturn" value="<?php 
                    echo intval($_smarty_tpl->tpl_vars['customization']->value['quantity_returned']);
                    ?>
" />
					<input type="hidden" name="totalQty" id="totalQty" value="<?php 
                    echo intval($_smarty_tpl->tpl_vars['customization']->value['quantity']);
                    ?>
" />
					<input type="hidden" name="productName" id="productName" value="<?php 
                    echo $_smarty_tpl->tpl_vars['product']->value['product_name'];
                    ?>
" />
					<?php 
                    if ((!$_smarty_tpl->tpl_vars['order']->value->hasBeenDelivered() || Configuration::get('PS_ORDER_RETURN')) && (int) $_smarty_tpl->tpl_vars['customization']->value['quantity_returned'] < (int) $_smarty_tpl->tpl_vars['customization']->value['quantity']) {
                        ?>
						<input type="checkbox" name="id_customization[<?php 
                        echo intval($_smarty_tpl->tpl_vars['customizationId']->value);
                        ?>
]" id="id_customization[<?php 
                        echo intval($_smarty_tpl->tpl_vars['customizationId']->value);
                        ?>
]" value="<?php 
                        echo intval($_smarty_tpl->tpl_vars['product']->value['id_order_detail']);
                        ?>
" onchange="setCancelQuantity(this, <?php 
                        echo intval($_smarty_tpl->tpl_vars['customizationId']->value);
                        ?>
, <?php 
                        echo $_smarty_tpl->tpl_vars['customization']->value['quantity'] - $_smarty_tpl->tpl_vars['product']->value['customizationQuantityTotal'] - $_smarty_tpl->tpl_vars['product']->value['product_quantity_reinjected'];
                        ?>
)" <?php 
                        if ($_smarty_tpl->tpl_vars['product']->value['product_quantity_return'] + $_smarty_tpl->tpl_vars['product']->value['product_quantity_refunded'] >= $_smarty_tpl->tpl_vars['product']->value['product_quantity']) {
                            ?>
disabled="disabled" <?php 
                        }
                        ?>
/>
					<?php 
                    } else {
                        ?>
					--
				<?php 
                    }
                    ?>
				</td>
				<td class="cancelQuantity standard_refund_fields current-edit" style="display:none">
				<?php 
                    if ($_smarty_tpl->tpl_vars['customization']->value['quantity_returned'] + $_smarty_tpl->tpl_vars['customization']->value['quantity_refunded'] >= $_smarty_tpl->tpl_vars['customization']->value['quantity']) {
                        ?>
					<input type="hidden" name="cancelCustomizationQuantity[<?php 
                        echo intval($_smarty_tpl->tpl_vars['customizationId']->value);
                        ?>
]" value="0" />
				<?php 
                    } elseif (!$_smarty_tpl->tpl_vars['order']->value->hasBeenDelivered() || Configuration::get('PS_ORDER_RETURN')) {
                        ?>
					<input type="text" id="cancelQuantity_<?php 
                        echo intval($_smarty_tpl->tpl_vars['customizationId']->value);
                        ?>
" name="cancelCustomizationQuantity[<?php 
                        echo intval($_smarty_tpl->tpl_vars['customizationId']->value);
                        ?>
]" size="2" onclick="selectCheckbox(this);" value="" />0/<?php 
                        echo $_smarty_tpl->tpl_vars['customization']->value['quantity'] - $_smarty_tpl->tpl_vars['customization']->value['quantity_refunded'];
                        ?>

				<?php 
                    }
                    ?>
				</td>
				<td class="partial_refund_fields current-edit" style="display:none; width: 250px;">
					<?php 
                    if ($_smarty_tpl->tpl_vars['product']->value['quantity_refundable'] > 0) {
                        ?>
					<?php 
                        if ($_smarty_tpl->tpl_vars['order']->value->getTaxCalculationMethod() == @constant('PS_TAX_EXC')) {
                            ?>
						<?php 
                            $_smarty_tpl->tpl_vars['amount_refundable'] = new Smarty_variable($_smarty_tpl->tpl_vars['product']->value['amount_refundable'], null, 0);
                            ?>
					<?php 
                        } else {
                            ?>
						<?php 
                            $_smarty_tpl->tpl_vars['amount_refundable'] = new Smarty_variable($_smarty_tpl->tpl_vars['product']->value['amount_refundable_tax_incl'], null, 0);
                            ?>
					<?php 
                        }
                        ?>
					<div class="form-group">
						<div class="<?php 
                        if ($_smarty_tpl->tpl_vars['product']->value['amount_refundable'] > 0) {
                            ?>
col-lg-4<?php 
                        } else {
                            ?>
col-lg-12<?php 
                        }
                        ?>
">
							<label class="control-label">
								<?php 
                        echo smartyTranslate(array('s' => 'Quantity:'), $_smarty_tpl);
                        ?>

							</label>
							<div class="input-group">
								<input onchange="checkPartialRefundProductQuantity(this)" type="text" name="partialRefundProductQuantity[<?php 
                        echo intval($_smarty_tpl->tpl_vars['product']->value['id_order_detail']);
                        ?>
]" value="<?php 
                        if ($_smarty_tpl->tpl_vars['customization']->value['quantity'] - $_smarty_tpl->tpl_vars['customization']->value['quantity_refunded'] > 0) {
                            ?>
1<?php 
                        } else {
                            ?>
0<?php 
                        }
                        ?>
" />
								<div class="input-group-addon">/ <?php 
                        echo $_smarty_tpl->tpl_vars['product']->value['quantity_refundable'];
                        ?>
</div>
							</div>
						</div>
						<div class="<?php 
                        if ($_smarty_tpl->tpl_vars['product']->value['quantity_refundable'] > 0) {
                            ?>
col-lg-8<?php 
                        } else {
                            ?>
col-lg-12<?php 
                        }
                        ?>
">
							<label class="control-label">
								<span class="title_box "><?php 
                        echo smartyTranslate(array('s' => 'Amount:'), $_smarty_tpl);
                        ?>
</span>
								<small class="text-muted">(<?php 
                        echo Smarty::$_smarty_vars['capture']['TaxMethod'];
                        ?>
)</small>
							</label>
							<div class="input-group">
								<?php 
                        if ($_smarty_tpl->tpl_vars['currency']->value->format % 2) {
                            ?>
<div class="input-group-addon"><?php 
                            echo $_smarty_tpl->tpl_vars['currency']->value->sign;
                            ?>
</div><?php 
                        }
                        ?>
								<input onchange="checkPartialRefundProductAmount(this)" type="text" name="partialRefundProduct[<?php 
                        echo intval($_smarty_tpl->tpl_vars['product']->value['id_order_detail']);
                        ?>
]" />
								<?php 
                        if (!$_smarty_tpl->tpl_vars['currency']->value->format % 2) {
                            ?>
<div class="input-group-addon"><?php 
                            echo $_smarty_tpl->tpl_vars['currency']->value->sign;
                            ?>
</div><?php 
                        }
                        ?>
							</div>
							<p class="help-block"><i class="icon-warning-sign"></i> <?php 
                        echo smartyTranslate(array('s' => '(Max %s %s)', 'sprintf' => array(Tools::displayPrice(Tools::ps_round($_smarty_tpl->tpl_vars['amount_refundable']->value, 2), $_smarty_tpl->tpl_vars['currency']->value->id), Smarty::$_smarty_vars['capture']['TaxMethod'])), $_smarty_tpl);
                        ?>
</p>
						</div>
					</div>
					<?php 
                    }
                    ?>
				</td>
				<?php 
                    if ($_smarty_tpl->tpl_vars['can_edit']->value && !$_smarty_tpl->tpl_vars['order']->value->hasBeenDelivered()) {
                        ?>
					<td class="edit_product_fields" colspan="2" style="display:none"></td>
					<td class="product_action" style="text-align:right"></td>
				<?php 
                    }
                    ?>
			</tr>
		<?php 
                }
                ?>
	<?php 
            }
        }
    }
Exemplo n.º 18
0
 public function hookPayment($params)
 {
     if ($this->_allowToWork == false) {
         return;
     }
     // One page Checkout cause problem with event and document.write use by twenga script
     // (page completely deleted
     if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) {
         return;
     }
     $customer = new Customer($params['cart']->id_customer);
     $currency = new Currency($params['cart']->id_currency);
     $address = $customer->getAddresses($params['cart']->id_lang);
     $address = $address[0];
     // for 1.3 compatibility
     $type_both = 3;
     $type_only_shipping = 5;
     /*		const ONLY_PRODUCTS = 1;
     		const ONLY_DISCOUNTS = 2;
     		const BOTH = 3;
     		const BOTH_WITHOUT_SHIPPING = 4;
     		const ONLY_SHIPPING = 5;
     		const ONLY_WRAPPING = 6;
     		const ONLY_PRODUCTS_WITHOUT_SHIPPING = 7;
     		*/
     $tva = $params['cart']->getOrderTotal(true, $type_both) - $params['cart']->getOrderTotal(false, $type_both);
     $tax = $tva * 100 / $params['cart']->getOrderTotal(true, $type_both);
     $params_to_twenga = array();
     // @todo delete or not ??
     //		$params_to_twenga['user_id'] = $customer->id;
     //		$params_to_twenga['cli_email'] = $customer->email;
     $params_to_twenga['total_ht'] = $params['cart']->getOrderTotal(false, Twenga::ONLY_PRODUCTS_WITHOUT_SHIPPING);
     $params_to_twenga['basket_id'] = $params['cart']->id;
     $params_to_twenga['currency'] = $currency->iso_code;
     $params_to_twenga['total_ttc'] = $params['cart']->getOrderTotal(true, Twenga::BOTH);
     $params_to_twenga['shipping'] = $params['cart']->getOrderTotal(true, Twenga::ONLY_SHIPPING);
     $params_to_twenga['tax'] = Tools::ps_round($tax, 2);
     $params_to_twenga['tva'] = $tva;
     $params_to_twenga['cli_firstname'] = $customer->firstname;
     $params_to_twenga['cli_lastname'] = $customer->lastname;
     $params_to_twenga['cli_city'] = $address['city'];
     $params_to_twenga['cli_state'] = $address['state'];
     $params_to_twenga['cli_country'] = $address['country'];
     $params_to_twenga['items'] = array();
     foreach ($params['cart']->getProducts() as $product) {
         $arr_item = array();
         if ($product['total'] != '') {
             $arr_item['total_ht'] = (double) $product['total'];
         }
         if ($product['cart_quantity'] != '') {
             $arr_item['quantity'] = (int) $product['cart_quantity'];
         }
         if ($product['reference'] != '') {
             $arr_item['sku'] = (string) $product['reference'];
         }
         if ($product['name'] != '') {
             $arr_item['name'] = (string) $product['name'];
         }
         if ($product['category']) {
             $arr_item['category_name'] = (string) $product['category'];
         }
         $params_to_twenga['items'][] = $arr_item;
     }
     $params_to_twenga = array_filter($params_to_twenga);
     try {
         // twenga don't saved double orders with the same id,
         // so don't need to use TwengaObj::orderExist() method.
         $tracking_code = self::$obj_twenga->getTrackingScript($params_to_twenga);
         return $tracking_code;
     } catch (TwengaFieldsException $e) {
         return $this->l('Error occurred when params passed in Twenga API') . ' : <br />' . $e->getMessage();
     } catch (Exception $e) {
         return $e->getMessage();
     }
 }
Exemplo n.º 19
0
 public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null, $id_zone = null)
 {
     if (!Configuration::get('LEGAL_SHIPTAXMETH')) {
         return parent::getPackageShippingCost($id_carrier, $use_tax, $default_country, $product_list, $id_zone);
     }
     if ($this->isVirtualCart()) {
         return 0;
     }
     if (!$default_country) {
         $default_country = Context::getContext()->country;
     }
     if (!is_null($product_list)) {
         foreach ($product_list as $key => $value) {
             if ($value['is_virtual'] == 1) {
                 unset($product_list[$key]);
             }
         }
     }
     $complete_product_list = $this->getProducts();
     if (is_null($product_list)) {
         $products = $complete_product_list;
     } else {
         $products = $product_list;
     }
     if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
         $address_id = (int) $this->id_address_invoice;
     } elseif (count($product_list)) {
         $prod = current($product_list);
         $address_id = (int) $prod['id_address_delivery'];
     } else {
         $address_id = null;
     }
     if (!Address::addressExists($address_id)) {
         $address_id = null;
     }
     $cache_id = 'getPackageShippingCost_' . (int) $this->id . '_' . (int) $address_id . '_' . (int) $id_carrier . '_' . (int) $use_tax . '_' . (int) $default_country->id;
     if ($products) {
         foreach ($products as $product) {
             $cache_id .= '_' . (int) $product['id_product'] . '_' . (int) $product['id_product_attribute'];
         }
     }
     if (Cache::isStored($cache_id)) {
         return Cache::retrieve($cache_id);
     }
     // Order total in default currency without fees
     $order_total = $this->getOrderTotal(true, Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING, $product_list);
     // Start with shipping cost at 0
     $shipping_cost = 0;
     // If no product added, return 0
     if (!count($products)) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     if (!isset($id_zone)) {
         // Get id zone
         if (!$this->isMultiAddressDelivery() && isset($this->id_address_delivery) && $this->id_address_delivery && Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
             $id_zone = Address::getZoneById((int) $this->id_address_delivery);
         } else {
             if (!Validate::isLoadedObject($default_country)) {
                 $default_country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
             }
             $id_zone = (int) $default_country->id_zone;
         }
     }
     if ($id_carrier && !$this->isCarrierInRange((int) $id_carrier, (int) $id_zone)) {
         $id_carrier = '';
     }
     if (empty($id_carrier) && $this->isCarrierInRange((int) Configuration::get('PS_CARRIER_DEFAULT'), (int) $id_zone)) {
         $id_carrier = (int) Configuration::get('PS_CARRIER_DEFAULT');
     }
     $total_package_without_shipping_tax_inc = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list);
     if (empty($id_carrier)) {
         if ((int) $this->id_customer) {
             $customer = new Customer((int) $this->id_customer);
             $result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone, $customer->getGroups());
             unset($customer);
         } else {
             $result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone);
         }
         foreach ($result as $k => $row) {
             if ($row['id_carrier'] == Configuration::get('PS_CARRIER_DEFAULT')) {
                 continue;
             }
             if (!isset(self::$_carriers[$row['id_carrier']])) {
                 self::$_carriers[$row['id_carrier']] = new Carrier((int) $row['id_carrier']);
             }
             $carrier = self::$_carriers[$row['id_carrier']];
             // Get only carriers that are compliant with shipping method
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight((int) $id_zone) === false || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice((int) $id_zone) === false) {
                 unset($result[$k]);
                 continue;
             }
             // If out-of-range behavior carrier is set on "Desactivate carrier"
             if ($row['range_behavior']) {
                 $check_delivery_price_by_weight = Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->getTotalWeight(), (int) $id_zone);
                 $total_order = $total_package_without_shipping_tax_inc;
                 $check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $total_order, (int) $id_zone, (int) $this->id_currency);
                 // Get only carriers that have a range compatible with cart
                 if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !$check_delivery_price_by_weight || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !$check_delivery_price_by_price) {
                     unset($result[$k]);
                     continue;
                 }
             }
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $shipping = $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), (int) $id_zone);
             } else {
                 $shipping = $carrier->getDeliveryPriceByPrice($order_total, (int) $id_zone, (int) $this->id_currency);
             }
             if (!isset($min_shipping_price)) {
                 $min_shipping_price = $shipping;
             }
             if ($shipping <= $min_shipping_price) {
                 $id_carrier = (int) $row['id_carrier'];
                 $min_shipping_price = $shipping;
             }
         }
     }
     if (empty($id_carrier)) {
         $id_carrier = Configuration::get('PS_CARRIER_DEFAULT');
     }
     if (!isset(self::$_carriers[$id_carrier])) {
         self::$_carriers[$id_carrier] = new Carrier((int) $id_carrier, Configuration::get('PS_LANG_DEFAULT'));
     }
     $carrier = self::$_carriers[$id_carrier];
     // No valid Carrier or $id_carrier <= 0 ?
     if (!Validate::isLoadedObject($carrier)) {
         Cache::store($cache_id, 0);
         return 0;
     }
     if (!$carrier->active) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     // Free fees if free carrier
     if ($carrier->is_free == 1) {
         Cache::store($cache_id, 0);
         return 0;
     }
     // Select carrier tax
     if ($use_tax && !Tax::excludeTaxeOption()) {
         $address = Address::initialize((int) $address_id);
         $carrier_tax = $carrier->getTaxesRate($address);
     }
     $configuration = Configuration::getMultiple(array('PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT'));
     // Free fees
     $free_fees_price = 0;
     if (isset($configuration['PS_SHIPPING_FREE_PRICE'])) {
         $free_fees_price = Tools::convertPrice((double) $configuration['PS_SHIPPING_FREE_PRICE'], Currency::getCurrencyInstance((int) $this->id_currency));
     }
     $orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, null, null, false);
     if ($orderTotalwithDiscounts >= (double) $free_fees_price && (double) $free_fees_price > 0) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) && $this->getTotalWeight() >= (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] && (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] > 0) {
         Cache::store($cache_id, $shipping_cost);
         return $shipping_cost;
     }
     // Get shipping cost using correct method
     if ($carrier->range_behavior) {
         if (!isset($id_zone)) {
             // Get id zone
             if (isset($this->id_address_delivery) && $this->id_address_delivery && Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
                 $id_zone = Address::getZoneById((int) $this->id_address_delivery);
             } else {
                 $id_zone = (int) $default_country->id_zone;
             }
         }
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !Carrier::checkDeliveryPriceByWeight($carrier->id, $this->getTotalWeight(), (int) $id_zone) || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !Carrier::checkDeliveryPriceByPrice($carrier->id, $total_package_without_shipping_tax_inc, $id_zone, (int) $this->id_currency)) {
             $shipping_cost += 0;
         } else {
             if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
                 $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $id_zone);
             } else {
                 // by price
                 $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency);
             }
         }
     } else {
         if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
             $shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $id_zone);
         } else {
             $shipping_cost += $carrier->getDeliveryPriceByPrice($order_total, $id_zone, (int) $this->id_currency);
         }
     }
     // Adding handling charges
     if (isset($configuration['PS_SHIPPING_HANDLING']) && $carrier->shipping_handling) {
         $shipping_cost += (double) $configuration['PS_SHIPPING_HANDLING'];
     }
     // Additional Shipping Cost per product
     foreach ($products as $product) {
         if (!$product['is_virtual']) {
             $shipping_cost += $product['additional_shipping_cost'] * $product['cart_quantity'];
         }
     }
     $shipping_cost = Tools::convertPrice($shipping_cost, Currency::getCurrencyInstance((int) $this->id_currency));
     //get external shipping cost from module
     if ($carrier->shipping_external) {
         $module_name = $carrier->external_module_name;
         $module = Module::getInstanceByName($module_name);
         if (Validate::isLoadedObject($module)) {
             if (array_key_exists('id_carrier', $module)) {
                 $module->id_carrier = $carrier->id;
             }
             if ($carrier->need_range) {
                 if (method_exists($module, 'getPackageShippingCost')) {
                     $shipping_cost = $module->getPackageShippingCost($this, $shipping_cost, $products);
                 } else {
                     $shipping_cost = $module->getOrderShippingCost($this, $shipping_cost);
                 }
             } else {
                 $shipping_cost = $module->getOrderShippingCostExternal($this);
             }
             // Check if carrier is available
             if ($shipping_cost === false) {
                 Cache::store($cache_id, false);
                 return false;
             }
         } else {
             Cache::store($cache_id, false);
             return false;
         }
     }
     $shipping_cost = (double) Tools::ps_round((double) $shipping_cost, 2);
     Cache::store($cache_id, $shipping_cost);
     return $shipping_cost;
 }
Exemplo n.º 20
0
    /**
     * Returns the ecotax taxes breakdown
     *
     * @since 1.5
     * @return array
     */
    public function getEcoTaxTaxesBreakdown()
    {
        $result = Db::getInstance()->executeS('
		SELECT `ecotax_tax_rate` as `rate`, SUM(`ecotax` * `product_quantity`) as `ecotax_tax_excl`, SUM(`ecotax` * `product_quantity`) as `ecotax_tax_incl`
		FROM `' . _DB_PREFIX_ . 'order_detail`
		WHERE `id_order` = ' . (int) $this->id_order . '
		AND `id_order_invoice` = ' . (int) $this->id . '
		GROUP BY `ecotax_tax_rate`');
        $taxes = array();
        foreach ($result as $row) {
            if ($row['ecotax_tax_excl'] > 0) {
                $row['ecotax_tax_incl'] = Tools::ps_round($row['ecotax_tax_excl'] + $row['ecotax_tax_excl'] * $row['rate'] / 100, _PS_PRICE_DISPLAY_PRECISION_);
                $row['ecotax_tax_excl'] = Tools::ps_round($row['ecotax_tax_excl'], _PS_PRICE_DISPLAY_PRECISION_);
                $taxes[] = $row;
            }
        }
        return $taxes;
    }
    function content_564b5c4ce69b44_84864285($_smarty_tpl)
    {
        ?>

<input type="hidden" name="supplier_loaded" value="1">
<?php 
        if (isset($_smarty_tpl->tpl_vars['product']->value->id)) {
            ?>
<div id="product-suppliers" class="panel product-tab">
	<input type="hidden" name="submitted_tabs[]" value="Suppliers" />
	<h3><?php 
            echo smartyTranslate(array('s' => 'Suppliers of the current product'), $_smarty_tpl);
            ?>
</h3>
	<div class="alert alert-info">
		<?php 
            echo smartyTranslate(array('s' => 'This interface allows you to specify the suppliers of the current product and eventually its combinations.'), $_smarty_tpl);
            ?>
<br />
		<?php 
            echo smartyTranslate(array('s' => 'It is also possible to specify supplier references according to previously associated suppliers.'), $_smarty_tpl);
            ?>
<br />
		<br />
		<?php 
            echo smartyTranslate(array('s' => 'When using the advanced stock management tool (see Preferences/Products), the values you define (prices, references) will be used in supply orders.'), $_smarty_tpl);
            ?>

	</div>
	<label><?php 
            echo smartyTranslate(array('s' => 'Please choose the suppliers associated with this product. Please select a default supplier, as well.'), $_smarty_tpl);
            ?>
</label>
	<table class="table">
		<thead>
			<tr>
				<th class="fixed-width-xs"><span class="title_box"><?php 
            echo smartyTranslate(array('s' => 'Selected'), $_smarty_tpl);
            ?>
</span></th>
				<th><span class="title_box"><?php 
            echo smartyTranslate(array('s' => 'Supplier Name'), $_smarty_tpl);
            ?>
</span></th>
				<th class="fixed-width-xs"><span class="title_box"><?php 
            echo smartyTranslate(array('s' => 'Default'), $_smarty_tpl);
            ?>
</span></th>
			</tr>
		</thead>
		<tbody>
		<?php 
            $_smarty_tpl->tpl_vars['supplier'] = new Smarty_Variable();
            $_smarty_tpl->tpl_vars['supplier']->_loop = false;
            $_from = $_smarty_tpl->tpl_vars['suppliers']->value;
            if (!is_array($_from) && !is_object($_from)) {
                settype($_from, 'array');
            }
            foreach ($_from as $_smarty_tpl->tpl_vars['supplier']->key => $_smarty_tpl->tpl_vars['supplier']->value) {
                $_smarty_tpl->tpl_vars['supplier']->_loop = true;
                ?>
			<tr>
				<td><input type="checkbox" class="supplierCheckBox" name="check_supplier_<?php 
                echo $_smarty_tpl->tpl_vars['supplier']->value['id_supplier'];
                ?>
" <?php 
                if ($_smarty_tpl->tpl_vars['supplier']->value['is_selected'] == true) {
                    ?>
checked="checked"<?php 
                }
                ?>
 value="<?php 
                echo $_smarty_tpl->tpl_vars['supplier']->value['id_supplier'];
                ?>
" /></td>
				<td><?php 
                echo $_smarty_tpl->tpl_vars['supplier']->value['name'];
                ?>
</td>
				<td><input type="radio" id="default_supplier_<?php 
                echo $_smarty_tpl->tpl_vars['supplier']->value['id_supplier'];
                ?>
" name="default_supplier" value="<?php 
                echo $_smarty_tpl->tpl_vars['supplier']->value['id_supplier'];
                ?>
" <?php 
                if ($_smarty_tpl->tpl_vars['supplier']->value['is_selected'] == false) {
                    ?>
disabled="disabled"<?php 
                }
                ?>
 <?php 
                if ($_smarty_tpl->tpl_vars['supplier']->value['is_default'] == true) {
                    ?>
checked="checked"<?php 
                }
                ?>
 /></td>
			</tr>
		<?php 
            }
            ?>
		</tbody>
	</table>
	<a class="btn btn-link bt-icon confirm_leave" href="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['link']->value->getAdminLink('AdminSuppliers'), ENT_QUOTES, 'UTF-8', true);
            ?>
&addsupplier">
		<i class="icon-plus"></i> <?php 
            echo smartyTranslate(array('s' => 'Create a new supplier'), $_smarty_tpl);
            ?>
 <i class="icon-external-link-sign"></i>
	</a>
	<div class="panel-footer">
		<a href="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['link']->value->getAdminLink('AdminProducts'), ENT_QUOTES, 'UTF-8', true);
            if (isset($_REQUEST['page']) && $_REQUEST['page'] > 1) {
                ?>
&amp;submitFilterproduct=<?php 
                echo intval($_REQUEST['page']);
            }
            ?>
" class="btn btn-default"><i class="process-icon-cancel"></i> <?php 
            echo smartyTranslate(array('s' => 'Cancel'), $_smarty_tpl);
            ?>
</a>
		<button type="submit" name="submitAddproduct" class="btn btn-default pull-right" disabled="disabled"><i class="process-icon-loading"></i> <?php 
            echo smartyTranslate(array('s' => 'Save'), $_smarty_tpl);
            ?>
</button>
		<button type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right" disabled="disabled"><i class="process-icon-loading"></i> <?php 
            echo smartyTranslate(array('s' => 'Save and stay'), $_smarty_tpl);
            ?>
</button>
	</div>
</div>
<div class="panel">
	<h3><?php 
            echo smartyTranslate(array('s' => 'Supplier reference(s)'), $_smarty_tpl);
            ?>
</h3>
	<div class="alert alert-info">
		<?php 
            if (count($_smarty_tpl->tpl_vars['associated_suppliers']->value) == 0) {
                ?>
			<?php 
                echo smartyTranslate(array('s' => 'You must specify the suppliers associated with this product. You must also select the default product supplier before setting references.'), $_smarty_tpl);
                ?>

		<?php 
            } else {
                ?>
			<?php 
                echo smartyTranslate(array('s' => 'You can specify product reference(s) for each associated supplier.'), $_smarty_tpl);
                ?>

		<?php 
            }
            ?>
		<?php 
            echo smartyTranslate(array('s' => 'Click "Save and Stay" after changing selected suppliers to display the associated product references.'), $_smarty_tpl);
            ?>

	</div>
	<div class="panel-group" id="accordion-supplier">
		<?php 
            $_smarty_tpl->tpl_vars['supplier'] = new Smarty_Variable();
            $_smarty_tpl->tpl_vars['supplier']->_loop = false;
            $_from = $_smarty_tpl->tpl_vars['associated_suppliers']->value;
            if (!is_array($_from) && !is_object($_from)) {
                settype($_from, 'array');
            }
            foreach ($_from as $_smarty_tpl->tpl_vars['supplier']->key => $_smarty_tpl->tpl_vars['supplier']->value) {
                $_smarty_tpl->tpl_vars['supplier']->_loop = true;
                ?>
		<div class="panel">
			<div class="panel-heading">
				<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion-supplier" href="#supplier-<?php 
                echo $_smarty_tpl->tpl_vars['supplier']->value->id;
                ?>
"><?php 
                if (isset($_smarty_tpl->tpl_vars['supplier']->value->name)) {
                    echo $_smarty_tpl->tpl_vars['supplier']->value->name;
                }
                ?>
</a>
			</div>
			<div id="supplier-<?php 
                echo $_smarty_tpl->tpl_vars['supplier']->value->id;
                ?>
">
				<div class="panel-body">
					<table class="table">
						<thead>
							<tr>
								<th><span class="title_box"><?php 
                echo smartyTranslate(array('s' => 'Product name'), $_smarty_tpl);
                ?>
</span></th>
								<th><span class="title_box"><?php 
                echo smartyTranslate(array('s' => 'Supplier reference'), $_smarty_tpl);
                ?>
</span></th>
								<th><span class="title_box"><?php 
                echo smartyTranslate(array('s' => 'Unit price tax excluded'), $_smarty_tpl);
                ?>
</span></th>
								<th><span class="title_box"><?php 
                echo smartyTranslate(array('s' => 'Unit price currency'), $_smarty_tpl);
                ?>
</span></th>
							</tr>
						</thead>
						<tbody>
						<?php 
                $_smarty_tpl->tpl_vars['attribute'] = new Smarty_Variable();
                $_smarty_tpl->tpl_vars['attribute']->_loop = false;
                $_smarty_tpl->tpl_vars['index'] = new Smarty_Variable();
                $_from = $_smarty_tpl->tpl_vars['attributes']->value;
                if (!is_array($_from) && !is_object($_from)) {
                    settype($_from, 'array');
                }
                foreach ($_from as $_smarty_tpl->tpl_vars['attribute']->key => $_smarty_tpl->tpl_vars['attribute']->value) {
                    $_smarty_tpl->tpl_vars['attribute']->_loop = true;
                    $_smarty_tpl->tpl_vars['index']->value = $_smarty_tpl->tpl_vars['attribute']->key;
                    ?>
							<?php 
                    $_smarty_tpl->tpl_vars['reference'] = new Smarty_variable('', null, 0);
                    ?>
							<?php 
                    $_smarty_tpl->tpl_vars['price_te'] = new Smarty_variable('', null, 0);
                    ?>
							<?php 
                    $_smarty_tpl->tpl_vars['id_currency'] = new Smarty_variable($_smarty_tpl->tpl_vars['id_default_currency']->value, null, 0);
                    ?>
							<?php 
                    $_smarty_tpl->tpl_vars['asc'] = new Smarty_Variable();
                    $_smarty_tpl->tpl_vars['asc']->_loop = false;
                    $_from = $_smarty_tpl->tpl_vars['associated_suppliers_collection']->value;
                    if (!is_array($_from) && !is_object($_from)) {
                        settype($_from, 'array');
                    }
                    foreach ($_from as $_smarty_tpl->tpl_vars['asc']->key => $_smarty_tpl->tpl_vars['asc']->value) {
                        $_smarty_tpl->tpl_vars['asc']->_loop = true;
                        ?>
								<?php 
                        if ($_smarty_tpl->tpl_vars['asc']->value->id_product == $_smarty_tpl->tpl_vars['attribute']->value['id_product'] && $_smarty_tpl->tpl_vars['asc']->value->id_product_attribute == $_smarty_tpl->tpl_vars['attribute']->value['id_product_attribute'] && $_smarty_tpl->tpl_vars['asc']->value->id_supplier == $_smarty_tpl->tpl_vars['supplier']->value->id_supplier) {
                            ?>
									<?php 
                            $_smarty_tpl->tpl_vars['reference'] = new Smarty_variable($_smarty_tpl->tpl_vars['asc']->value->product_supplier_reference, null, 0);
                            ?>
									<?php 
                            $_smarty_tpl->tpl_vars['price_te'] = new Smarty_variable(Tools::ps_round($_smarty_tpl->tpl_vars['asc']->value->product_supplier_price_te, 2), null, 0);
                            ?>
									<?php 
                            if ($_smarty_tpl->tpl_vars['asc']->value->id_currency) {
                                ?>
										<?php 
                                $_smarty_tpl->tpl_vars['id_currency'] = new Smarty_variable($_smarty_tpl->tpl_vars['asc']->value->id_currency, null, 0);
                                ?>
									<?php 
                            }
                            ?>
								<?php 
                        }
                        ?>
							<?php 
                    }
                    ?>
							<tr <?php 
                    if (1 & $_smarty_tpl->tpl_vars['index']->value) {
                        ?>
class="alt_row"<?php 
                    }
                    ?>
>
								<td><?php 
                    echo $_smarty_tpl->tpl_vars['product_designation']->value[$_smarty_tpl->tpl_vars['attribute']->value['id_product_attribute']];
                    ?>
</td>
								<td>
									<input type="text" value="<?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['reference']->value, ENT_QUOTES, 'UTF-8', true);
                    ?>
" name="supplier_reference_<?php 
                    echo $_smarty_tpl->tpl_vars['attribute']->value['id_product'];
                    ?>
_<?php 
                    echo $_smarty_tpl->tpl_vars['attribute']->value['id_product_attribute'];
                    ?>
_<?php 
                    echo $_smarty_tpl->tpl_vars['supplier']->value->id_supplier;
                    ?>
" />
								</td>
								<td>
									<input type="text" value="<?php 
                    echo htmlentities($_smarty_tpl->tpl_vars['price_te']->value);
                    ?>
" name="product_price_<?php 
                    echo $_smarty_tpl->tpl_vars['attribute']->value['id_product'];
                    ?>
_<?php 
                    echo $_smarty_tpl->tpl_vars['attribute']->value['id_product_attribute'];
                    ?>
_<?php 
                    echo $_smarty_tpl->tpl_vars['supplier']->value->id_supplier;
                    ?>
" />
								</td>
								<td>
									<select name="product_price_currency_<?php 
                    echo $_smarty_tpl->tpl_vars['attribute']->value['id_product'];
                    ?>
_<?php 
                    echo $_smarty_tpl->tpl_vars['attribute']->value['id_product_attribute'];
                    ?>
_<?php 
                    echo $_smarty_tpl->tpl_vars['supplier']->value->id_supplier;
                    ?>
">
										<?php 
                    $_smarty_tpl->tpl_vars['currency'] = new Smarty_Variable();
                    $_smarty_tpl->tpl_vars['currency']->_loop = false;
                    $_from = $_smarty_tpl->tpl_vars['currencies']->value;
                    if (!is_array($_from) && !is_object($_from)) {
                        settype($_from, 'array');
                    }
                    foreach ($_from as $_smarty_tpl->tpl_vars['currency']->key => $_smarty_tpl->tpl_vars['currency']->value) {
                        $_smarty_tpl->tpl_vars['currency']->_loop = true;
                        ?>
											<option value="<?php 
                        echo $_smarty_tpl->tpl_vars['currency']->value['id_currency'];
                        ?>
"
												<?php 
                        if ($_smarty_tpl->tpl_vars['currency']->value['id_currency'] == $_smarty_tpl->tpl_vars['id_currency']->value) {
                            ?>
selected="selected"<?php 
                        }
                        ?>
											><?php 
                        echo $_smarty_tpl->tpl_vars['currency']->value['name'];
                        ?>
</option>
										<?php 
                    }
                    ?>
									</select>
								</td>
							</tr>
						<?php 
                }
                ?>
						</tbody>
					</table>
				</div>
			</div>
		</div>
		<?php 
            }
            ?>
	</div>
	<div class="panel-footer">
		<a href="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['link']->value->getAdminLink('AdminProducts'), ENT_QUOTES, 'UTF-8', true);
            if (isset($_REQUEST['page']) && $_REQUEST['page'] > 1) {
                ?>
&amp;submitFilterproduct=<?php 
                echo intval($_REQUEST['page']);
            }
            ?>
" class="btn btn-default"><i class="process-icon-cancel"></i> <?php 
            echo smartyTranslate(array('s' => 'Cancel'), $_smarty_tpl);
            ?>
</a>
		<button type="submit" name="submitAddproduct" class="btn btn-default pull-right" disabled="disabled"><i class="process-icon-loading"></i> <?php 
            echo smartyTranslate(array('s' => 'Save'), $_smarty_tpl);
            ?>
</button>
		<button type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right" disabled="disabled"><i class="process-icon-loading"></i> <?php 
            echo smartyTranslate(array('s' => 'Save and stay'), $_smarty_tpl);
            ?>
</button>
	</div>
</div>
<?php 
        }
    }
Exemplo n.º 22
0
 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
     $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' => $qty), 'id_customization = ' . (int) $id_customization);
             // Calculate the real quantity of the product
             $product_quantity += $qty;
         }
     } else {
         $product_quantity = 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 = $product_price_tax_incl * $product_quantity;
     $total_products_tax_excl = $product_price_tax_excl * $product_quantity;
     // 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;
     // 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 = $order_detail->product_quantity;
     $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 - $order_detail->product_quantity, $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_incl'] - $resume['amount_tax_incl'];
     $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')))));
 }
Exemplo n.º 23
0
 private function _validateOrder($cart, $marketplace)
 {
     $payment = new SFPayment();
     $payment->name = 'SFPayment';
     $payment->active = true;
     //we need to flush the cart because of cache problems
     $cart->getPackageList(true);
     $cart->getDeliveryOptionList(null, true);
     $cart->getDeliveryOption(null, false, false);
     $payment->validateOrder((int) $cart->id, 2, (double) Tools::ps_round(Tools::convertPrice($cart->getOrderTotal(), new Currency($cart->id_currency)), 2), $marketplace, null, array(), $cart->id_currency, false, $cart->secure_key);
     return $payment;
 }
Exemplo n.º 24
0
 /**
  * Set the additional shipping information
  *
  * @param Order $order
  * @param $product
  */
 public function setShippingCost(Order $order, $product)
 {
     $tax_rate = 0;
     $carrier = OrderInvoice::getCarrier((int) $this->id_order_invoice);
     if (isset($carrier) && Validate::isLoadedObject($carrier)) {
         $tax_rate = $carrier->getTaxesRate(new Address((int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
     }
     $this->total_shipping_price_tax_excl = (double) $product['additional_shipping_cost'];
     $this->total_shipping_price_tax_incl = (double) ($this->total_shipping_price_tax_excl * (1 + $tax_rate / 100));
     $this->total_shipping_price_tax_incl = Tools::ps_round($this->total_shipping_price_tax_incl, 2);
 }
Exemplo n.º 25
0
 /**
  * Return useful informations for cart
  *
  * @return array Cart details
  */
 public function getSummaryDetails($id_lang = null, $refresh = false)
 {
     $context = Context::getContext();
     if (!$id_lang) {
         $id_lang = $context->language->id;
     }
     $delivery = new Address((int) $this->id_address_delivery);
     $invoice = new Address((int) $this->id_address_invoice);
     // New layout system with personalization fields
     $formatted_addresses = array('delivery' => AddressFormat::getFormattedLayoutData($delivery), 'invoice' => AddressFormat::getFormattedLayoutData($invoice));
     $base_total_tax_inc = $this->getOrderTotal(true);
     $base_total_tax_exc = $this->getOrderTotal(false);
     $total_tax = $base_total_tax_inc - $base_total_tax_exc;
     if ($total_tax < 0) {
         $total_tax = 0;
     }
     $currency = new Currency($this->id_currency);
     $products = $this->getProducts($refresh);
     $gift_products = array();
     $cart_rules = $this->getCartRules();
     $total_shipping = $this->getTotalShippingCost();
     $total_shipping_tax_exc = $this->getTotalShippingCost(null, false);
     $total_products_wt = $this->getOrderTotal(true, Cart::ONLY_PRODUCTS);
     $total_products = $this->getOrderTotal(false, Cart::ONLY_PRODUCTS);
     $total_discounts = $this->getOrderTotal(true, Cart::ONLY_DISCOUNTS);
     $total_discounts_tax_exc = $this->getOrderTotal(false, Cart::ONLY_DISCOUNTS);
     // The cart content is altered for display
     foreach ($cart_rules as &$cart_rule) {
         // If the cart rule is automatic (wihtout any code) and include free shipping, it should not be displayed as a cart rule but only set the shipping cost to 0
         if ($cart_rule['free_shipping'] && (empty($cart_rule['code']) || preg_match('/^' . CartRule::BO_ORDER_CODE_PREFIX . '[0-9]+/', $cart_rule['code']))) {
             $cart_rule['value_real'] -= $total_shipping;
             $cart_rule['value_tax_exc'] -= $total_shipping_tax_exc;
             $cart_rule['value_real'] = Tools::ps_round($cart_rule['value_real'], (int) $context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
             $cart_rule['value_tax_exc'] = Tools::ps_round($cart_rule['value_tax_exc'], (int) $context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
             if ($total_discounts > $cart_rule['value_real']) {
                 $total_discounts -= $total_shipping;
             }
             if ($total_discounts_tax_exc > $cart_rule['value_tax_exc']) {
                 $total_discounts_tax_exc -= $total_shipping_tax_exc;
             }
             // Update total shipping
             $total_shipping = 0;
             $total_shipping_tax_exc = 0;
         }
         if ($cart_rule['gift_product']) {
             foreach ($products as $key => &$product) {
                 if (empty($product['gift']) && $product['id_product'] == $cart_rule['gift_product'] && $product['id_product_attribute'] == $cart_rule['gift_product_attribute']) {
                     // Update total products
                     $total_products_wt = Tools::ps_round($total_products_wt - $product['price_wt'], (int) $context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     $total_products = Tools::ps_round($total_products - $product['price'], (int) $context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     // Update total discounts
                     $total_discounts = Tools::ps_round($total_discounts - $product['price_wt'], (int) $context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     $total_discounts_tax_exc = Tools::ps_round($total_discounts_tax_exc - $product['price'], (int) $context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     // Update cart rule value
                     $cart_rule['value_real'] = Tools::ps_round($cart_rule['value_real'] - $product['price_wt'], (int) $context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     $cart_rule['value_tax_exc'] = Tools::ps_round($cart_rule['value_tax_exc'] - $product['price'], (int) $context->currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     // Update product quantity
                     $product['total_wt'] = Tools::ps_round($product['total_wt'] - $product['price_wt'], (int) $currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     $product['total'] = Tools::ps_round($product['total'] - $product['price'], (int) $currency->decimals * _PS_PRICE_DISPLAY_PRECISION_);
                     $product['cart_quantity']--;
                     if (!$product['cart_quantity']) {
                         unset($products[$key]);
                     }
                     // Add a new product line
                     $gift_product = $product;
                     $gift_product['cart_quantity'] = 1;
                     $gift_product['price'] = 0;
                     $gift_product['price_wt'] = 0;
                     $gift_product['total_wt'] = 0;
                     $gift_product['total'] = 0;
                     $gift_product['gift'] = true;
                     $gift_products[] = $gift_product;
                     break;
                     // One gift product per cart rule
                 }
             }
         }
     }
     foreach ($cart_rules as $key => &$cart_rule) {
         if ($cart_rule['value_real'] == 0) {
             unset($cart_rules[$key]);
         }
     }
     return array('delivery' => $delivery, 'delivery_state' => State::getNameById($delivery->id_state), 'invoice' => $invoice, 'invoice_state' => State::getNameById($invoice->id_state), 'formattedAddresses' => $formatted_addresses, 'products' => array_values($products), 'gift_products' => $gift_products, 'discounts' => $cart_rules, 'is_virtual_cart' => (int) $this->isVirtualCart(), 'total_discounts' => $total_discounts, 'total_discounts_tax_exc' => $total_discounts_tax_exc, 'total_wrapping' => $this->getOrderTotal(true, Cart::ONLY_WRAPPING), 'total_wrapping_tax_exc' => $this->getOrderTotal(false, Cart::ONLY_WRAPPING), 'total_shipping' => $total_shipping, 'total_shipping_tax_exc' => $total_shipping_tax_exc, 'total_products_wt' => $total_products_wt, 'total_products' => $total_products, 'total_price' => $base_total_tax_inc, 'total_tax' => $total_tax, 'total_price_without_tax' => $base_total_tax_exc, 'is_multi_address_delivery' => $this->isMultiAddressDelivery() || (int) Tools::getValue('multi-shipping') == 1, 'free_ship' => $total_shipping ? 0 : 1, 'carrier' => new Carrier($this->id_carrier, $id_lang));
 }
Exemplo n.º 26
0
 /**
  *
  * Convert amount from a currency to an other currency automatically
  *
  * @param float $amount
  * @param Currency $currency_from if null we used the default currency
  * @param Currency $currency_to if null we used the default currency
  */
 public static function convertPriceFull($amount, Currency $currency_from = null, Currency $currency_to = null)
 {
     if ($currency_from === $currency_to) {
         return $amount;
     }
     if ($currency_from === null) {
         $currency_from = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
     }
     if ($currency_to === null) {
         $currency_to = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
     }
     if ($currency_from->id == Configuration::get('PS_CURRENCY_DEFAULT')) {
         $amount *= $currency_to->conversion_rate;
     } else {
         $conversion_rate = $currency_from->conversion_rate == 0 ? 1 : $currency_from->conversion_rate;
         // Convert amount to default currency (using the old currency rate)
         $amount = Tools::ps_round($amount / $conversion_rate, 2);
         // Convert to new currency
         $amount *= $currency_to->conversion_rate;
     }
     return Tools::ps_round($amount, 2);
 }
Exemplo n.º 27
0
 public static function getTotalAmountSold($id_seller)
 {
     $ovqdvnun = "sql";
     ${"GLOBALS"}["vpyikzbsisjd"] = "result";
     ${"GLOBALS"}["yibjtsiqdru"] = "totals";
     ${"GLOBALS"}["lueftdnvr"] = "id_seller";
     if (intval(${${"GLOBALS"}["tpubctvvlkrd"]}) <= 0) {
         return 0;
     }
     ${"GLOBALS"}["vtvlgprwkcq"] = "res";
     ${"GLOBALS"}["jihfecydict"] = "sql";
     ${$ovqdvnun} = "\n                SELECT SUM( (product_quantity  - product_quantity_refunded  ) * \n                            (product_price \n                              - CASE WHEN reduction_percent>0 THEN product_price * reduction_percent/100 ELSE reduction_amount END\n                              - product_price * group_reduction/100\n                             )\n                            - CASE WHEN IFNULL(discount_quantity_applied,0) = 1 THEN IFNULL(product_quantity_discount,0) ELSE 0 END\n                           ) AS total\n\t\t\t\t\t\t,o.id_currency\n                FROM `" . _DB_PREFIX_ . "order_detail` a\n                    LEFT JOIN `" . _DB_PREFIX_ . "order_owner` oo ON (a.id_order=oo.id_order)\n                    LEFT JOIN `" . _DB_PREFIX_ . "orders` o ON (a.id_order=o.id_order)\n                WHERE oo.id_owner =  " . intval(${${"GLOBALS"}["lueftdnvr"]}) . "\n\t\t\t\tGROUP BY o.id_currency\n                ";
     $jtohdtq = "result";
     ${${"GLOBALS"}["rqkzwch"]} = Db::getInstance()->ExecuteS(${${"GLOBALS"}["jihfecydict"]});
     ${${"GLOBALS"}["pcsrqmmeqyh"]} = array();
     if (empty(${${"GLOBALS"}["vpyikzbsisjd"]})) {
         return array(array("currency" => new Currency((int) Configuration::get("PS_CURRENCY_DEFAULT")), "amount" => 0));
     }
     foreach (${$jtohdtq} as ${${"GLOBALS"}["vtvlgprwkcq"]}) {
         $iccpjpexvivn = "res";
         ${${"GLOBALS"}["pcsrqmmeqyh"]}[] = array("currency" => new Currency(${${"GLOBALS"}["nsginhlnhc"]}["id_currency"]), "amount" => Tools::ps_round(${$iccpjpexvivn}["total"], 2));
     }
     return ${${"GLOBALS"}["yibjtsiqdru"]};
 }
Exemplo n.º 28
0
    public function getEcoTaxTaxesBreakdown()
    {
        $ecotax_detail = array();
        foreach ($this->getOrdersSlipDetail((int) $this->id) as $order_slip_details) {
            $row = Db::getInstance()->getRow('
					SELECT `ecotax_tax_rate` as `rate`, `ecotax` as `ecotax_tax_excl`, `ecotax` as `ecotax_tax_incl`, `product_quantity`
					FROM `' . _DB_PREFIX_ . 'order_detail`
					WHERE `id_order_detail` = ' . (int) $order_slip_details['id_order_detail']);
            if (!isset($ecotax_detail[$row['rate']])) {
                $ecotax_detail[$row['rate']] = array('ecotax_tax_incl' => 0, 'ecotax_tax_excl' => 0, 'rate' => $row['rate']);
            }
            $ecotax_detail[$row['rate']]['ecotax_tax_incl'] += Tools::ps_round($row['ecotax_tax_excl'] * $order_slip_details['product_quantity'] + $row['ecotax_tax_excl'] * $order_slip_details['product_quantity'] * $row['rate'] / 100, 2);
            $ecotax_detail[$row['rate']]['ecotax_tax_excl'] += Tools::ps_round($row['ecotax_tax_excl'] * $order_slip_details['product_quantity'], 2);
        }
        return $ecotax_detail;
    }
Exemplo n.º 29
0
 /**
  * @see ObjectModel::hydrate()
  */
 public function hydrate(array $data, $id_lang = null)
 {
     $this->id_lang = $id_lang;
     if (isset($data[$this->def['primary']])) {
         $this->id = $data[$this->def['primary']];
     }
     foreach ($data as $key => $value) {
         if (array_key_exists($key, $this)) {
             // formats prices and floats
             if ($this->def['fields'][$key]['validate'] == 'isFloat' || $this->def['fields'][$key]['validate'] == 'isPrice') {
                 $value = Tools::ps_round($value, 6);
             }
             $this->{$key} = $value;
         }
     }
 }
Exemplo n.º 30
0
 protected function itemExportAttributes($row, $product)
 {
     //Prodcut attributes
     if ($product->hasAttributes()) {
         $attributes = $product->getAttributeCombinaisons($this->id_lang);
         $images = $product->getCombinationImages($this->id_lang);
         $combinations = array();
         $attribute_groups = array();
         foreach ($attributes as $a) {
             $combinations[$a['id_product_attribute']][$a['id_attribute_group']] = $a;
             $attribute_groups[$a['id_attribute_group']] = $a['group_name'];
         }
         $i = 1;
         foreach ($attribute_groups as $id => $name) {
             $row['attribute_' . $i++] = $name;
         }
         $r = $row;
         foreach ($combinations as $id => $c) {
             $combination = current($c);
             //Images
             $image_urls = array();
             if (isset($images[$id]) && is_array($images[$id])) {
                 foreach ($images[$id] as $i) {
                     if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
                         array_push($image_urls, $this->context->link->getImageLink($product->link_rewrite, $product->id . '-' . $i['id_image'], 'thickbox_default'));
                     } elseif (version_compare(_PS_VERSION_, '1.5.0.0', '<') && version_compare(_PS_VERSION_, '1.4.0.0', '>=')) {
                         // lower than 1.5.0.0 higher than 1.4.0.0
                         array_push($image_urls, $this->context->link->getImageLink($product->link_rewrite, $product->id . '-' . $i['id_image'], 'thickbox'));
                     } else {
                         // lower then 1.4.0.0
                         array_push($image_urls, _PS_BASE_URL_ . $this->context->link->getImageLink($product->link_rewrite, $product->id . '-' . $i['id_image'], 'thickbox'));
                     }
                 }
             }
             if ((version_compare(_PS_VERSION_, '1.4.0.2', '>=') && $product->available_for_order && $combination['quantity'] > 0 || version_compare(_PS_VERSION_, '1.4.0.2', '<')) && $combination['quantity'] > 0) {
                 $availableText = $product->available_now;
                 $r['is_available'] = 1;
             } else {
                 $availableText = $product->available_later;
                 $r['is_available'] = 0;
             }
             $r['item_number'] = self::prefix . $product->id . '_' . $id;
             $r['has_children'] = 0;
             $r['parent_item_number'] = $row['item_number'];
             $r['urls_images'] = implode('||', $image_urls);
             // getPrice(false...) then we get only the net amount
             $reduction = (double) $product->getPrice(false, (int) $id, 2, NULL, true);
             // getPrice(false...) then we get only the net amount
             $r['old_unit_amount_net'] = Tools::ps_round($reduction != 0 ? $product->getPrice(false, (int) $id, 2, NULL, false, false) : 0, 2);
             // getPrice(false...) then we get only the net amount
             $r['unit_amount_net'] = Tools::ps_round($product->getPrice(false, (int) $id, 2), 2);
             if (version_compare(_PS_VERSION_, '1.4.1.0', '>=') && !empty($product->unity) && $product->unit_price_ratio > 0.0) {
                 // getPrice(false...) then we get only the net amount
                 $r['basic_price'] = Tools::displayPrice($product->getPrice(false, (int) $id, 2) / $product->unit_price_ratio) . ' ' . $this->shopgateModul->l('per') . ' ' . $product->unity;
             }
             $r['stock_quantity'] = $combination['quantity'];
             $r['ean'] = $combination['ean13'];
             $r['weight'] = $row['weight'] + self::convertProductWeightToGrams($combination['weight']);
             if (version_compare(_PS_VERSION_, '1.4.0.2', '>=')) {
                 $r['minimum_order_quantity'] = $combination['minimal_quantity'];
             }
             $r['available_text'] = $availableText;
             $r['item_number_public'] = array_key_exists('reference', $combination) && !empty($combination['reference']) ? $combination['reference'] : '';
             $i = 1;
             foreach ($attribute_groups as $id => $name) {
                 $r['attribute_' . $i++] = $c[$id]['attribute_name'];
             }
             $this->addItem($r);
         }
     }
     return $row;
 }