예제 #1
0
 public function smartyAssigns(&$smarty, &$params)
 {
     global $errors, $cookie;
     // Set currency
     if (!intval($params['cart']->id_currency)) {
         $currency = new Currency(intval($params['cookie']->id_currency));
     } else {
         $currency = new Currency(intval($params['cart']->id_currency));
     }
     if (!Validate::isLoadedObject($currency)) {
         $currency = new Currency(intval(Configuration::get('PS_CURRENCY_DEFAULT')));
     }
     if ($params['cart']->id_customer) {
         $customer = new Customer(intval($params['cart']->id_customer));
         $taxCalculationMethod = Group::getPriceDisplayMethod(intval($customer->id_default_group));
     } else {
         $taxCalculationMethod = Group::getDefaultPriceDisplayMethod();
     }
     $usetax = $taxCalculationMethod == PS_TAX_EXC ? false : true;
     $products = $params['cart']->getProducts(true);
     $nbTotalProducts = 0;
     foreach ($products as $product) {
         $nbTotalProducts += intval($product['cart_quantity']);
     }
     $wrappingCost = floatval($params['cart']->getOrderTotal($usetax, 6));
     $smarty->assign(array('products' => $products, 'customizedDatas' => Product::getAllCustomizedDatas(intval($params['cart']->id)), 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'discounts' => $params['cart']->getDiscounts(false, $usetax), 'nb_total_products' => intval($nbTotalProducts), 'shipping_cost' => Tools::displayPrice($params['cart']->getOrderTotal($usetax, 5), $currency), 'show_wrapping' => $wrappingCost > 0 ? true : false, 'wrapping_cost' => Tools::displayPrice($wrappingCost, $currency), 'product_total' => Tools::displayPrice($params['cart']->getOrderTotal($usetax, 4), $currency), 'total' => Tools::displayPrice($params['cart']->getOrderTotal($usetax), $currency), 'id_carrier' => intval($params['cart']->id_carrier), 'ajax_allowed' => intval(Configuration::get('PS_BLOCK_CART_AJAX')) == 1 ? true : false));
     if (sizeof($errors)) {
         $smarty->assign('errors', $errors);
     }
     if (isset($cookie->ajax_blockcart_display)) {
         $smarty->assign('colapseExpandStatus', $cookie->ajax_blockcart_display);
     }
 }
예제 #2
0
 /**
  * Returns the template's HTML content
  * @return string HTML content
  */
 public function getContent()
 {
     $invoice_address = new Address((int) $this->order->id_address_invoice);
     $country = new Country((int) $invoice_address->id_country);
     $formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' ');
     $formatted_delivery_address = '';
     if ($this->order->id_address_delivery != $this->order->id_address_invoice) {
         $delivery_address = new Address((int) $this->order->id_address_delivery);
         $formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' ');
     }
     $customer = new Customer((int) $this->order->id_customer);
     $order_details = $this->order_invoice->getProducts();
     if (Configuration::get('PS_PDF_IMG_INVOICE')) {
         foreach ($order_details as &$order_detail) {
             if ($order_detail['image'] != null) {
                 $name = 'product_mini_' . (int) $order_detail['product_id'] . (isset($order_detail['product_attribute_id']) ? '_' . (int) $order_detail['product_attribute_id'] : '') . '.jpg';
                 $order_detail['image_tag'] = ImageManager::thumbnail(_PS_IMG_DIR_ . 'p/' . $order_detail['image']->getExistingImgPath() . '.jpg', $name, 45, 'jpg', false);
                 if (file_exists(_PS_TMP_IMG_DIR_ . $name)) {
                     $order_detail['image_size'] = getimagesize(_PS_TMP_IMG_DIR_ . $name);
                 } else {
                     $order_detail['image_size'] = false;
                 }
             }
         }
     }
     $data = array('order' => $this->order, 'order_details' => $order_details, 'cart_rules' => $this->order->getCartRules($this->order_invoice->id), 'delivery_address' => $formatted_delivery_address, 'invoice_address' => $formatted_invoice_address, 'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group), 'tax_tab' => $this->getTaxTabContent(), 'customer' => $customer);
     if (Tools::getValue('debug')) {
         die(json_encode($data));
     }
     $this->smarty->assign($data);
     return $this->smarty->fetch($this->getTemplateByCountry($country->iso_code));
 }
예제 #3
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;
     }
     if ($params['cart']->id_customer) {
         $customer = new Customer((int) $params['cart']->id_customer);
         $taxCalculationMethod = Group::getPriceDisplayMethod((int) $customer->id_default_group);
     } else {
         $taxCalculationMethod = Group::getDefaultPriceDisplayMethod();
     }
     $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();
     $shipping_cost = Tools::displayPrice($params['cart']->getOrderTotal($useTax, Cart::ONLY_SHIPPING), $currency);
     $shipping_cost_float = Tools::convertPrice($params['cart']->getOrderTotal($useTax, Cart::ONLY_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['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);
     }
 }
예제 #4
0
 public function __construct($id = NULL, $id_lang = NULL)
 {
     parent::__construct($id, $id_lang);
     if ($this->id_customer) {
         $customer = new Customer(intval($this->id_customer));
         $this->_taxCalculationMethod = Group::getPriceDisplayMethod(intval($customer->id_default_group));
     } else {
         $this->_taxCalculationMethod = Group::getDefaultPriceDisplayMethod();
     }
 }
 public function process()
 {
     parent::process();
     if ($id_order = Tools::getValue('id_order') and $email = Tools::getValue('email')) {
         $order = new Order((int) $id_order);
         if (!Validate::isLoadedObject($order)) {
             $this->errors[] = Tools::displayError('Invalid order');
         } elseif (!$order->isAssociatedAtGuest($email)) {
             $this->errors[] = Tools::displayError('Invalid order');
         } else {
             $customer = new Customer((int) $order->id_customer);
             $id_order_state = (int) $order->getCurrentState();
             $carrier = new Carrier((int) $order->id_carrier, (int) $order->id_lang);
             $addressInvoice = new Address((int) $order->id_address_invoice);
             $addressDelivery = new Address((int) $order->id_address_delivery);
             $inv_adr_fields = AddressFormat::getOrderedAddressFields($addressInvoice->id_country);
             $dlv_adr_fields = AddressFormat::getOrderedAddressFields($addressDelivery->id_country);
             $invoiceAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressInvoice, $inv_adr_fields);
             $deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressDelivery, $dlv_adr_fields);
             if ($order->total_discounts > 0) {
                 self::$smarty->assign('total_old', (double) ($order->total_paid - $order->total_discounts));
             }
             $products = $order->getProducts();
             $customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart);
             Product::addCustomizationPrice($products, $customizedDatas);
             $this->processAddressFormat($addressDelivery, $addressInvoice);
             self::$smarty->assign(array('shop_name' => Configuration::get('PS_SHOP_NAME'), 'order' => $order, 'return_allowed' => false, 'currency' => new Currency($order->id_currency), 'order_state' => (int) $id_order_state, 'invoiceAllowed' => (int) Configuration::get('PS_INVOICE'), 'invoice' => OrderState::invoiceAvailable((int) $id_order_state) and $order->invoice_number, 'order_history' => $order->getHistory((int) self::$cookie->id_lang, false, true), 'products' => $products, 'discounts' => $order->getDiscounts(), 'carrier' => $carrier, 'address_invoice' => $addressInvoice, 'invoiceState' => (Validate::isLoadedObject($addressInvoice) and $addressInvoice->id_state) ? new State((int) $addressInvoice->id_state) : false, 'address_delivery' => $addressDelivery, 'deliveryState' => (Validate::isLoadedObject($addressDelivery) and $addressDelivery->id_state) ? new State((int) $addressDelivery->id_state) : false, 'is_guest' => true, 'group_use_tax' => Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC, 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'use_tax' => Configuration::get('PS_TAX'), 'customizedDatas' => $customizedDatas, 'invoiceAddressFormatedValues' => $invoiceAddressFormatedValues, 'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues));
             if ($carrier->url and $order->shipping_number) {
                 self::$smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url));
             }
             self::$smarty->assign('HOOK_ORDERDETAILDISPLAYED', Module::hookExec('orderDetailDisplayed', array('order' => $order)));
             Module::hookExec('OrderDetail', array('carrier' => $carrier, 'order' => $order));
             if (Tools::isSubmit('submitTransformGuestToCustomer')) {
                 $customer = new Customer((int) $order->id_customer);
                 if (!Validate::isLoadedObject($customer)) {
                     $this->errors[] = Tools::displayError('Invalid customer');
                 }
                 if (!$customer->transformToCustomer(self::$cookie->id_lang, Tools::getValue('password'))) {
                     $this->errors[] = Tools::displayError('An error occurred while transforming guest to customer.');
                 }
                 if (!Tools::getValue('password')) {
                     $this->errors[] = Tools::displayError('Invalid password');
                 } else {
                     self::$smarty->assign('transformSuccess', true);
                 }
             }
         }
         if (sizeof($this->errors)) {
             /* Handle brute force attacks */
             sleep(1);
         }
     }
     self::$smarty->assign(array('action' => 'guest-tracking.php', 'errors' => $this->errors));
 }
예제 #6
0
 /**
  * Returns the template's HTML content
  * @return string HTML content
  */
 public function getContent()
 {
     $country = new Country((int) $this->order->id_address_invoice);
     $invoice_address = new Address((int) $this->order->id_address_invoice);
     $formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' ');
     $formatted_delivery_address = '';
     if ($this->order->id_address_delivery != $this->order->id_address_invoice) {
         $delivery_address = new Address((int) $this->order->id_address_delivery);
         $formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' ');
     }
     $customer = new Customer((int) $this->order->id_customer);
     $this->smarty->assign(array('order' => $this->order, 'order_details' => $this->order_invoice->getProducts(), 'cart_rules' => $this->order->getCartRules($this->order_invoice->id), 'delivery_address' => $formatted_delivery_address, 'invoice_address' => $formatted_invoice_address, 'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group), 'tax_tab' => $this->getTaxTabContent(), 'customer' => $customer));
     return $this->smarty->fetch($this->getTemplateByCountry($country->iso_code));
 }
예제 #7
0
 public function getContent()
 {
     $invoice_address = new Address((int) $this->order->id_address_invoice);
     $formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' ');
     $formatted_delivery_address = '';
     if ($this->order->id_address_delivery != $this->order->id_address_invoice) {
         $delivery_address = new Address((int) $this->order->id_address_delivery);
         $formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' ');
     }
     $customer = new Customer((int) $this->order->id_customer);
     $carrier = new Carrier((int) $this->order->id_carrier);
     $data = array('order' => $this->order, 'order_details' => $this->order->getProducts(), 'delivery_address' => $formatted_delivery_address, 'invoice_address' => $formatted_invoice_address, 'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group), 'customer' => $customer, 'carrier' => $carrier);
     $this->smarty->assign($data);
     $order_pdf_tpl = _PS_MODULE_DIR_ . '/mobassistantconnector/views/templates/front/order_pdf.tpl';
     return $this->smarty->fetch($order_pdf_tpl);
 }
 /**
  * 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)));
 }
예제 #9
0
 public function smartyAssigns(&$smarty, &$params)
 {
     global $errors, $cookie;
     // Set currency
     if (!(int) $params['cart']->id_currency) {
         $currency = new Currency((int) $params['cookie']->id_currency);
     } else {
         $currency = new Currency((int) $params['cart']->id_currency);
     }
     if (!Validate::isLoadedObject($currency)) {
         $currency = new Currency((int) Configuration::get('PS_CURRENCY_DEFAULT'));
     }
     if ($params['cart']->id_customer) {
         $customer = new Customer((int) $params['cart']->id_customer);
         $taxCalculationMethod = Group::getPriceDisplayMethod((int) $customer->id_default_group);
     } else {
         $taxCalculationMethod = Group::getDefaultPriceDisplayMethod();
     }
     $useTax = $taxCalculationMethod != PS_TAX_EXC;
     $products = $params['cart']->getProducts(true);
     $nbTotalProducts = 0;
     foreach ($products as $product) {
         $nbTotalProducts += (int) $product['cart_quantity'];
     }
     $wrappingCost = (double) $params['cart']->getOrderTotal($useTax, Cart::ONLY_WRAPPING);
     if (Configuration::get('PS_TAX_DISPLAY') == 1 && ($useTax || Configuration::get('PS_TAX_DISPLAY_ALL'))) {
         $totalToPay = $params['cart']->getOrderTotal(true);
         $totalToPayWithoutTaxes = $params['cart']->getOrderTotal(false);
         $smarty->assign('tax_cost', Tools::displayPrice($totalToPay - $totalToPayWithoutTaxes, $currency));
     } else {
         $totalToPay = $params['cart']->getOrderTotal($useTax);
     }
     $smarty->assign(array('products' => $products, 'customizedDatas' => Product::getAllCustomizedDatas((int) $params['cart']->id), 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'discounts' => $params['cart']->getDiscounts(false, Tools::isSubmit('id_product')), 'nb_total_products' => (int) $nbTotalProducts, 'shipping_cost' => Tools::displayPrice($params['cart']->getOrderTotal($useTax, Cart::ONLY_SHIPPING), $currency), 'show_wrapping' => $wrappingCost > 0 ? true : false, 'show_tax' => (int) ((int) Configuration::get('PS_TAX_DISPLAY') && (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), 'id_carrier' => (int) $params['cart']->id_carrier, 'order_process' => Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc' : 'order', 'ajax_allowed' => (int) Configuration::get('PS_BLOCK_CART_AJAX') == 1 ? true : false));
     if (sizeof($errors)) {
         $smarty->assign('errors', $errors);
     }
     if (isset($cookie->ajax_blockcart_display)) {
         $smarty->assign('colapseExpandStatus', $cookie->ajax_blockcart_display);
     }
 }
예제 #10
0
 public function setTaxCalculationMethod()
 {
     $this->_taxCalculationMethod = Group::getPriceDisplayMethod(Group::getCurrent()->id);
 }
예제 #11
0
 /**
  *
  * @see FrontController::postProcess()
  */
 public function postProcess()
 {
     $cart = $this->context->cart;
     if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active) {
         Tools::redirect('index.php?controller=order&step=1');
     }
     // Check that this payment option is still available in case the customer changed his address just before the end of the checkout process
     $authorized = false;
     foreach (Module::getPaymentModules() as $module) {
         if ($module['name'] == 'adyen') {
             $authorized = true;
             break;
         }
     }
     if (!$authorized) {
         die($this->module->l('This payment method is not available.', 'validation'));
     }
     $customer = new Customer($cart->id_customer);
     if (!Validate::isLoadedObject($customer)) {
         Tools::redirect('index.php?controller=order&step=1');
     }
     // get the selected currency
     $currency = $this->context->currency;
     $total = (double) $cart->getOrderTotal(true, Cart::BOTH);
     // validate order
     // $payment_method name must be the same as module name otherwise successurl won't show
     $this->module->validateOrder($cart->id, Configuration::get('ADYEN_NEW_STATUS'), $total, 'Adyen', null, array(), (int) $currency->id, false, $customer->secure_key);
     Logger::addLog('Adyen module: order is validated for id_order ' . $cart->id);
     // go to form adyen post values (submitted automatically)
     $config = Configuration::getMultiple(array('ADYEN_MERCHANT_ACCOUNT', 'ADYEN_MODE', 'ADYEN_SKIN_CODE', 'ADYEN_HMAC_TEST', 'ADYEN_HMAC_LIVE', 'ADYEN_NOTI_USERNAME', 'ADYEN_NOTI_PASSWORD', 'ADYEN_DAYS_DELIVERY', 'PS_SSL_ENABLED', 'ADYEN_COUNTRY_CODE_ISO', 'ADYEN_LANGUAGE_LOCALE'));
     $customer = new Customer((int) $cart->id_customer);
     $address = new Address((int) $cart->id_address_invoice);
     $country = new Country((int) $address->id_country);
     $language = Language::getIsoById((int) $cart->id_lang);
     if (!Validate::isLoadedObject($address) || !Validate::isLoadedObject($customer) || !Validate::isLoadedObject($currency)) {
         Logger::addLog('Adyen module: invalid address, customer, or currency for id_order ' . $cart->id, 4);
         return $this->module->l('Adyen error: (invalid address, customer, or currency)');
     }
     $merchant_account = (string) $config['ADYEN_MERCHANT_ACCOUNT'];
     $skin_code = (string) $config['ADYEN_SKIN_CODE'];
     $currency_code = (string) $currency->iso_code;
     $shopper_email = (string) $customer->email;
     $merchant_reference = (int) $this->module->currentOrder;
     // set when order is validated
     $payment_amount = number_format($cart->getOrderTotal(true, 3), 2, '', '');
     $shopper_reference = (string) $customer->secure_key;
     if ($config['ADYEN_COUNTRY_CODE_ISO'] != '') {
         $country_code = (string) $config['ADYEN_COUNTRY_CODE_ISO'];
     } else {
         $country_code = (string) $country->iso_code;
     }
     // Locale (language) to present to shopper (e.g. en_US, nl, fr, fr_BE)
     if ($config['ADYEN_LANGUAGE_LOCALE'] != '') {
         $shopper_locale = (string) $config['ADYEN_LANGUAGE_LOCALE'];
     } else {
         $shopper_locale = (string) $language;
     }
     $recurring_contract = 'ONECLICK';
     $ship_before_date = date('Y-m-d', mktime(date('H'), date('i'), date('s'), date('m'), date('j') + (isset($config['ADYEN_DAYS_DELIVERY']) ? $config['ADYEN_DAYS_DELIVERY'] : 5), date('Y')));
     // example: ship in 5 days
     $session_validity = date(DATE_ATOM, mktime(date('H') + 1, date('i'), date('s'), date('m'), date('j'), date('Y')));
     // presentation of the shopping basket.
     $tax_calculation_method = Group::getPriceDisplayMethod((int) Group::getCurrent()->id);
     $use_tax = !($tax_calculation_method == PS_TAX_EXC);
     $shipping_cost = Tools::displayPrice($cart->getOrderTotal($use_tax, Cart::ONLY_SHIPPING), $currency);
     $prod_details = sprintf('Shipment cost: %s <br />', $shipping_cost);
     $prod_details .= 'Order rows: <br />';
     // get order items
     foreach ($cart->getProducts() as $product) {
         $name = $product['name'];
         $qty_ordered = (int) $product['cart_quantity'];
         $row_total = Tools::ps_round($product['total_wt'], 2);
         $prod_details .= sprintf('%s ( Qty: %s ) ( Price: %s %s ) <br />', $name, $qty_ordered, $row_total, $currency_code);
     }
     $order_data = base64_encode(gzencode($prod_details));
     // for elv and cc can be mutliple values seperate by comma(,)
     $blocked_methods = '';
     $hmac_data = $payment_amount . $currency_code . $ship_before_date . $merchant_reference . $skin_code . $merchant_account . $session_validity . $shopper_email . $shopper_reference . $recurring_contract . $blocked_methods;
     $merchant_sig = base64_encode(pack('H*', $this->module->getHmacsha1($this->module->getHmac(), $hmac_data)));
     $brand_code = '';
     $ideal_issuer_id = '';
     $skip_selection = '';
     if (Tools::getValue('payment_type') != '') {
         $brand_code = (string) Tools::getValue('payment_type');
     }
     if (Tools::getValue('ideal_type') != '') {
         $ideal_issuer_id = (int) Tools::getValue('ideal_type');
         $skip_selection = 'true';
     }
     $this->context->smarty->assign(array('merchantAccount' => $merchant_account, 'skinCode' => $skin_code, 'currencyCode' => $currency_code, 'shopperEmail' => $shopper_email, 'merchantReference' => $merchant_reference, 'paymentAmount' => $payment_amount, 'shopperReference' => $shopper_reference, 'shipBeforeDate' => $ship_before_date, 'sessionValidity' => $session_validity, 'shopperLocale' => $shopper_locale, 'countryCode' => $country_code, 'orderData' => $order_data, 'recurringContract' => $recurring_contract, 'merchantSig' => $merchant_sig, 'adyenUrl' => $this->getAdyenUrl($brand_code, $ideal_issuer_id), 'resURL' => ($config['PS_SSL_ENABLED'] ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'index.php?controller=order-confirmation&key=' . $customer->secure_key . '&id_cart=' . (int) $cart->id . '&id_module=' . (int) $this->module->id . '&id_order=' . (int) $this->module->currentOrder, 'brandCode' => $brand_code, 'skipSelection' => $skip_selection, 'idealIssuerId' => $ideal_issuer_id));
 }
예제 #12
0
 public function getProducts($selected_filters, &$products, &$nb_products, &$p, &$n, &$pages_nb, &$start, &$stop, &$range, &$combinations)
 {
     global $cookie;
     $products = $this->getProductByFilters($selected_filters);
     $products = Product::getProductsProperties((int) $cookie->id_lang, $products);
     $nb_products = $this->nbr_products;
     $range = 2;
     /* how many pages around page selected */
     $n = (int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE'));
     if ($n <= 0) {
         $n = 1;
     }
     $p = $this->page;
     if ($p < 0) {
         $p = 0;
     }
     if ($p > $nb_products / $n) {
         $p = ceil($nb_products / $n);
     }
     $pages_nb = ceil($nb_products / (int) $n);
     $start = (int) ($p - $range);
     if ($start < 1) {
         $start = 1;
     }
     $stop = (int) ($p + $range);
     if ($stop > $pages_nb) {
         $stop = (int) $pages_nb;
     }
     foreach ($products as &$product) {
         if ($product['id_product_attribute'] && isset($product['product_attribute_minimal_quantity'])) {
             $product['minimal_quantity'] = $product['product_attribute_minimal_quantity'];
         }
         $product_obj = new Product((int) $product['id_product'], $this->context->language->id);
         $product['groups'] = $product_obj->getProductCombinationsGroups((int) $product['id_product']);
         $product['obj'] = $product_obj;
         $combinations[$product['id_product']] = $product_obj->getProductAttributeCombinations($product['id_product']);
         $id_group = (int) Group::getCurrent()->id;
         $group_reduction = GroupReduction::getValueForProduct($product['id_product'], $id_group);
         if ($group_reduction === false) {
             $group_reduction = Group::getReduction((int) $this->context->cookie->id_customer) / 100;
         }
         $product['group_reduction'] = $group_reduction;
         $address = new Address($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
         $product['no_tax'] = Tax::excludeTaxeOption() || !$product_obj->getTaxesRate($address);
         $product['customer_group_without_tax'] = Group::getPriceDisplayMethod($this->context->customer->id_default_group);
         $tax = (double) $product_obj->getTaxesRate(new Address((int) $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
         $product['tax_rate'] = $tax;
         $product['unit_price_ratio'] = $product_obj->unit_price_ratio;
         $ecotax_rate = (double) Tax::getProductEcotaxRate($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
         $product['ecotaxTax_rate'] = $ecotax_rate;
     }
 }
예제 #13
0
 public static function initPricesComputation($id_customer = NULL)
 {
     global $cookie;
     if ($id_customer) {
         $customer = new Customer((int) $id_customer);
         if (!Validate::isLoadedObject($customer)) {
             die(Tools::displayError());
         }
         self::$_taxCalculationMethod = Group::getPriceDisplayMethod((int) $customer->id_default_group);
     } elseif ($cookie->id_customer) {
         $customer = new Customer((int) $cookie->id_customer);
         self::$_taxCalculationMethod = Group::getPriceDisplayMethod((int) $customer->id_default_group);
     } else {
         self::$_taxCalculationMethod = Group::getDefaultPriceDisplayMethod();
     }
 }
예제 #14
0
 /**
  * Check if customer has tax
  * @param  mix $customer Customer information (id|email|object)
  * @return boolean       Tax enable
  */
 protected function taxEnableByCustomer($customer)
 {
     if (!Validate::isLoadedObject($customer)) {
         if (Validate::isEmail($customer)) {
             $customer = $this->getCustomerByEmail($customer);
         } else {
             if (Validate::isInt($customer)) {
                 $customer = new Customer((int) $customer);
             }
         }
     }
     return !Group::getPriceDisplayMethod((int) $customer->id_default_group);
 }
 public function preProcess()
 {
     parent::preProcess();
     if (Tools::isSubmit('submitMessage')) {
         $idOrder = (int) Tools::getValue('id_order');
         $msgText = htmlentities(Tools::getValue('msgText'), ENT_COMPAT, 'UTF-8');
         if (!$idOrder or !Validate::isUnsignedId($idOrder)) {
             $this->errors[] = Tools::displayError('Order is no longer valid');
         } elseif (empty($msgText)) {
             $this->errors[] = Tools::displayError('Message cannot be blank');
         } elseif (!Validate::isMessage($msgText)) {
             $this->errors[] = Tools::displayError('Message is invalid (HTML is not allowed)');
         }
         if (!sizeof($this->errors)) {
             $order = new Order((int) $idOrder);
             if (Validate::isLoadedObject($order) and $order->id_customer == self::$cookie->id_customer) {
                 $message = new Message();
                 $message->id_customer = (int) self::$cookie->id_customer;
                 $message->message = $msgText;
                 $message->id_order = (int) $idOrder;
                 $message->private = false;
                 $message->add();
                 if (!Configuration::get('PS_MAIL_EMAIL_MESSAGE')) {
                     $to = strval(Configuration::get('PS_SHOP_EMAIL'));
                 } else {
                     $to = new Contact((int) Configuration::get('PS_MAIL_EMAIL_MESSAGE'));
                     $to = strval($to->email);
                 }
                 $toName = strval(Configuration::get('PS_SHOP_NAME'));
                 $customer = new Customer((int) self::$cookie->id_customer);
                 if (Validate::isLoadedObject($customer)) {
                     Mail::Send((int) self::$cookie->id_lang, 'order_customer_comment', Mail::l('Message from a customer', (int) self::$cookie->id_lang), array('{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{email}' => $customer->email, '{id_order}' => (int) $message->id_order, '{order_name}' => sprintf("#%06d", (int) $message->id_order), '{message}' => $message->message), $to, $toName, $customer->email, $customer->firstname . ' ' . $customer->lastname);
                 }
                 if (Tools::getValue('ajax') != 'true') {
                     Tools::redirect('order-detail.php?id_order=' . (int) $idOrder);
                 }
             } else {
                 $this->errors[] = Tools::displayError('Order not found');
             }
         }
     }
     if (!($id_order = (int) Tools::getValue('id_order')) or !Validate::isUnsignedId($id_order)) {
         $this->errors[] = Tools::displayError('Order ID required');
     } else {
         $order = new Order($id_order);
         if (Validate::isLoadedObject($order) and $order->id_customer == self::$cookie->id_customer) {
             $id_order_state = (int) $order->getCurrentState();
             $carrier = new Carrier((int) $order->id_carrier, (int) $order->id_lang);
             $addressInvoice = new Address((int) $order->id_address_invoice);
             $addressDelivery = new Address((int) $order->id_address_delivery);
             //	$stateInvoiceAddress = new State((int)$addressInvoice->id_state);
             $inv_adr_fields = AddressFormat::getOrderedAddressFields($addressInvoice->id_country);
             $dlv_adr_fields = AddressFormat::getOrderedAddressFields($addressDelivery->id_country);
             $invoiceAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressInvoice, $inv_adr_fields);
             $deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressDelivery, $dlv_adr_fields);
             if ($order->total_discounts > 0) {
                 self::$smarty->assign('total_old', (double) ($order->total_paid - $order->total_discounts));
             }
             $products = $order->getProducts();
             $customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart);
             Product::addCustomizationPrice($products, $customizedDatas);
             $customer = new Customer($order->id_customer);
             self::$smarty->assign(array('shop_name' => strval(Configuration::get('PS_SHOP_NAME')), 'order' => $order, 'return_allowed' => (int) $order->isReturnable(), 'currency' => new Currency($order->id_currency), 'order_state' => (int) $id_order_state, 'invoiceAllowed' => (int) Configuration::get('PS_INVOICE'), 'invoice' => OrderState::invoiceAvailable((int) $id_order_state) and $order->invoice_number, 'order_history' => $order->getHistory((int) self::$cookie->id_lang, false, true), 'products' => $products, 'discounts' => $order->getDiscounts(), 'carrier' => $carrier, 'address_invoice' => $addressInvoice, 'invoiceState' => (Validate::isLoadedObject($addressInvoice) and $addressInvoice->id_state) ? new State((int) $addressInvoice->id_state) : false, 'address_delivery' => $addressDelivery, 'inv_adr_fields' => $inv_adr_fields, 'dlv_adr_fields' => $dlv_adr_fields, 'invoiceAddressFormatedValues' => $invoiceAddressFormatedValues, 'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues, 'deliveryState' => (Validate::isLoadedObject($addressDelivery) and $addressDelivery->id_state) ? new State((int) $addressDelivery->id_state) : false, 'is_guest' => false, 'messages' => Message::getMessagesByOrderId((int) $order->id), 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'isRecyclable' => Configuration::get('PS_RECYCLABLE_PACK'), 'use_tax' => Configuration::get('PS_TAX'), 'group_use_tax' => Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC, 'customizedDatas' => $customizedDatas));
             if ($carrier->url and $order->shipping_number) {
                 self::$smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url));
             }
             self::$smarty->assign('HOOK_ORDERDETAILDISPLAYED', Module::hookExec('orderDetailDisplayed', array('order' => $order)));
             Module::hookExec('OrderDetail', array('carrier' => $carrier, 'order' => $order));
             unset($carrier);
             unset($addressInvoice);
             unset($addressDelivery);
         } else {
             $this->errors[] = Tools::displayError('Cannot find this order');
         }
         unset($order);
     }
 }
 /**
  * Returns Shipping tax breakdown elements
  *
  * @return Array Shipping tax breakdown elements
  */
 public function getShippingTaxesBreakdown()
 {
     $taxes_breakdown = array();
     $tax = new Tax();
     $tax->rate = $this->order->carrier_tax_rate;
     $tax_calculator = new TaxCalculator(array($tax));
     $customer = new Customer((int) $this->order->id_customer);
     $tax_excluded_display = Group::getPriceDisplayMethod((int) $customer->id_default_group);
     if ($tax_excluded_display) {
         $total_tax_excl = $this->order_slip->shipping_cost_amount;
         $shipping_tax_amount = $tax_calculator->addTaxes($this->order_slip->shipping_cost_amount) - $total_tax_excl;
     } else {
         $total_tax_excl = $tax_calculator->removeTaxes($this->order_slip->shipping_cost_amount);
         $shipping_tax_amount = $this->order_slip->shipping_cost_amount - $total_tax_excl;
     }
     if ($shipping_tax_amount > 0) {
         $taxes_breakdown[] = array('rate' => $this->order->carrier_tax_rate, 'total_amount' => $shipping_tax_amount, 'total_tax_excl' => $total_tax_excl);
     }
     return $taxes_breakdown;
 }
예제 #17
0
 /**
  * Assign template vars related to order tracking informations
  */
 protected function assignOrderTracking($order_collection)
 {
     $customer = new Customer((int) $order_collection->getFirst()->id_customer);
     $order_collection = $order_collection->getAll();
     $order_list = array();
     foreach ($order_collection as $order) {
         $order_list[] = $order;
     }
     foreach ($order_list as &$order) {
         $order->id_order_state = (int) $order->getCurrentState();
         $order->invoice = OrderState::invoiceAvailable((int) $order->id_order_state) && $order->invoice_number;
         $order->order_history = $order->getHistory((int) $this->context->language->id, false, true);
         $order->carrier = new Carrier((int) $order->id_carrier, (int) $order->id_lang);
         $order->address_invoice = new Address((int) $order->id_address_invoice);
         $order->address_delivery = new Address((int) $order->id_address_delivery);
         $order->inv_adr_fields = AddressFormat::getOrderedAddressFields($order->address_invoice->id_country);
         $order->dlv_adr_fields = AddressFormat::getOrderedAddressFields($order->address_delivery->id_country);
         $order->invoiceAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($order->address_invoice, $order->inv_adr_fields);
         $order->deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($order->address_delivery, $order->dlv_adr_fields);
         $order->currency = new Currency($order->id_currency);
         $order->discounts = $order->getCartRules();
         $order->invoiceState = Validate::isLoadedObject($order->address_invoice) && $order->address_invoice->id_state ? new State((int) $order->address_invoice->id_state) : false;
         $order->deliveryState = Validate::isLoadedObject($order->address_delivery) && $order->address_delivery->id_state ? new State((int) $order->address_delivery->id_state) : false;
         $order->products = $order->getProducts();
         $order->customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart);
         Product::addCustomizationPrice($order->products, $order->customizedDatas);
         $order->total_old = $order->total_discounts > 0 ? (double) ($order->total_paid - $order->total_discounts) : false;
         if ($order->carrier->url && $order->shipping_number) {
             $order->followup = str_replace('@', $order->shipping_number, $order->carrier->url);
         }
         $order->hook_orderdetaildisplayed = Hook::exec('displayOrderDetail', array('order' => $order));
         Hook::exec('actionOrderDetail', array('carrier' => $order->carrier, 'order' => $order));
     }
     $this->context->smarty->assign(array('shop_name' => Configuration::get('PS_SHOP_NAME'), 'order_collection' => $order_list, 'return_allowed' => false, 'invoiceAllowed' => (int) Configuration::get('PS_INVOICE'), 'is_guest' => true, 'group_use_tax' => Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC, 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'use_tax' => Configuration::get('PS_TAX')));
 }
예제 #18
0
파일: Cart.php 프로젝트: dev-lav/htdocs
 public function __construct($id = null, $id_lang = null)
 {
     parent::__construct($id);
     if (!is_null($id_lang)) {
         $this->id_lang = (int) (Language::getLanguage($id_lang) !== false) ? $id_lang : Configuration::get('PS_LANG_DEFAULT');
     }
     if ($this->id_customer) {
         if (isset(Context::getContext()->customer) && Context::getContext()->customer->id == $this->id_customer) {
             $customer = Context::getContext()->customer;
         } else {
             $customer = new Customer((int) $this->id_customer);
         }
         if ((!$this->secure_key || $this->secure_key == '-1') && $customer->secure_key) {
             $this->secure_key = $customer->secure_key;
             $this->save();
         }
     }
     $this->_taxCalculationMethod = Group::getPriceDisplayMethod(Group::getCurrent()->id);
 }
예제 #19
0
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     if (!($id_order = (int) Tools::getValue('id_order')) || !Validate::isUnsignedId($id_order)) {
         $this->errors[] = Tools::displayError('Order ID required');
     } else {
         $order = new Order($id_order);
         if (Validate::isLoadedObject($order) && $order->id_customer == $this->context->customer->id) {
             $id_order_state = (int) $order->getCurrentState();
             $carrier = new Carrier((int) $order->id_carrier, (int) $order->id_lang);
             $addressInvoice = new Address((int) $order->id_address_invoice);
             $addressDelivery = new Address((int) $order->id_address_delivery);
             $inv_adr_fields = AddressFormat::getOrderedAddressFields($addressInvoice->id_country);
             $dlv_adr_fields = AddressFormat::getOrderedAddressFields($addressDelivery->id_country);
             $invoiceAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressInvoice, $inv_adr_fields);
             $deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressDelivery, $dlv_adr_fields);
             if ($order->total_discounts > 0) {
                 $this->context->smarty->assign('total_old', (double) ($order->total_paid - $order->total_discounts));
             }
             $products = $order->getProducts();
             /* DEPRECATED: customizedDatas @since 1.5 */
             $customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart);
             Product::addCustomizationPrice($products, $customizedDatas);
             OrderReturn::addReturnedQuantity($products, $order->id);
             $customer = new Customer($order->id_customer);
             $this->context->smarty->assign(array('shop_name' => strval(Configuration::get('PS_SHOP_NAME')), 'order' => $order, 'return_allowed' => (int) $order->isReturnable(), 'currency' => new Currency($order->id_currency), 'order_state' => (int) $id_order_state, 'invoiceAllowed' => (int) Configuration::get('PS_INVOICE'), 'invoice' => OrderState::invoiceAvailable($id_order_state) && count($order->getInvoicesCollection()), 'order_history' => $order->getHistory($this->context->language->id, false, true), 'products' => $products, 'discounts' => $order->getCartRules(), 'carrier' => $carrier, 'address_invoice' => $addressInvoice, 'invoiceState' => Validate::isLoadedObject($addressInvoice) && $addressInvoice->id_state ? new State($addressInvoice->id_state) : false, 'address_delivery' => $addressDelivery, 'inv_adr_fields' => $inv_adr_fields, 'dlv_adr_fields' => $dlv_adr_fields, 'invoiceAddressFormatedValues' => $invoiceAddressFormatedValues, 'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues, 'deliveryState' => Validate::isLoadedObject($addressDelivery) && $addressDelivery->id_state ? new State($addressDelivery->id_state) : false, 'is_guest' => false, 'messages' => CustomerMessage::getMessagesByOrderId((int) $order->id, false), 'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE, 'CUSTOMIZE_TEXTFIELD' => Product::CUSTOMIZE_TEXTFIELD, 'isRecyclable' => Configuration::get('PS_RECYCLABLE_PACK'), 'use_tax' => Configuration::get('PS_TAX'), 'group_use_tax' => Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC, 'customizedDatas' => $customizedDatas));
             if ($carrier->url && $order->shipping_number) {
                 $this->context->smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url));
             }
             $this->context->smarty->assign('HOOK_ORDERDETAILDISPLAYED', Hook::exec('displayOrderDetail', array('order' => $order)));
             Hook::exec('actionOrderDetail', array('carrier' => $carrier, 'order' => $order));
             unset($carrier, $addressInvoice, $addressDelivery);
         } else {
             $this->errors[] = Tools::displayError('This order cannot be found.');
         }
         unset($order);
     }
     $this->setTemplate(_PS_THEME_DIR_ . 'order-detail.tpl');
 }
예제 #20
0
파일: Cart.php 프로젝트: jicheng17/pengwine
 public function __construct($id = null, $id_lang = null)
 {
     parent::__construct($id, $id_lang);
     if ($this->id_customer) {
         if (isset(Context::getContext()->customer) && Context::getContext()->customer->id == $this->id_customer) {
             $customer = Context::getContext()->customer;
         } else {
             $customer = new Customer((int) $this->id_customer);
         }
         if ((!$this->secure_key || $this->secure_key == '-1') && $customer->secure_key) {
             $this->secure_key = $customer->secure_key;
             $this->save();
         }
     }
     $this->_taxCalculationMethod = Group::getPriceDisplayMethod(Group::getCurrent()->id);
 }
 public function process()
 {
     parent::process();
     self::$smarty->assign(array('is_guest' => self::$cookie->is_guest, 'HOOK_ORDER_CONFIRMATION' => Hook::orderConfirmation((int) $this->id_order), 'HOOK_PAYMENT_RETURN' => Hook::paymentReturn((int) $this->id_order, (int) $this->id_module)));
     if (self::$cookie->is_guest) {
         self::$smarty->assign(array('id_order' => $this->id_order, 'id_order_formatted' => sprintf('#%06d', $this->id_order)));
         /* If guest we clear the cookie for security reason */
         self::$cookie->logout();
     } else {
         self::$smarty->assign(array('id_order' => $this->id_order, 'id_order_formatted' => sprintf('#%06d', $this->id_order)));
     }
     //assign order details here
     $order = new Order($this->id_order);
     if (Validate::isLoadedObject($order) and $order->id_customer == self::$cookie->id_customer) {
         $id_order_state = (int) $order->getCurrentState();
         $carrier = new Carrier((int) $order->id_carrier, (int) $order->id_lang);
         $addressInvoice = new Address((int) $order->id_address_invoice);
         $addressDelivery = new Address((int) $order->id_address_delivery);
         //	$stateInvoiceAddress = new State((int)$addressInvoice->id_state);
         $inv_adr_fields = AddressFormat::getOrderedAddressFields($addressInvoice->id_country);
         $dlv_adr_fields = AddressFormat::getOrderedAddressFields($addressDelivery->id_country);
         $invoiceAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressInvoice, $inv_adr_fields);
         $deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressDelivery, $dlv_adr_fields);
         if ($order->total_discounts > 0) {
             self::$smarty->assign('total_old', (double) ($order->total_paid - $order->total_discounts));
         }
         self::$smarty->assign('order_total', Tools::ps_round($order->total_paid));
         self::$smarty->assign('order_total_usd', Tools::ps_round(Tools::convertPrice($order->total_paid, self::$cookie->id_currency, false)));
         $products = $order->getProducts();
         $customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart);
         Product::addCustomizationPrice($products, $customizedDatas);
         $customer = new Customer($order->id_customer);
         $order->customization_fee = Cart::getCustomizationCostStatic((int) $order->id_cart);
         $totalQuantity = 0;
         foreach ($products as $productRow) {
             $totalQuantity += $productRow['product_quantity'];
         }
         if (strpos($order->payment, 'COD') === false) {
             self::$smarty->assign('paymentMethod', 'ONLINE');
         } else {
             self::$smarty->assign('paymentMethod', 'COD');
         }
         $shippingdate = new DateTime($order->expected_shipping_date);
         self::$smarty->assign(array('shipping_date' => $shippingdate->format("F j, Y"), 'shop_name' => strval(Configuration::get('PS_SHOP_NAME')), 'order' => $order, 'return_allowed' => (int) $order->isReturnable(), 'currency' => new Currency($order->id_currency), 'order_state' => (int) $id_order_state, 'invoiceAllowed' => (int) Configuration::get('PS_INVOICE'), 'invoice' => OrderState::invoiceAvailable((int) $id_order_state) and $order->invoice_number, 'order_history' => $order->getHistory((int) self::$cookie->id_lang, false, true), 'products' => $products, 'discounts' => $order->getDiscounts(), 'carrier' => $carrier, 'address_invoice' => $addressInvoice, 'invoiceState' => (Validate::isLoadedObject($addressInvoice) and $addressInvoice->id_state) ? new State((int) $addressInvoice->id_state) : false, 'address_delivery' => $addressDelivery, 'inv_adr_fields' => $inv_adr_fields, 'dlv_adr_fields' => $dlv_adr_fields, 'invoiceAddressFormatedValues' => $invoiceAddressFormatedValues, 'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues, 'deliveryState' => (Validate::isLoadedObject($addressDelivery) and $addressDelivery->id_state) ? new State((int) $addressDelivery->id_state) : false, 'is_guest' => false, 'messages' => Message::getMessagesByOrderId((int) $order->id), 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'use_tax' => Configuration::get('PS_TAX'), 'group_use_tax' => Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC, 'customizedDatas' => $customizedDatas, 'totalQuantity' => $totalQuantity));
         if ($carrier->url and $order->shipping_number) {
             self::$smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url));
         }
         self::$smarty->assign('HOOK_ORDERDETAILDISPLAYED', Module::hookExec('orderDetailDisplayed', array('order' => $order)));
         Module::hookExec('OrderDetail', array('carrier' => $carrier, 'order' => $order));
         //FB Share
         //$products = $order->getProducts();
         $orderProducts = array();
         $productMaxVal = 0;
         $productMaxId = null;
         foreach ($products as $product) {
             array_push($orderProducts, $product['product_id']);
             if ($product['product_price'] > $productMaxVal) {
                 $productMaxId = $product['product_id'];
                 $productMaxVal = $product['product_price'];
             }
         }
         $productObj = new Product($productMaxId, true, 1);
         self::$smarty->assign('fbShareProductObject', $productObj->getLink());
         self::$smarty->assign('fbShareProductObjectId', $productMaxId);
         self::$smarty->assign('orderProducts', implode(",", $orderProducts));
         self::$cookie->shareProductCode = md5(time() . $productMaxId);
         self::$cookie->write();
         unset($carrier);
         unset($addressInvoice);
         unset($addressDelivery);
     }
 }
예제 #22
0
 public function __construct($id = NULL, $id_lang = NULL)
 {
     parent::__construct($id, $id_lang);
     if ($this->id_customer) {
         $customer = new Customer((int) $this->id_customer);
         $this->_taxCalculationMethod = Group::getPriceDisplayMethod((int) $customer->id_default_group);
         if ((!$this->secure_key or $this->secure_key == '-1') and $customer->secure_key) {
             $this->secure_key = $customer->secure_key;
             $this->save();
         }
     } else {
         $this->_taxCalculationMethod = Group::getDefaultPriceDisplayMethod();
     }
 }
예제 #23
0
 public function __construct($id = null, $id_lang = null)
 {
     parent::__construct($id, $id_lang);
     $is_admin = is_object(Context::getContext()->controller) && Context::getContext()->controller->controller_type == 'admin';
     if ($this->id_customer && !$is_admin) {
         $customer = new Customer((int) $this->id_customer);
         $this->_taxCalculationMethod = Group::getPriceDisplayMethod((int) $customer->id_default_group);
     } else {
         $this->_taxCalculationMethod = Group::getDefaultPriceDisplayMethod();
     }
 }
예제 #24
0
 public function __construct($id = NULL, $id_lang = NULL)
 {
     parent::__construct($id, $id_lang);
     $this->_taxCalculationMethod = $this->id_customer ? Group::getPriceDisplayMethod(intval($this->id_customer)) : Group::getDefaultPriceDisplayMethod();
 }
예제 #25
0
 public function renderView()
 {
     if (!($cart = $this->loadObject(true))) {
         return;
     }
     $customer = new Customer($cart->id_customer);
     $currency = new Currency($cart->id_currency);
     $this->context->cart = $cart;
     $this->context->currency = $currency;
     $this->context->customer = $customer;
     $this->toolbar_title = sprintf($this->l('Cart #%06d'), $this->context->cart->id);
     $products = $cart->getProducts();
     $customized_datas = Product::getAllCustomizedDatas((int) $cart->id);
     Product::addCustomizationPrice($products, $customized_datas);
     $summary = $cart->getSummaryDetails();
     /* Display order information */
     $id_order = (int) Order::getOrderByCartId($cart->id);
     $order = new Order($id_order);
     if (Validate::isLoadedObject($order)) {
         $tax_calculation_method = $order->getTaxCalculationMethod();
         $id_shop = (int) $order->id_shop;
     } else {
         $id_shop = (int) $cart->id_shop;
         $tax_calculation_method = Group::getPriceDisplayMethod(Group::getCurrent()->id);
     }
     if ($tax_calculation_method == PS_TAX_EXC) {
         $total_products = $summary['total_products'];
         $total_discounts = $summary['total_discounts_tax_exc'];
         $total_wrapping = $summary['total_wrapping_tax_exc'];
         $total_price = $summary['total_price_without_tax'];
         $total_shipping = $summary['total_shipping_tax_exc'];
     } else {
         $total_products = $summary['total_products_wt'];
         $total_discounts = $summary['total_discounts'];
         $total_wrapping = $summary['total_wrapping'];
         $total_price = $summary['total_price'];
         $total_shipping = $summary['total_shipping'];
     }
     foreach ($products as $k => &$product) {
         if ($tax_calculation_method == PS_TAX_EXC) {
             $product['product_price'] = $product['price'];
             $product['product_total'] = $product['total'];
         } else {
             $product['product_price'] = $product['price_wt'];
             $product['product_total'] = $product['total_wt'];
         }
         $image = array();
         if (isset($product['id_product_attribute']) && (int) $product['id_product_attribute']) {
             $image = Db::getInstance()->getRow('SELECT id_image FROM ' . _DB_PREFIX_ . 'product_attribute_image WHERE id_product_attribute = ' . (int) $product['id_product_attribute']);
         }
         if (!isset($image['id_image'])) {
             $image = Db::getInstance()->getRow('SELECT id_image FROM ' . _DB_PREFIX_ . 'image WHERE id_product = ' . (int) $product['id_product'] . ' AND cover = 1');
         }
         $product_obj = new Product($product['id_product']);
         $product['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct($product['id_product'], isset($product['id_product_attribute']) ? $product['id_product_attribute'] : null, (int) $id_shop);
         $image_product = new Image($image['id_image']);
         $product['image'] = isset($image['id_image']) ? ImageManager::thumbnail(_PS_IMG_DIR_ . 'p/' . $image_product->getExistingImgPath() . '.jpg', 'product_mini_' . (int) $product['id_product'] . (isset($product['id_product_attribute']) ? '_' . (int) $product['id_product_attribute'] : '') . '.jpg', 45, 'jpg') : '--';
     }
     $helper = new HelperKpi();
     $helper->id = 'box-kpi-cart';
     $helper->icon = 'icon-shopping-cart';
     $helper->color = 'color1';
     $helper->title = $this->l('Total Cart', null, null, false);
     $helper->subtitle = sprintf($this->l('Cart #%06d', null, null, false), $cart->id);
     $helper->value = Tools::displayPrice($total_price, $currency);
     $kpi = $helper->generate();
     $this->tpl_view_vars = array('kpi' => $kpi, 'products' => $products, 'discounts' => $cart->getCartRules(), 'order' => $order, 'cart' => $cart, 'currency' => $currency, 'customer' => $customer, 'customer_stats' => $customer->getStats(), 'total_products' => $total_products, 'total_discounts' => $total_discounts, 'total_wrapping' => $total_wrapping, 'total_price' => $total_price, 'total_shipping' => $total_shipping, 'customized_datas' => $customized_datas);
     return parent::renderView();
 }
예제 #26
0
파일: Product.php 프로젝트: yewed/share
 public static function initPricesComputation($id_customer = null)
 {
     if ($id_customer) {
         $customer = new Customer((int) $id_customer);
         if (!Validate::isLoadedObject($customer)) {
             die(Tools::displayError());
         }
         self::$_taxCalculationMethod = Group::getPriceDisplayMethod((int) $customer->id_default_group);
         $cur_cart = Context::getContext()->cart;
         $id_address = 0;
         if (Validate::isLoadedObject($cur_cart)) {
             $id_address = (int) $cur_cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
         }
         $address_infos = Address::getCountryAndState($id_address);
         if (self::$_taxCalculationMethod != PS_TAX_EXC && !empty($address_infos['vat_number']) && $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') && Configuration::get('VATNUMBER_MANAGEMENT')) {
             self::$_taxCalculationMethod = PS_TAX_EXC;
         }
     } else {
         self::$_taxCalculationMethod = Group::getPriceDisplayMethod(Group::getCurrent()->id);
     }
 }
예제 #27
0
$smarty->register_function('convertPriceWithoutDisplay', array('Product', 'productPriceWithoutDisplay'));
$smarty->register_function('convertPriceWithCurrency', array('Product', 'convertPriceWithCurrency'));
$smarty->register_function('displayWtPrice', array('Product', 'displayWtPrice'));
$smarty->register_function('displayWtPriceWithCurrency', array('Product', 'displayWtPriceWithCurrency'));
$smarty->register_function('displayPrice', array('Tools', 'displayPriceSmarty'));
$smarty->assign(Tools::getMetaTags(intval($cookie->id_lang)));
$smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
/* Breadcrumb */
$navigationPipe = Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>';
$smarty->assign('navigationPipe', $navigationPipe);
/* Server Params */
$server_host = Tools::getHttpHost(false, true);
$protocol = 'http://';
$protocol_ssl = 'https://';
$protocol_link = Configuration::get('PS_SSL_ENABLED') ? $protocol_ssl : $protocol;
$protocol_content = (isset($useSSL) and $useSSL and Configuration::get('PS_SSL_ENABLED')) ? $protocol_ssl : $protocol;
define('_PS_BASE_URL_', $protocol . $server_host);
Product::initPricesComputation();
if (!Configuration::get('PS_THEME_V11')) {
    define('_PS_BASE_URL_SSL_', $protocol_ssl . $server_host);
    $smarty->assign(array('base_dir' => _PS_BASE_URL_ . __PS_BASE_URI__, 'base_dir_ssl' => $protocol_link . $server_host . __PS_BASE_URI__, 'content_dir' => $protocol_content . $server_host . __PS_BASE_URI__, 'img_ps_dir' => $protocol_content . $server_host . _PS_IMG_, 'img_cat_dir' => $protocol_content . $server_host . _THEME_CAT_DIR_, 'img_lang_dir' => $protocol_content . $server_host . _THEME_LANG_DIR_, 'img_prod_dir' => $protocol_content . $server_host . _THEME_PROD_DIR_, 'img_manu_dir' => $protocol_content . $server_host . _THEME_MANU_DIR_, 'img_sup_dir' => $protocol_content . $server_host . _THEME_SUP_DIR_, 'img_ship_dir' => $protocol_content . $server_host . _THEME_SHIP_DIR_, 'img_col_dir' => $protocol_content . $server_host . _THEME_COL_DIR_, 'img_dir' => $protocol_content . $server_host . _THEME_IMG_DIR_, 'css_dir' => $protocol_content . $server_host . _THEME_CSS_DIR_, 'js_dir' => $protocol_content . $server_host . _THEME_JS_DIR_, 'tpl_dir' => _PS_THEME_DIR_, 'modules_dir' => _MODULE_DIR_, 'mail_dir' => _MAIL_DIR_, 'pic_dir' => $protocol_content . $server_host . _THEME_PROD_PIC_DIR_, 'lang_iso' => $ps_language->iso_code, 'come_from' => Tools::getHttpHost(true, true) . htmlentities($_SERVER['REQUEST_URI']), 'shop_name' => Configuration::get('PS_SHOP_NAME'), 'cart_qties' => intval($cart->nbProducts()), 'cart' => $cart, 'currencies' => Currency::getCurrencies(), 'id_currency_cookie' => intval($currency->id), 'currency' => $currency, 'cookie' => $cookie, 'languages' => Language::getLanguages(), 'logged' => $cookie->isLogged(), 'page_name' => $page_name, 'customerName' => $cookie->logged ? $cookie->customer_firstname . ' ' . $cookie->customer_lastname : false, 'priceDisplay' => intval($cookie->id_customer ? Group::getPriceDisplayMethod(intval($cookie->id_customer)) : Group::getDefaultPriceDisplayMethod()), 'roundMode' => intval(Configuration::get('PS_PRICE_ROUND_MODE'))));
} else {
    $protocol = (isset($useSSL) and $useSSL and Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
    $smarty->assign(array('base_dir' => __PS_BASE_URI__, 'base_dir_ssl' => Tools::getHttpHost(true, true) . __PS_BASE_URI__, 'content_dir' => __PS_BASE_URI__, 'protocol' => $protocol, 'img_ps_dir' => _PS_IMG_, 'img_cat_dir' => _THEME_CAT_DIR_, 'img_lang_dir' => _THEME_LANG_DIR_, 'img_prod_dir' => _THEME_PROD_DIR_, 'img_manu_dir' => _THEME_MANU_DIR_, 'img_sup_dir' => _THEME_SUP_DIR_, 'img_ship_dir' => _THEME_SHIP_DIR_, 'img_col_dir' => _THEME_COL_DIR_, 'img_dir' => _THEME_IMG_DIR_, 'css_dir' => _THEME_CSS_DIR_, 'js_dir' => _THEME_JS_DIR_, 'tpl_dir' => _PS_THEME_DIR_, 'modules_dir' => _MODULE_DIR_, 'mail_dir' => _MAIL_DIR_, 'pic_dir' => _THEME_PROD_PIC_DIR_, 'lang_iso' => $ps_language->iso_code, 'come_from' => Tools::getHttpHost(true, true) . htmlentities($_SERVER['REQUEST_URI']), 'shop_name' => Configuration::get('PS_SHOP_NAME'), 'cart_qties' => intval($cart->nbProducts()), 'cart' => $cart, 'currencies' => Currency::getCurrencies(), 'id_currency_cookie' => intval($currency->id), 'currency' => $currency, 'cookie' => $cookie, 'languages' => Language::getLanguages(), 'logged' => $cookie->isLogged(), 'priceDisplay' => intval($cookie->id_customer ? Group::getPriceDisplayMethod(intval($cookie->id_customer)) : Group::getDefaultPriceDisplayMethod()), 'page_name' => $page_name, 'customerName' => $cookie->logged ? $cookie->customer_firstname . ' ' . $cookie->customer_lastname : false, 'roundMode' => intval(Configuration::get('PS_PRICE_ROUND_MODE'))));
}
/* Display a maintenance page if shop is closed */
if (isset($maintenance) and (!isset($_SERVER['REMOTE_ADDR']) or !in_array($_SERVER['REMOTE_ADDR'], explode(',', Configuration::get('PS_MAINTENANCE_IP'))))) {
    header('HTTP/1.1 503 temporarily overloaded');
    $smarty->display(_PS_THEME_DIR_ . 'maintenance.tpl');
    exit;
}
예제 #28
0
 public static function initPricesComputation($id_customer = null)
 {
     if ($id_customer) {
         $customer = new Customer((int) $id_customer);
         if (!Validate::isLoadedObject($customer)) {
             die(Tools::displayError());
         }
         self::$_taxCalculationMethod = Group::getPriceDisplayMethod((int) $customer->id_default_group);
     } else {
         if (Validate::isLoadedObject(Context::getContext()->customer)) {
             self::$_taxCalculationMethod = Group::getPriceDisplayMethod(Context::getContext()->customer->id_default_group);
         } else {
             self::$_taxCalculationMethod = Group::getDefaultPriceDisplayMethod();
         }
     }
 }
예제 #29
0
 public static function getDefaultPriceDisplayMethod()
 {
     return Group::getPriceDisplayMethod((int) Configuration::get('PS_CUSTOMER_GROUP'));
 }
    /**
     * Returns the template's HTML content
     * @return string HTML content
     */
    public function getContent()
    {
        $invoice_address = new Address((int) $this->order->id_address_invoice);
        $formatted_invoice_address = AddressFormat::generateAddress($invoice_address, array(), '<br />', ' ');
        $formatted_delivery_address = '';
        if ($this->order->id_address_delivery != $this->order->id_address_invoice) {
            $delivery_address = new Address((int) $this->order->id_address_delivery);
            $formatted_delivery_address = AddressFormat::generateAddress($delivery_address, array(), '<br />', ' ');
        }
        $customer = new Customer((int) $this->order->id_customer);
        $this->order->total_products = $this->order->total_products_wt = 0;
        foreach ($this->order->products as &$product) {
            $product['total_price_tax_excl'] = $product['unit_price_tax_excl'] * $product['product_quantity'];
            $product['total_price_tax_incl'] = $product['unit_price_tax_incl'] * $product['product_quantity'];
            if ($this->order_slip->partial == 1) {
                $order_slip_detail = Db::getInstance()->getRow('
					SELECT * FROM `' . _DB_PREFIX_ . 'order_slip_detail`
					WHERE `id_order_slip` = ' . (int) $this->order_slip->id . '
					AND `id_order_detail` = ' . (int) $product['id_order_detail']);
                $product['total_price_tax_excl'] = $order_slip_detail['amount_tax_excl'];
                $product['total_price_tax_incl'] = $order_slip_detail['amount_tax_incl'];
            }
            $this->order->total_products += $product['total_price_tax_excl'];
            $this->order->total_products_wt += $product['total_price_tax_incl'];
            $this->order->total_paid_tax_excl = $this->order->total_products;
            $this->order->total_paid_tax_incl = $this->order->total_products_wt;
        }
        unset($product);
        // remove reference
        if ($this->order_slip->shipping_cost == 0) {
            $this->order->total_shipping_tax_incl = $this->order->total_shipping_tax_excl = 0;
        }
        if ($this->order_slip->partial == 1 && $this->order_slip->shipping_cost_amount > 0) {
            $this->order->total_shipping_tax_incl = $this->order_slip->shipping_cost_amount;
        }
        $tax = new Tax();
        $tax->rate = $this->order->carrier_tax_rate;
        $tax_calculator = new TaxCalculator(array($tax));
        $this->order->total_shipping_tax_excl = Tools::ps_round($tax_calculator->removeTaxes($this->order_slip->shipping_cost_amount), 2);
        $this->order->total_paid_tax_incl += $this->order_slip->shipping_cost_amount;
        $this->smarty->assign(array('order' => $this->order, 'order_slip' => $this->order_slip, 'order_details' => $this->order->products, 'cart_rules' => $this->order_slip->order_slip_type == 1 ? $this->order->getCartRules($this->order_invoice->id) : false, 'amount_choosen' => $this->order_slip->order_slip_type == 2 ? true : false, 'delivery_address' => $formatted_delivery_address, 'invoice_address' => $formatted_invoice_address, 'tax_excluded_display' => Group::getPriceDisplayMethod((int) $customer->id_default_group), 'tax_tab' => $this->getTaxTabContent()));
        return $this->smarty->fetch($this->getTemplate('order-slip'));
    }