Exemple #1
1
 public static function getCountryDefault($countryID)
 {
     if (!$countryID) {
         return false;
     }
     $sql = "SELECT *\n                FROM `taxes`\n                WHERE `country_id` = ?s\n                AND `state_code` IS NULL";
     $db = self::$_msql = SafeMySQL::getInstance();
     $result = $db->getRow($sql, $countryID);
     if ($result) {
         $tax = new Tax();
         $tax->fillFromArray($result);
         return $tax;
     }
     return false;
 }
 /**
  * creates of a dejala carrier corresponding to $dejalaProduct
  */
 public static function createDejalaCarrier($dejalaConfig, $dejalaProduct)
 {
     // MFR091130 - get id zone from the country used in the module (if the store zones were customized) - default is 1 (Europe)
     $id_zone = 1;
     $moduleCountryIsoCode = strtoupper($dejalaConfig->country);
     $countryID = Country::getByIso($moduleCountryIsoCode);
     if (intval($countryID)) {
         $id_zone = Country::getIdZone($countryID);
     }
     $vatRate = floatval($dejalaProduct['vat']);
     // MFR091130 - get or create the tax & attach it to our zone if needed
     $id_tax = Tax::getTaxIdByRate($vatRate);
     if (!$id_tax) {
         $tax = new Tax();
         $tax->rate = $vatRate;
         $defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
         $tax->name[$defaultLanguage] = $tax->rate . '%';
         $tax->add();
         $id_tax = Tax::getTaxIdByRate($vatRate);
     }
     if (!Tax::zoneHasTax($id_tax, $id_zone)) {
         // MFR : direct call because $tax->addZone($id_zone) causes errors when called
         Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'tax_zone` (`id_tax` , `id_zone`) VALUES (' . intval($id_tax) . ', ' . intval($id_zone) . ')');
     }
     $carrier = new Carrier();
     $carrier->name = 'dejala';
     $carrier->id_tax = $id_tax;
     $carrier->url = 'http://tracking.dejala.' . $dejalaConfig->country . '/tracker/@';
     $carrier->active = true;
     $carrier->deleted = 0;
     $carrier->shipping_handling = false;
     $carrier->range_behavior = 0;
     $carrier->is_module = 1;
     $languages = Language::getLanguages(true);
     foreach ($languages as $language) {
         if ($language['iso_code'] == 'fr') {
             $carrier->delay[$language['id_lang']] = utf8_encode('Quand vous voulez... Par coursier, ' . $dejalaProduct['timelimit'] . 'H');
         }
         if ($language['iso_code'] == 'en') {
             $carrier->delay[$language['id_lang']] = utf8_encode('When you want... Dispatch rider, ' . $dejalaProduct['timelimit'] . 'H range');
         }
         if ($language['iso_code'] == 'es') {
             $carrier->delay[$language['id_lang']] = utf8_encode('Cuando quiera... Por mensajero, ' . $dejalaProduct['timelimit'] . 'H');
         }
     }
     $carrier->add();
     $sql = 'INSERT INTO `' . _DB_PREFIX_ . 'carrier_zone` (`id_carrier` , `id_zone`) VALUES (' . intval($carrier->id) . ', ' . intval($id_zone) . ')';
     Db::getInstance()->Execute($sql);
     $rangeW = new RangeWeight();
     $rangeW->id_carrier = $carrier->id;
     $rangeW->delimiter1 = 0;
     $rangeW->delimiter2 = $dejalaProduct['max_weight'];
     $rangeW->add();
     $vat_factor = 1 + $dejalaProduct['vat'] / 100;
     $priceTTC = round($dejalaProduct['price'] * $vat_factor + $dejalaProduct['margin'], 2);
     $priceHT = round($priceTTC / $vat_factor, 2);
     $priceList = '(NULL' . ',' . $rangeW->id . ',' . $carrier->id . ',' . $id_zone . ',' . $priceHT . ')';
     $carrier->addDeliveryPrice($priceList);
     return new Carrier($carrier->id);
 }
Exemple #3
0
 /** @depends testConstructEmpty */
 public function testValidity()
 {
     $tax = new Tax("Cat", "Label", stdtimefstr("2001-01-01 00:00:00"), 0.2);
     $this->assertTrue($tax->isValid(stdtimefstr("2001-01-01 00:00:00")), "Tax recognised invalid at change date");
     $this->assertTrue($tax->isValid(stdtimefstr("2001-01-02 00:00:00")), "Tax recognised invalid after change date");
     $this->assertFalse($tax->isValid(stdtimefstr("2000-01-01 00:00:00")), "Tax recognised valid before change date");
 }
Exemple #4
0
 public function getTax($request)
 {
     if ($this->checkDetails($request)) {
         $object = new Tax();
         $array = $object->getTaxes($request["restaurantID"]);
         return $array;
     }
 }
 function calcTax($subTotal, $storeId)
 {
     $tax = new Tax();
     $rs = $tax->taxRate($storeId);
     if (isset($rs[0])) {
         $taxRate = $rs[0]['rate'];
         return number_format(floatval($subTotal) * floatval($taxRate / 100), 2, '.', ' ');
     } else {
         return number_format(0, 2, '.', ' ');
     }
 }
Exemple #6
0
 /**
  * Setup the instance (singleton)
  *
  * @return Tax
  */
 public static function getInstance()
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 public function initRuleForm()
 {
     $this->fields_form[0]['form'] = array('legend' => array('title' => $this->l('New tax rule'), 'icon' => 'icon-money'), 'input' => array(array('type' => 'select', 'label' => $this->l('Country'), 'name' => 'country', 'id' => 'country', 'options' => array('query' => Country::getCountries($this->context->language->id), 'id' => 'id_country', 'name' => 'name', 'default' => array('value' => 0, 'label' => $this->l('All')))), array('type' => 'select', 'label' => $this->l('State'), 'name' => 'states[]', 'id' => 'states', 'multiple' => true, 'options' => array('query' => array(), 'id' => 'id_state', 'name' => 'name', 'default' => array('value' => 0, 'label' => $this->l('All')))), array('type' => 'hidden', 'name' => 'action'), array('type' => 'text', 'label' => $this->l('Zip/postal code range'), 'name' => 'zipcode', 'required' => false, 'hint' => $this->l('You can define a range of Zip/postal codes (e.g., 75000-75015) or simply use one Zip/postal code.')), array('type' => 'select', 'label' => $this->l('Behavior'), 'name' => 'behavior', 'required' => false, 'options' => array('query' => array(array('id' => 0, 'name' => $this->l('This tax only')), array('id' => 1, 'name' => $this->l('Combine')), array('id' => 2, 'name' => $this->l('One after another'))), 'id' => 'id', 'name' => 'name'), 'hint' => array($this->l('You must define the behavior if an address matches multiple rules:') . '<br>', $this->l('- This tax only: Will apply only this tax') . '<br>', $this->l('- Combine: Combine taxes (e.g.: 10% + 5% = 15%)') . '<br>', $this->l('- One after another: Apply taxes one after another (e.g.: 0 + 10% = 0 + 5% = 5.5)'))), array('type' => 'select', 'label' => $this->l('Tax'), 'name' => 'id_tax', 'required' => false, 'options' => array('query' => Tax::getTaxes((int) $this->context->language->id), 'id' => 'id_tax', 'name' => 'name', 'default' => array('value' => 0, 'label' => $this->l('No Tax'))), 'hint' => sprintf($this->l('(Total tax: %s)'), '9%')), array('type' => 'select', 'label' => $this->l('Grupos'), 'name' => 'id_group', 'required' => false, 'options' => array('query' => Group::getGroups($this->default_form_language, true), 'id' => 'id_group', 'name' => 'name', 'default' => array('value' => 0, 'label' => $this->l('Default'))), 'hint' => sprintf($this->l('(Total tax: %s)'), '9%')), array('type' => 'text', 'label' => $this->l('Description'), 'name' => 'description')), 'submit' => array('title' => $this->l('Save and stay'), 'stay' => true));
     if (!($obj = $this->loadObject(true))) {
         return;
     }
     $this->fields_value = array('action' => 'create_rule', 'id_tax_rules_group' => $obj->id, 'id_tax_rule' => '');
     $this->getlanguages();
     $helper = new HelperForm();
     $helper->override_folder = $this->tpl_folder;
     $helper->currentIndex = self::$currentIndex;
     $helper->token = $this->token;
     $helper->table = 'tax_rule';
     $helper->identifier = 'id_tax_rule';
     $helper->id = $obj->id;
     $helper->toolbar_scroll = true;
     $helper->show_toolbar = true;
     $helper->languages = $this->_languages;
     $helper->default_form_language = $this->default_form_language;
     $helper->allow_employee_form_lang = $this->allow_employee_form_lang;
     $helper->fields_value = $this->getFieldsValue($this->object);
     $helper->toolbar_btn['save_new_rule'] = array('href' => self::$currentIndex . '&amp;id_tax_rules_group=' . $obj->id . '&amp;action=create_rule&amp;token=' . $this->token, 'desc' => 'Save tax rule', 'class' => 'process-icon-save');
     $helper->submit_action = 'create_rule';
     return $helper->generateForm($this->fields_form);
 }
Exemple #8
0
 /** @return Tax */
 public function getVat()
 {
     if (!$this->tax) {
         return NULL;
     }
     return $this->tax->getVat()->getPercent();
 }
 public function update($nullValues = false)
 {
     if (!$this->deleted && $this->isUsed()) {
         $historized_tax = new Tax($this->id);
         $historized_tax->historize();
         // remove the id in order to create a new object
         $this->id = 0;
         $res = $this->add();
         // change tax id in the tax rule table
         $res &= TaxRule::swapTaxId($historized_tax->id, $this->id);
         return $res;
     } elseif (parent::update($nullValues)) {
         return $this->_onStatusChange();
     }
     return false;
 }
Exemple #10
0
 public function beforeSave()
 {
     // make sure there isn't already a record with the same country and state code
     $db = self::$_msql = SafeMySQL::getInstance();
     $sql = "SELECT tax_id\n                FROM `taxes`\n                WHERE `country_id` = ?s";
     if ($this->state_code) {
         $sql .= " and state_code = ?s";
     } else {
         $sql .= " and state_code is NULL";
     }
     if ($this->tax_id) {
         $sql .= " and tax_id = ?i";
         if ($this->state_code) {
             $result = $db->getOne($sql, $this->country_id, $this->state_code, $this->tax_id);
         } else {
             $result = $db->getOne($sql, $this->country_id, $this->tax_id);
         }
     } else {
         if ($this->state_code) {
             $result = $db->getOne($sql, $this->country_id, $this->state_code);
         } else {
             $result = $db->getOne($sql, $this->country_id);
         }
     }
     if ($result) {
         return false;
     } else {
         return TRUE;
     }
 }
 public function __construct()
 {
     global $cookie;
     $this->className = 'Configuration';
     $this->table = 'configuration';
     $max_upload = (int) ini_get('upload_max_filesize');
     $max_post = (int) ini_get('post_max_size');
     $upload_mb = min($max_upload, $max_post);
     $timezones = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT name FROM ' . _DB_PREFIX_ . 'timezone');
     $taxes[] = array('id' => 0, 'name' => $this->l('None'));
     foreach (Tax::getTaxes((int) $cookie->id_lang) as $tax) {
         $taxes[] = array('id' => $tax['id_tax'], 'name' => $tax['name']);
     }
     $order_process_type = array(array('value' => PS_ORDER_PROCESS_STANDARD, 'name' => $this->l('Standard (5 steps)')), array('value' => PS_ORDER_PROCESS_OPC, 'name' => $this->l('One page checkout')));
     $round_mode = array(array('value' => PS_ROUND_UP, 'name' => $this->l('superior')), array('value' => PS_ROUND_DOWN, 'name' => $this->l('inferior')), array('value' => PS_ROUND_HALF, 'name' => $this->l('classical')));
     $cms_tab = array(0 => array('id' => 0, 'name' => $this->l('None')));
     foreach (CMS::listCms($cookie->id_lang) as $cms_file) {
         $cms_tab[] = array('id' => $cms_file['id_cms'], 'name' => $cms_file['meta_title']);
     }
     $this->_fieldsGeneral = array('PS_SHOP_ENABLE' => array('title' => $this->l('Enable Shop'), 'desc' => $this->l('Activate or deactivate your shop. Deactivate your shop while you perform maintenance on it. Please note that the webservice will not be disabled'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_MAINTENANCE_IP' => array('title' => $this->l('Maintenance IP'), 'desc' => $this->l('IP addresses allowed to access the Front Office even if shop is disabled. Use a comma to separate them (e.g., 42.24.4.2,127.0.0.1,99.98.97.96)'), 'validation' => 'isGenericName', 'type' => 'maintenance_ip', 'size' => 30, 'default' => ''), 'PS_SSL_ENABLED' => array('title' => $this->l('Enable SSL'), 'desc' => $this->l('If your hosting provider allows SSL, you can activate SSL encryption (https://) for customer account identification and order processing'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'default' => '0'), 'PS_COOKIE_CHECKIP' => array('title' => $this->l('Check IP on the cookie'), 'desc' => $this->l('Check the IP address of the cookie in order to avoid your cookie being stolen'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'default' => '0'), 'PS_COOKIE_LIFETIME_FO' => array('title' => $this->l('Lifetime of the Front Office cookie'), 'desc' => $this->l('Indicate the number of hours'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'text', 'default' => '480'), 'PS_COOKIE_LIFETIME_BO' => array('title' => $this->l('Lifetime of the Back Office cookie'), 'desc' => $this->l('Indicate the number of hours'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'text', 'default' => '480'), 'PS_TOKEN_ENABLE' => array('title' => $this->l('Increase Front Office security'), 'desc' => $this->l('Enable or disable token on the Front Office in order to improve PrestaShop security'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'default' => '0'), 'PS_HELPBOX' => array('title' => $this->l('Back Office help boxes'), 'desc' => $this->l('Enable yellow help boxes which are displayed under form fields in the Back Office'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_ORDER_PROCESS_TYPE' => array('title' => $this->l('Order process type'), 'desc' => $this->l('You can choose the order process type as either standard (5 steps) or One Page Checkout'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'select', 'list' => $order_process_type, 'identifier' => 'value'), 'PS_GUEST_CHECKOUT_ENABLED' => array('title' => $this->l('Enable guest checkout'), 'desc' => $this->l('Your guest can make an order without registering'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_CONDITIONS' => array('title' => $this->l('Terms of service'), 'desc' => $this->l('Require customers to accept or decline terms of service before processing the order'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'js' => array('on' => 'onchange="changeCMSActivationAuthorization()"', 'off' => 'onchange="changeCMSActivationAuthorization()"')), 'PS_CONDITIONS_CMS_ID' => array('title' => $this->l('Conditions of use of CMS page'), 'desc' => $this->l('Choose the Conditions of use of CMS page'), 'validation' => 'isInt', 'type' => 'select', 'list' => $cms_tab, 'identifier' => 'id', 'cast' => 'intval'), 'PS_GIFT_WRAPPING' => array('title' => $this->l('Offer gift-wrapping'), 'desc' => $this->l('Suggest gift-wrapping to customer and possibility of leaving a message'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_GIFT_WRAPPING_PRICE' => array('title' => $this->l('Gift-wrap pricing'), 'desc' => $this->l('Set a price for gift-wrapping'), 'validation' => 'isPrice', 'cast' => 'floatval', 'type' => 'price'), 'PS_GIFT_WRAPPING_TAX' => array('title' => $this->l('Gift-wrapping tax'), 'desc' => $this->l('Set a tax for gift-wrapping'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'select', 'list' => $taxes, 'identifier' => 'id'), 'PS_ATTACHMENT_MAXIMUM_SIZE' => array('title' => $this->l('Maximum attachment size'), 'desc' => $this->l('Set the maximum size of attached files (in Megabytes ).') . ' ' . $this->l('Maximum:') . ' ' . ((int) str_replace('M', '', ini_get('post_max_size')) > (int) str_replace('M', '', ini_get('upload_max_filesize')) ? ini_get('upload_max_filesize') : ini_get('post_max_size')), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'text', 'default' => '2'), 'PS_RECYCLABLE_PACK' => array('title' => $this->l('Offer recycled packaging'), 'desc' => $this->l('Suggest recycled packaging to customer'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_CART_FOLLOWING' => array('title' => $this->l('Save cart content and re-display it at login'), 'desc' => $this->l('Recall and display contents of shopping cart following customer login'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_PRICE_ROUND_MODE' => array('title' => $this->l('Round mode'), 'desc' => $this->l('You can choose how to round prices: always round superior; always round inferior, or classic rounding'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'select', 'list' => $round_mode, 'identifier' => 'value'), 'PRESTASTORE_LIVE' => array('title' => $this->l('Automatically check for module updates'), 'desc' => $this->l('New modules and updates are displayed on the modules page'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_HIDE_OPTIMIZATION_TIPS' => array('title' => $this->l('Hide optimization tips'), 'desc' => $this->l('Hide optimization tips on the back office homepage'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_DISPLAY_SUPPLIERS' => array('title' => $this->l('Display suppliers and manufacturers'), 'desc' => $this->l('Display manufacturers and suppliers list even if corresponding blocks are disabled'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_FORCE_SMARTY_2' => array('title' => $this->l('Use Smarty 2 instead of 3'), 'desc' => $this->l('Enable if your theme is incompatible with Smarty 3 (you should update your theme, since Smarty 2 will be unsupported from PrestaShop v1.5)'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_LIMIT_UPLOAD_FILE_VALUE' => array('title' => $this->l('Limit upload file value'), 'desc' => $this->l('Define the limit upload for a downloadable product, this value has to be inferior or equal to your server\'s maximum upload file ') . sprintf('(%s MB).', $upload_mb), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'limit', 'default' => '1'), 'PS_LIMIT_UPLOAD_IMAGE_VALUE' => array('title' => $this->l('Limit upload image value'), 'desc' => $this->l('Define the limit upload for an image, this value has to be inferior or equal to your server\'s maximum upload file ') . sprintf('(%s MB).', $upload_mb), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'limit', 'default' => '1'));
     if (function_exists('date_default_timezone_set')) {
         $this->_fieldsGeneral['PS_TIMEZONE'] = array('title' => $this->l('Time Zone:'), 'validation' => 'isAnything', 'type' => 'select', 'list' => $timezones, 'identifier' => 'name');
     }
     // No HTTPS activation if you haven't already.
     if (!Tools::usingSecureMode() && !_PS_SSL_ENABLED_) {
         $this->_fieldsGeneral['PS_SSL_ENABLED']['type'] = 'disabled';
         $this->_fieldsGeneral['PS_SSL_ENABLED']['disabled'] = '<a href="https://' . Tools::getShopDomainSsl() . Tools::safeOutput($_SERVER['REQUEST_URI']) . '">' . $this->l('Please click here to use HTTPS protocol before enabling SSL.') . '</a>';
     }
     parent::__construct();
 }
Exemple #12
0
 /**
  * Return the total of the item, with or without tax
  *
  * @param  boolean $includeTax Whether or not to include tax
  *
  * @return float              The total, as a float
  */
 public function total($includeTax = true)
 {
     $price = $this->price;
     if ($includeTax) {
         $price = $this->tax->add($price);
     }
     return (double) ($price * $this->quantity);
 }
Exemple #13
0
 public function getTotal()
 {
     $total = 0;
     foreach ($this->getProducts() as $product) {
         $total += $this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity'];
     }
     return $total;
 }
Exemple #14
0
 public function testGetAllTaxes()
 {
     $allTaxesCount = Tax::getTaxes()->getTotalRecordCount();
     $taxEnabled = Tax::getNewInstance('testing');
     $taxEnabled->save();
     $taxDisabled = Tax::getNewInstance('testing');
     $taxDisabled->save();
     $this->assertEqual(Tax::getTaxes()->getTotalRecordCount(), $allTaxesCount + 2);
 }
Exemple #15
0
 public function getTaxes()
 {
     if (!empty(self::$Tax) && is_array(self::$Tax) && count(self::$Tax) > 0) {
         return self::$Tax;
     } else {
         self::$Tax = $this->find('all', array('fields' => array('tax_name', 'tax_percentage')));
         return self::$Tax;
     }
 }
 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)));
 }
 public function GetPrice($objTaxCode, $intTaxStatus, $taxExclusive = false)
 {
     if ($taxExclusive) {
         return $this->price;
     } elseif (_xls_get_conf('TAX_INCLUSIVE_PRICING', '') == '1') {
         $arrPrice = Tax::calculatePricesWithTax($this->price, $objTaxCode->id, $intTaxStatus);
         return $arrPrice['fltSellTotalWithTax'];
     } else {
         return $this->price;
     }
 }
Exemple #18
0
 public function tax()
 {
     if (isset($this->amount->tax)) {
         return $this->amount->tax;
     } elseif (isset($this->order->shipping)) {
         $tax = new Tax($this->order->shipping->country, $this->order->shipping->state, $this->order->basket);
         $this->amount->tax = $tax->amount();
         return $this->amount->tax;
     } else {
         return 0;
     }
 }
Exemple #19
0
 /**
  * Update WEEE amounts discount percents
  *
  * @param   \Magento\Framework\Event\Observer $observer
  * @return  $this
  */
 public function updateDiscountPercents(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_weeeData->isEnabled()) {
         return $this;
     }
     $productCondition = $observer->getEvent()->getProductCondition();
     if ($productCondition) {
         $eventProduct = $productCondition;
     } else {
         $eventProduct = $observer->getEvent()->getProduct();
     }
     $this->_weeeTax->updateProductsDiscountPercent($eventProduct);
     return $this;
 }
Exemple #20
0
 function getPriceTax($priceset_id, $product_id, $netto, $tax_id = -1)
 {
     $query = "SELECT * FROM " . $this->db->price_table . " WHERE priceset_id='" . $priceset_id . "' AND product_id='" . $product_id . "'";
     $tmp = $this->db->fetchRows($this->db->query($query));
     $price = $tmp[0][3];
     if ($tax_id == -1) {
         $product = new Product();
         $tmp_product = $product->get($product_id);
         if (count($tmp_product) > 0) {
             $tax_id = $tmp_product[0][4];
         } else {
             return 0;
         }
     }
     if ($netto) {
         $tax = new Tax();
         $tmp_tax = $tax->get($tax_id);
         if (count($tmp_tax) <= 0) {
             return 0;
         }
         $price = $price * (1 + $tmp_tax[0][2]);
     }
     return $price;
 }
 /**
  * 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 __construct()
 {
     $this->className = 'Configuration';
     $this->table = 'configuration';
     parent::__construct();
     // List of CMS tabs
     $cms_tab = array(0 => array('id' => 0, 'name' => $this->l('None')));
     foreach (CMS::listCms($this->context->language->id) as $cms_file) {
         $cms_tab[] = array('id' => $cms_file['id_cms'], 'name' => $cms_file['meta_title']);
     }
     // List of order process types
     $order_process_type = array(array('value' => PS_ORDER_PROCESS_STANDARD, 'name' => $this->l('Standard (5 steps)')), array('value' => PS_ORDER_PROCESS_OPC, 'name' => $this->l('One page checkout')));
     // Tax list
     $taxes[] = array('id' => 0, 'name' => $this->l('None'));
     foreach (Tax::getTaxes($this->context->language->id) as $tax) {
         $taxes[] = array('id' => $tax['id_tax'], 'name' => $tax['name']);
     }
     $this->fields_options = array('general' => array('title' => $this->l('General'), 'icon' => 'tab-preferences', 'fields' => array('PS_ORDER_PROCESS_TYPE' => array('title' => $this->l('Order process type'), 'desc' => $this->l('You can choose the order process type as either standard (5 steps) or One Page Checkout'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'select', 'list' => $order_process_type, 'identifier' => 'value'), 'PS_GUEST_CHECKOUT_ENABLED' => array('title' => $this->l('Enable guest checkout'), 'desc' => $this->l('Guests can place an order without registering'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_PURCHASE_MINIMUM' => array('title' => $this->l('Minimum purchase total required in order to validate order'), 'desc' => $this->l('Set to 0 to disable this feature'), 'validation' => 'isFloat', 'cast' => 'floatval', 'type' => 'price'), 'PS_ALLOW_MULTISHIPPING' => array('title' => $this->l('Allow multi-shipping'), 'desc' => $this->l('Allow the customer to ship his order to multiple addresses. This option will convert the customer\'s cart into one or more orders.'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_SHIP_WHEN_AVAILABLE' => array('title' => $this->l('Delayed shipping'), 'desc' => $this->l('Allow the customer to split his order: one with the products currently "in stock", and another with the other products. This option will convert the customer\'s cart into two orders.'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_CONDITIONS' => array('title' => $this->l('Terms of service'), 'desc' => $this->l('Require customers to accept or decline terms of service before processing the order'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'js' => array('on' => 'onchange="changeCMSActivationAuthorization()"', 'off' => 'onchange="changeCMSActivationAuthorization()"')), 'PS_CONDITIONS_CMS_ID' => array('title' => $this->l('Conditions of use CMS page'), 'desc' => $this->l('Choose the Conditions of use CMS page'), 'validation' => 'isInt', 'type' => 'select', 'list' => $cms_tab, 'identifier' => 'id', 'cast' => 'intval'))), 'gift' => array('title' => $this->l('Gift options'), 'icon' => 'tab-preferences', 'fields' => array('PS_GIFT_WRAPPING' => array('title' => $this->l('Offer gift-wrapping'), 'desc' => $this->l('Suggest gift-wrapping to customer and possibility of leaving a message'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_GIFT_WRAPPING_PRICE' => array('title' => $this->l('Gift-wrapping price'), 'desc' => $this->l('Set a price for gift-wrapping'), 'validation' => 'isPrice', 'cast' => 'floatval', 'type' => 'price'), 'PS_GIFT_WRAPPING_TAX' => array('title' => $this->l('Gift-wrapping tax'), 'desc' => $this->l('Set a tax for gift-wrapping'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'select', 'list' => $taxes, 'identifier' => 'id'), 'PS_RECYCLABLE_PACK' => array('title' => $this->l('Offer recycled packaging'), 'desc' => $this->l('Suggest recycled packaging to customer'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool')), 'submit' => array('title' => $this->l('Save'), 'class' => 'button')));
 }
function convert_product_price()
{
    $taxes = Tax::getTaxes();
    $taxRates = array();
    foreach ($taxes as $data) {
        $taxRates[$data['id_tax']] = (double) $data['rate'] / 100;
    }
    $resource = DB::getInstance()->ExecuteS('SELECT `id_product`, `price`, `id_tax` FROM `' . _DB_PREFIX_ . 'product`', false);
    while ($row = DB::getInstance()->nextRow($resource)) {
        if ($row['id_tax']) {
            $price = $row['price'] * (1 + $taxRates[$row['id_tax']]);
            $decimalPart = $price - (int) $price;
            if ($decimalPart < 1.0E-6) {
                $newPrice = (double) number_format($price, 6, '.', '');
                $newPrice = Tools::floorf($newPrice / (1 + $taxRates[$row['id_tax']]), 6);
                DB::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'product` SET `price` = ' . $newPrice . ' WHERE `id_product` = ' . (int) $row['id_product']);
            }
        }
    }
}
Exemple #24
0
 public function __construct()
 {
     global $cookie;
     $this->className = 'Configuration';
     $this->table = 'configuration';
     $tmz = Tools::getTimezones();
     $txs = Tax::getTaxes(intval($cookie->id_lang));
     $timezone = array();
     foreach ($tmz as $id => $name) {
         $timezone[] = array('id' => $id, 'name' => $name);
     }
     $taxes[] = array('id' => 0, 'name' => $this->l('None'));
     foreach ($txs as $tax) {
         $taxes[] = array('id' => $tax['id_tax'], 'name' => $tax['name']);
     }
     $this->_fieldsGeneral = array('PS_BASE_URI' => array('title' => $this->l('PS directory:'), 'desc' => $this->l('Name of the PrestaShop directory on your Web server, bracketed by forward slashes (e.g., /shop/)'), 'validation' => 'isGenericName', 'type' => 'text', 'size' => 20, 'default' => '/'), 'PS_SHOP_ENABLE' => array('title' => $this->l('Enable Shop:'), 'desc' => $this->l('Activate or deactivate your shop. Deactivate your shop while you perform maintenance on it'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_MAINTENANCE_IP' => array('title' => $this->l('Maintenance IP:'), 'desc' => $this->l('IP address allowed to access the Front Office while the shop is disabled (e.g., 42.24.4.2)'), 'validation' => 'isGenericName', 'type' => 'text', 'size' => 15, 'default' => ''), 'PS_SSL_ENABLED' => array('title' => $this->l('Enable SSL'), 'desc' => $this->l('If your hosting provider allows SSL, you can activate SSL encryption (https://) for customer account identification and order processing'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'default' => '0'), 'PS_TOKEN_ENABLE' => array('title' => $this->l('Increase Front Office security'), 'desc' => $this->l('Enable or disable token on the Front Office in order to improve PrestaShop security'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'default' => '0'), 'PS_REWRITING_SETTINGS' => array('title' => $this->l('Friendly URL:'), 'desc' => $this->l('Enable only if your server allows URL rewriting (recommended)') . '<p class="hint clear" style="display: block;">' . $this->l('If you turn on this feature, you must') . ' <a href="?tab=AdminGenerator&token=' . Tools::getAdminToken('AdminGenerator' . intval(Tab::getIdFromClassName('AdminGenerator')) . intval($cookie->id_employee)) . '">' . $this->l('generate a .htaccess file') . '</a></p><div class="clear"></div>', 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_HELPBOX' => array('title' => $this->l('Back Office help boxes:'), 'desc' => $this->l('Enable yellow help boxes which are displayed under form fields in the Back Office'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_CONDITIONS' => array('title' => $this->l('Terms of service:'), 'desc' => $this->l('Require customers to accept or decline terms of service before processing the order'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_GIFT_WRAPPING' => array('title' => $this->l('Offer gift-wrapping:'), 'desc' => $this->l('Suggest gift-wrapping to customer and possibility of leaving a message'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_GIFT_WRAPPING_PRICE' => array('title' => $this->l('Gift-wrapping price:'), 'desc' => $this->l('Set a price for gift-wrapping'), 'validation' => 'isPrice', 'cast' => 'floatval', 'type' => 'price'), 'PS_GIFT_WRAPPING_TAX' => array('title' => $this->l('Gift-wrapping tax:'), 'desc' => $this->l('Set a tax for gift-wrapping'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'select', 'list' => $taxes, 'identifier' => 'id'), 'PS_RECYCLABLE_PACK' => array('title' => $this->l('Offer recycled packaging:'), 'desc' => $this->l('Suggest recycled packaging to customer'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_CART_FOLLOWING' => array('title' => $this->l('Cart re-display at login:'******'desc' => $this->l('After customer logs in, recall and display contents of his/her last shopping cart'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'));
     if (function_exists('date_default_timezone_set')) {
         $this->_fieldsGeneral['PS_TIMEZONE'] = array('title' => $this->l('Timezone:'), 'validation' => 'isUnsignedId', 'cast' => 'intval', 'type' => 'select', 'list' => $timezone, 'identifier' => 'id');
     }
     parent::__construct();
 }
 public function __construct()
 {
     global $cookie;
     $this->className = 'Configuration';
     $this->table = 'configuration';
     $timezones = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT name FROM ' . _DB_PREFIX_ . 'timezone');
     $taxes[] = array('id' => 0, 'name' => $this->l('None'));
     foreach (Tax::getTaxes((int) $cookie->id_lang) as $tax) {
         $taxes[] = array('id' => $tax['id_tax'], 'name' => $tax['name']);
     }
     $order_process_type = array(array('value' => PS_ORDER_PROCESS_STANDARD, 'name' => $this->l('Standard (5 steps)')), array('value' => PS_ORDER_PROCESS_OPC, 'name' => $this->l('One page checkout')));
     $round_mode = array(array('value' => PS_ROUND_UP, 'name' => $this->l('superior')), array('value' => PS_ROUND_DOWN, 'name' => $this->l('inferior')), array('value' => PS_ROUND_HALF, 'name' => $this->l('classical')));
     $cms_tab = array(0 => array('id' => 0, 'name' => $this->l('None')));
     foreach (CMS::listCms($cookie->id_lang) as $cms_file) {
         $cms_tab[] = array('id' => $cms_file['id_cms'], 'name' => $cms_file['meta_title']);
     }
     $this->_fieldsGeneral = array('PS_SHOP_ENABLE' => array('title' => $this->l('Enable Shop'), 'desc' => $this->l('Activate or deactivate your shop. Deactivate your shop while you perform maintenance on it. Please note that the webservice will not be disabled'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_MAINTENANCE_IP' => array('title' => $this->l('Maintenance IP'), 'desc' => $this->l('IP addresses allowed to access the Front Office even if shop is disabled. Use a comma to separate them (e.g., 42.24.4.2,127.0.0.1,99.98.97.96)'), 'validation' => 'isGenericName', 'type' => 'text', 'size' => 15, 'default' => ''), 'PS_SSL_ENABLED' => array('title' => $this->l('Enable SSL'), 'desc' => $this->l('If your hosting provider allows SSL, you can activate SSL encryption (https://) for customer account identification and order processing'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'default' => '0'), 'PS_COOKIE_CHECKIP' => array('title' => $this->l('Check IP on the cookie'), 'desc' => $this->l('Check the IP address of the cookie in order to avoid your cookie being stolen'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'default' => '0'), 'PS_TOKEN_ENABLE' => array('title' => $this->l('Increase Front Office security'), 'desc' => $this->l('Enable or disable token on the Front Office in order to improve PrestaShop security'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'default' => '0'), 'PS_HELPBOX' => array('title' => $this->l('Back Office help boxes'), 'desc' => $this->l('Enable yellow help boxes which are displayed under form fields in the Back Office'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_ORDER_PROCESS_TYPE' => array('title' => $this->l('Order process type'), 'desc' => $this->l('You can choose the order process type as either standard (5 steps) or One Page Checkout'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'select', 'list' => $order_process_type, 'identifier' => 'value'), 'PS_GUEST_CHECKOUT_ENABLED' => array('title' => $this->l('Enable guest checkout'), 'desc' => $this->l('Your guest can make an order without registering'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_CONDITIONS' => array('title' => $this->l('Terms of service'), 'desc' => $this->l('Require customers to accept or decline terms of service before processing the order'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool', 'js' => array('on' => 'onchange="changeCMSActivationAuthorization()"', 'off' => 'onchange="changeCMSActivationAuthorization()"')), 'PS_CONDITIONS_CMS_ID' => array('title' => $this->l('Conditions of use CMS page'), 'desc' => $this->l('Choose the Conditions of use CMS page'), 'validation' => 'isInt', 'type' => 'select', 'list' => $cms_tab, 'identifier' => 'id', 'cast' => 'intval'), 'PS_GIFT_WRAPPING' => array('title' => $this->l('Offer gift-wrapping'), 'desc' => $this->l('Suggest gift-wrapping to customer and possibility of leaving a message'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_GIFT_WRAPPING_PRICE' => array('title' => $this->l('Gift-wrapping price'), 'desc' => $this->l('Set a price for gift-wrapping'), 'validation' => 'isPrice', 'cast' => 'floatval', 'type' => 'price'), 'PS_GIFT_WRAPPING_TAX' => array('title' => $this->l('Gift-wrapping tax'), 'desc' => $this->l('Set a tax for gift-wrapping'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'select', 'list' => $taxes, 'identifier' => 'id'), 'PS_ATTACHMENT_MAXIMUM_SIZE' => array('title' => $this->l('Attachment maximum size'), 'desc' => $this->l('Set the maximum size of attachment files (in MegaBytes)'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'text'), 'PS_RECYCLABLE_PACK' => array('title' => $this->l('Offer recycled packaging'), 'desc' => $this->l('Suggest recycled packaging to customer'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_CART_FOLLOWING' => array('title' => $this->l('Cart re-display at login'), 'desc' => $this->l('After customer logs in, recall and display contents of his/her last shopping cart'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_PRICE_ROUND_MODE' => array('title' => $this->l('Round mode'), 'desc' => $this->l('You can choose how to round prices: always round superior; always round inferior, or classic rounding'), 'validation' => 'isInt', 'cast' => 'intval', 'type' => 'select', 'list' => $round_mode, 'identifier' => 'value'), 'PRESTASTORE_LIVE' => array('title' => $this->l('Automatically check for module updates'), 'desc' => $this->l('New modules and updates are displayed on the modules page'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_HIDE_OPTIMIZATION_TIPS' => array('title' => $this->l('Hide optimization tips'), 'desc' => $this->l('Hide optimization tips on the back office homepage'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_DISPLAY_SUPPLIERS' => array('title' => $this->l('Display suppliers and manufacturers'), 'desc' => $this->l('Display manufacturers and suppliers list even if corresponding blocks are disabled'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'), 'PS_FORCE_SMARTY_2' => array('title' => $this->l('Use Smarty 2 instead of 3'), 'desc' => $this->l('Enable if your theme is incompatible with Smarty 3 (you should update your theme, since Smarty 2 will be unsupported from PrestaShop v1.5)'), 'validation' => 'isBool', 'cast' => 'intval', 'type' => 'bool'));
     if (function_exists('date_default_timezone_set')) {
         $this->_fieldsGeneral['PS_TIMEZONE'] = array('title' => $this->l('Time Zone:'), 'validation' => 'isAnything', 'type' => 'select', 'list' => $timezones, 'identifier' => 'name');
     }
     parent::__construct();
 }
 function fix($bill_id)
 {
     $products = $this->getByBillId($bill_id);
     $product = new Product();
     $price = new Price();
     $tax = new Tax();
     $bill = new Bill();
     $tmp = $bill->get($bill_id);
     $bill_data = $tmp[0];
     $customer = new Customer();
     $tmp = $customer->get($bill_data[1]);
     $customer_data = $tmp[0];
     for ($i = 0; $i < count($products); $i++) {
         $tmp = $this->getByBillIdAndProductId($bill_id, $products[$i][2]);
         $bill_product_data = $tmp[0];
         $tmp = $product->get($products[$i][2]);
         $product_data = $tmp[0];
         $tmp = $price->getPrice($customer_data[11], $product_data[0]);
         $price_data = $tmp[0];
         $tmp = $tax->get($product_data[4]);
         $tax_data = $tmp[0];
         $this->update($bill_product_data[0], array($bill_product_data[1], $bill_product_data[2], $bill_product_data[3], $bill_product_data[4], $bill_product_data[5], $price_data[3], $tax_data[2]));
     }
 }
 /**
  * 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;
 }
Exemple #28
0
 function deleteAction()
 {
     $id = AF::get($_POST, 'id', 0);
     $modelsID = explode(',', $id);
     $errors = FALSE;
     foreach ($modelsID as $id) {
         $model = new Tax();
         $model->model_uset_id = $this->user->user_id;
         if ($model->fillFromDbPk($id)) {
             $model->delete($id);
         } else {
             $errors = TRUE;
         }
         if ($model->getErrors()) {
             $errors = TRUE;
         }
         unset($model);
     }
     if (isset($_POST['ajax'])) {
         AF::setJsonHeaders('json');
         if ($errors) {
             Message::echoJsonError(__('tax_not_deleted'));
         } else {
             $countE = AF::get($_POST, 'countE', 100000);
             // if the delete request came from an update page, we need to redirect
             if (count($modelsID) >= $countE || stripos($_SERVER['HTTP_REFERER'], 'taxes/update') !== false) {
                 $link = AF::link(array('taxes' => 'view'));
                 Message::echoJsonRedirect($link);
             } else {
                 Message::echoJsonSuccess(__('tax_deleted'));
             }
         }
     }
     $this->redirect('view');
     //$this->redirect();
 }
Exemple #29
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;
 }
    function displayFormInformations($obj, $currency, $languages, $defaultLanguage)
    {
        global $currentIndex, $cookie;
        $iso = Language::getIsoById(intval($cookie->id_lang));
        $divLangName = 'cname¤cdesc¤cdesc_short¤clink_rewrite¤cmeta_description¤cmeta_title¤cmeta_keywords¤ctags¤cavailable_now¤cavailable_later';
        $qty_state = 'readonly';
        $qty = Attribute::getAttributeQty($this->getFieldValue($obj, 'id_product'));
        if ($qty === false) {
            if (Validate::isLoadedObject($obj)) {
                $qty = $this->getFieldValue($obj, 'quantity');
            } else {
                $qty = 1;
            }
            $qty_state = '';
        }
        $cover = Product::getCover($obj->id);
        $link = new Link();
        //includeDatepicker(array('reduction_from', 'reduction_to'));
        echo '
		<div class="tab-page" id="step1">
			<h4 class="tab">1. ' . $this->l('Info.') . '</h4>
			<b>' . $this->l('Product global informations') . '</b>&nbsp;-&nbsp;';
        if (isset($obj->id)) {
            echo '
			<a href="' . $link->getProductLink($this->getFieldValue($obj, 'id'), $this->getFieldValue($obj, 'link_rewrite', $defaultLanguage), Category::getLinkRewrite($this->getFieldValue($obj, 'id_category_default'), intval($cookie->id_lang))) . '"><img src="../img/admin/details.gif" alt="' . $this->l('View product in shop') . '" title="' . $this->l('View product in shop') . '" /> ' . $this->l('View product in shop') . '</a>';
            if (file_exists(_PS_MODULE_DIR_ . 'statsproduct/statsproduct.php')) {
                echo '&nbsp;-&nbsp;
					<a href="index.php?tab=AdminStatsModules&module=statsproduct&id_product=' . $obj->id . '&token=' . Tools::getAdminToken('AdminStatsModules' . intval(Tab::getIdFromClassName('AdminStatsModules')) . intval($cookie->id_employee)) . '"><img src="../modules/statsproduct/logo.gif" alt="' . $this->l('View product sales') . '" title="' . $this->l('View product sales') . '" /> ' . $this->l('View product sales') . '</a>';
            }
        }
        echo '	
			<hr class="clear"/>
			<br />
				<table cellpadding="5" style="width:100%">
					<tr>
						<td class="col-left">' . $this->l('Name:') . '</td>
						<td style="padding-bottom:5px;">';
        foreach ($languages as $language) {
            echo '			<div id="cname_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;">
								<input size="55" type="text" id="name_' . $language['id_lang'] . '" name="name_' . $language['id_lang'] . '"
								value="' . stripslashes(htmlspecialchars($this->getFieldValue($obj, 'name', $language['id_lang']))) . '"' . (!$obj->id ? ' onkeyup="copy2friendlyURL();"' : '') . ' onchange="updateCurrentText();" /><sup> *</sup>
								<span class="hint" name="help_box">' . $this->l('Invalid characters:') . ' <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
							</div>';
        }
        $this->displayFlags($languages, $defaultLanguage, $divLangName, 'cname');
        echo '<script type="text/javascript">updateCurrentText();</script>
						</td>
					</tr>
					<tr>
						<td style="vertical-align:top">' . $this->l('Status:') . '</td>
						<td style="padding-bottom:5px;">
							<input style="float:left;" type="radio" name="active" id="active_on" value="1" ' . ($this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '') . '/>
							<label for="active_on" class="t"><img src="../img/admin/enabled.gif" alt="' . $this->l('Enabled') . '" title="' . $this->l('Enabled') . '" style="float:left; padding:0px 5px 0px 5px;" />' . $this->l('Enabled') . '</label>
							<br style="clear:both;" />
							<input style="float:left;" type="radio" name="active" id="active_off" value="0" ' . (!$this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '') . '/>
							<label for="active_off" class="t"><img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('Disabled') . '" style="float:left; padding:0px 5px 0px 5px" />' . $this->l('Disabled') . '</label>
						</td>
					</tr>
					<tr>
						<td>' . $this->l('Manufacturer:') . '</td>
						<td style="padding-bottom:5px;">
							<select name="id_manufacturer" id="id_manufacturer">
								<option value="0">-- ' . $this->l('Choose (optional)') . ' --</option>';
        if ($id_manufacturer = $this->getFieldValue($obj, 'id_manufacturer')) {
            echo '				<option value="' . $id_manufacturer . '" selected="selected">' . Manufacturer::getNameById($id_manufacturer) . '</option>
								<option disabled="disabled">----------</option>';
        }
        echo '
							</select>&nbsp;&nbsp;&nbsp;<a href="?tab=AdminManufacturers&addmanufacturer&token=' . Tools::getAdminToken('AdminManufacturers' . intval(Tab::getIdFromClassName('AdminManufacturers')) . intval($cookie->id_employee)) . '" onclick="return confirm(\'' . $this->l('Are you sure you want to delete entered product information?', __CLASS__, true, false) . '\');"><img src="../img/admin/add.gif" alt="' . $this->l('Create') . '" title="' . $this->l('Create') . '" /> <b>' . $this->l('Create') . '</b></a>
							<script type="text/javascript">
								var ajaxManufacturersClicked = false;
								$("select#id_manufacturer").focus(
									function() {
										if (ajaxManufacturersClicked == true) return; else ajaxManufacturersClicked = true;
										$.getJSON("' . dirname($currentIndex) . '/ajax.php",{ajaxProductManufacturers:1},
											function(j) {
												var options = \'\';
												for (var i = 0; i < getE("id_manufacturer").options.length; i++)
												{
													if (getE("id_manufacturer").options[i].innerHTML == \'----------\')
														options += \'<option disabled="disabled">----------</option>\';
													else
														options += \'<option value="\' +  getE("id_manufacturer").options[i].value + \'">\' + getE("id_manufacturer").options[i].innerHTML + \'</option>\';
												}
												for (var i = 0; i < j.length; i++)
													options += \'<option value="\' + j[i].optionValue + \'">\' + j[i].optionDisplay + \'</option>\';
												$("select#id_manufacturer").html(options);
											}
										)
									}
								);
							</script>
						</td>
					</tr>
					<tr>
						<td>' . $this->l('Supplier:') . '</td>
						<td style="padding-bottom:5px;">
							<select name="id_supplier" id="id_supplier">
								<option value="0">-- ' . $this->l('Choose (optional)') . ' --</option>';
        if ($id_supplier = $this->getFieldValue($obj, 'id_supplier')) {
            echo '				<option value="' . $id_supplier . '" selected="selected">' . Supplier::getNameById($id_supplier) . '</option>
								<option disabled="disabled">----------</option>';
        }
        echo '
							</select>&nbsp;&nbsp;&nbsp;<a href="?tab=AdminSuppliers&addsupplier&token=' . Tools::getAdminToken('AdminSuppliers' . intval(Tab::getIdFromClassName('AdminSuppliers')) . intval($cookie->id_employee)) . '" onclick="return confirm(\'' . $this->l('Are you sure you want to delete entered product information?', __CLASS__, true, false) . '\');"><img src="../img/admin/add.gif" alt="' . $this->l('Create') . '" title="' . $this->l('Create') . '" /> <b>' . $this->l('Create') . '</b></a>
							<script type="text/javascript">
								var ajaxSuppliersClicked = false;
								$("select#id_supplier").focus(
									function() {
										if (ajaxSuppliersClicked == true) return; else ajaxSuppliersClicked = true;
										$.getJSON("' . dirname($currentIndex) . '/ajax.php",{ajaxProductSuppliers:1},
											function(j) {
												var options = \'\';
												for (var i = 0; i < getE("id_supplier").options.length; i++)
												{
													if (getE("id_supplier").options[i].innerHTML == \'----------\')
														options += \'<option disabled="disabled">----------</option>\';
													else
														options += \'<option value="\' +  getE("id_supplier").options[i].value + \'">\' + getE("id_supplier").options[i].innerHTML + \'</option>\';
												}
												for (var i = 0; i < j.length; i++)
													options += \'<option value="\' + j[i].optionValue + \'">\' + j[i].optionDisplay + \'</option>\';
												$("select#id_supplier").html(options);
											}
										)
									}
								);
							</script>
						</td>
					</tr>
					<tr>
						<td class="col-left">' . $this->l('Reference:') . '</td>
						<td style="padding-bottom:5px;">
							<input size="55" type="text" name="reference" value="' . htmlentities($this->getFieldValue($obj, 'reference'), ENT_COMPAT, 'UTF-8') . '" style="width: 130px; margin-right: 44px;" />
							' . $this->l('EAN13:') . '<input size="55" maxlength="13" type="text" name="ean13" value="' . $this->getFieldValue($obj, 'ean13') . '" style="width: 110px; margin-left: 10px;" />
							<span class="hint" name="help_box">' . $this->l('Special characters allowed:') . ' .-_#\\<span class="hint-pointer">&nbsp;</span></span>
						</td>
					</tr>
                	<tr>
						<td class="col-left">' . $this->l('Supplier Reference:') . '</td>
						<td style="padding-bottom:5px;">
							<input size="55" type="text" name="supplier_reference" value="' . htmlentities($this->getFieldValue($obj, 'supplier_reference'), ENT_COMPAT, 'UTF-8') . '" style="width: 130px; margin-right: 44px;" />
							' . $this->l('Location:') . '<input size="55" type="text" name="location" value="' . $this->getFieldValue($obj, 'location') . '" style="width: 101px; margin-left: 10px;" />
							<span class="hint" name="help_box">' . $this->l('Special characters allowed:') . ' .-_#\\<span class="hint-pointer">&nbsp;</span></span>
						</td>
					</tr>					
					<tr>
						<td class="col-left">' . $this->l('Weight:') . '</td>
						<td style="padding-bottom:5px;">
							<input size="6" maxlength="6" name="weight" type="text" value="' . htmlentities($this->getFieldValue($obj, 'weight'), ENT_COMPAT, 'UTF-8') . '" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\');" /> ' . Configuration::get('PS_WEIGHT_UNIT') . '
						</td>
					</tr>
					<tr><td colspan="2"><hr style="width:730px;"></td></tr>';
        $this->displayPack($obj);
        echo '		<tr><td colspan="2"><hr style="width:730px;"></td></tr>';
        /*
         * Form for add a virtual product like software, mp3, etc...
         */
        $productDownload = new ProductDownload();
        if ($id_product_download = $productDownload->getIdFromIdProduct($this->getFieldValue($obj, 'id'))) {
            $productDownload = new ProductDownload($id_product_download);
        }
        ?>
    <script type="text/javascript">
    // <![CDATA[
    	ThickboxI18nImage = '<?php 
        echo $this->l('Image');
        ?>
';
    	ThickboxI18nOf = '<?php 
        echo $this->l('of');
        ?>
';;
    	ThickboxI18nClose = '<?php 
        echo $this->l('Close');
        ?>
';
    	ThickboxI18nOrEscKey = '<?php 
        echo $this->l('(or "Esc")');
        ?>
';
    	ThickboxI18nNext = '<?php 
        echo $this->l('Next >');
        ?>
';
    	ThickboxI18nPrev = '<?php 
        echo $this->l('< Previous');
        ?>
';
    	tb_pathToImage = '../img/loadingAnimation.gif';
    //]]>
    </script>
	<script type="text/javascript" src="<?php 
        echo _PS_JS_DIR_;
        ?>
jquery/thickbox-modified.js"></script>
	<script type="text/javascript" src="<?php 
        echo _PS_JS_DIR_;
        ?>
jquery/ajaxfileupload.js"></script>
	<script type="text/javascript" src="<?php 
        echo _PS_JS_DIR_;
        ?>
date.js"></script>
	<style type="text/css">
		<!--
		@import url(<?php 
        echo _PS_CSS_DIR_;
        ?>
thickbox.css);
		-->
	</style>
	<script type="text/javascript">
	<!--	
	function toggleVirtualProduct(elt)
	{
		if (elt.checked)
		{
			$('#virtual_good').show('slow');
			getE('out_of_stock_1').checked = 'checked';
			getE('out_of_stock_2').readOnly = true;
			getE('out_of_stock_3').readOnly = true;
			getE('label_out_of_stock_2').setAttribute('for', '');
			getE('label_out_of_stock_3').setAttribute('for', '');
		}
		else
		{
			$('#virtual_good').hide('slow');
			getE('out_of_stock_2').readOnly = false;
			getE('out_of_stock_3').readOnly = false;
			getE('label_out_of_stock_2').setAttribute('for', 'out_of_stock_2');
			getE('label_out_of_stock_3').setAttribute('for', 'out_of_stock_3');
		}
	}
	function uploadFile()
	{
		$.ajaxFileUpload (
			{
				url:'./uploadProductFile.php',
				secureuri:false,
				fileElementId:'virtual_product_file',
				dataType: 'xml',

				success: function (data, status)
				{
					data = data.getElementsByTagName('return')[0];
					var result = data.getAttribute("result");
					var msg = data.getAttribute("msg");
					var fileName = data.getAttribute("filename");

					if(result == "error")
					{
						$("#upload-confirmation").html('<p>error: ' + msg + '</p>');
					}
					else
					{
						$('#virtual_product_file').remove();
						$('#virtual_product_file_label').hide();
						$('#virtual_product_name').attr('value', fileName);
						$('#upload-confirmation').html(
							'<a class="link" href="get-file-admin.php?file=' + msg + '"><?php 
        echo $this->l('The file');
        ?>
&nbsp;"' + fileName + '"&nbsp;<?php 
        echo $this->l('has successfully been uploaded');
        ?>
</a>' +
							'<input type="hidden" id="virtual_product_filename" name="virtual_product_filename" value="' + msg + '" />');
					}
				}
			}
		);
	}

	-->
	</script>
	<?php 
        echo '
		<script type="text/javascript">
			var newLabel = \'' . $this->l('New label') . '\';
			var choose_language = \'' . $this->l('Choose language:') . '\';
			var required = \'' . $this->l('required') . '\';
			var customizationUploadableFileNumber = ' . intval($this->getFieldValue($obj, 'uploadable_files')) . ';
			var customizationTextFieldNumber = ' . intval($this->getFieldValue($obj, 'text_fields')) . ';
			var uploadableFileLabel = 0;
			var textFieldLabel = 0;
			var defaultLanguage = ' . intval($defaultLanguage) . ';
			var languages = new Array();';
        $i = 0;
        foreach ($languages as $language) {
            echo 'languages[' . $i++ . '] = new Array(' . intval($language['id_lang']) . ', \'' . $language['iso_code'] . '\', \'' . htmlentities($language['name'], ENT_COMPAT, 'UTF-8') . '\');' . "\n";
        }
        echo '
		</script>';
        ?>
	<tr>
		<td colspan="2">
			<input type="checkbox" id="is_virtual_good" name="is_virtual_good" value="true" onchange="toggleVirtualProduct(this)" onclick="toggleVirtualProduct(this);" <?php 
        if (($productDownload->id or Tools::getValue('is_virtual_good') == 'true') and $productDownload->active) {
            echo 'checked="checked"';
        }
        ?>
 />
			<label for="is_virtual_good" class="t bold"><?php 
        echo $this->l('Is this a downloadable product?');
        ?>
</label>
			<div id="virtual_good" <?php 
        if (!$productDownload->id or !$productDownload->active) {
            echo 'style="display:none;"';
        }
        ?>
 >
	<?php 
        if (!ProductDownload::checkWritableDir()) {
            ?>
		<p class="alert">
			<?php 
            echo $this->l('Your download repository is not writable.');
            ?>
<br/>
			<?php 
            echo realpath(_PS_DOWNLOAD_DIR_);
            ?>
		</p>
	<?php 
        } else {
            ?>
			<?php 
            if ($productDownload->id) {
                echo '<input type="hidden" id="virtual_product_id" name="virtual_product_id" value="' . $productDownload->id . '" />';
            }
            ?>
				<p class="block">
	<?php 
            if (!$productDownload->checkFile()) {
                ?>
		<?php 
                if ($productDownload->id) {
                    ?>
					<p class="alert">
						<?php 
                    echo $this->l('This product is missing');
                    ?>
:<br/>
						<?php 
                    echo realpath(_PS_DOWNLOAD_DIR_) . '/' . $productDownload->physically_filename;
                    ?>
					</p>
		<?php 
                }
                ?>
					<p><?php 
                echo $this->l('Your server\'s maximum upload file size is') . ':&nbsp;' . ini_get('upload_max_filesize');
                ?>
</p>
					<?php 
                if (!strval(Tools::getValue('virtual_product_filename'))) {
                    ?>
					<label id="virtual_product_file_label" for="virtual_product_file" class="t"><?php 
                    echo $this->l('Upload a file');
                    ?>
</label>
					<input type="file" id="virtual_product_file" name="virtual_product_file" value="" class="" onchange="uploadFile()" maxlength="<?php 
                    echo $this->maxFileSize;
                    ?>
" />
					<?php 
                }
                ?>
					<div id="upload-confirmation">
					<?php 
                if ($up_filename = strval(Tools::getValue('virtual_product_filename'))) {
                    ?>
						<input type="hidden" id="virtual_product_filename" name="virtual_product_filename" value="<?php 
                    echo $up_filename;
                    ?>
" />
					<?php 
                }
                ?>
					</div>
	<?php 
            } else {
                ?>
					<input type="hidden" id="virtual_product_filename" name="virtual_product_filename" value="<?php 
                echo $productDownload->physically_filename;
                ?>
" />
					<?php 
                echo $this->l('This is the link') . ':&nbsp;' . $productDownload->getHtmlLink(false, true);
                ?>
					<a href="confirm.php?height=200&amp;width=300&amp;modal=true&amp;referer=<?php 
                echo rawurlencode($_SERVER['REQUEST_URI'] . '&deleteVirtualProduct=true');
                ?>
" class="thickbox red" title="<?php 
                echo $this->l('Delete this file');
                ?>
"><?php 
                echo $this->l('Delete this file');
                ?>
</a>
	<?php 
            }
            // check if file exists
            ?>
				</p>
				<p class="block">
					<label for="virtual_product_name" class="t"><?php 
            echo $this->l('Filename');
            ?>
</label>
					<input type="text" id="virtual_product_name" name="virtual_product_name" class="" value="<?php 
            echo $productDownload->id > 0 ? $productDownload->display_filename : htmlentities(Tools::getValue('virtual_product_name'), ENT_COMPAT, 'UTF-8');
            ?>
" />
					<span class="hint" name="help_box" style="display:none;"><?php 
            echo $this->l('The complete filename with its extension (e.g., Our best song.mp3)');
            ?>
</span>
				</p>
				<p class="block">
					<label for="virtual_product_nb_downloable" class="t"><?php 
            echo $this->l('Number of downloads');
            ?>
</label>
					<input type="text" id="virtual_product_nb_downloable" name="virtual_product_nb_downloable" value="<?php 
            echo $productDownload->id > 0 ? $productDownload->nb_downloadable : htmlentities(Tools::getValue('virtual_product_nb_downloable'), ENT_COMPAT, 'UTF-8');
            ?>
" class="" size="6" />
					<span class="hint" name="help_box" style="display:none"><?php 
            echo $this->l('Number of authorized downloads per customer');
            ?>
</span>
				</p>
				<p class="block">
					<label for="virtual_product_expiration_date" class="t"><?php 
            echo $this->l('Expiration date');
            ?>
</label>
					<input type="text" id="virtual_product_expiration_date" name="virtual_product_expiration_date" value="<?php 
            echo $productDownload->id > 0 ? (!empty($productDownload->date_expiration) and $productDownload->date_expiration != '0000-00-00 00:00:00') ? date('Y-m-d', strtotime($productDownload->date_expiration)) : '' : htmlentities(Tools::getValue('virtual_product_expiration_date'), ENT_COMPAT, 'UTF-8');
            ?>
" size="11" maxlength="10" autocomplete="off" /> <?php 
            echo $this->l('Format: YYYY-MM-DD');
            ?>
					<span class="hint" name="help_box" style="display:none"><?php 
            echo $this->l('No expiration date if you leave this blank');
            ?>
</span>
				</p>
				<p class="block">
					<label for="virtual_product_nb_days" class="t"><?php 
            echo $this->l('Number of days');
            ?>
</label>
					<input type="text" id="virtual_product_nb_days" name="virtual_product_nb_days" value="<?php 
            echo $productDownload->id > 0 ? $productDownload->nb_days_accessible : htmlentities(Tools::getValue('virtual_product_nb_days'), ENT_COMPAT, 'UTF-8');
            ?>
" class="" size="4" /><sup> *</sup>
					<span class="hint" name="help_box" style="display:none"><?php 
            echo $this->l('How many days this file can be accessed by customers');
            ?>
</span>
				</p>
	<?php 
        }
        // check if download directory is writable
        ?>
			</div>
		</td>
	</tr>
	<tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:730px;"></td></tr>
	<script type="text/javascript">
		if ($('#is_virtual_good').attr('checked'))
			$('#virtual_good').show('slow');
	</script>

<?php 
        echo '
					<tr>
						<td class="col-left">' . $this->l('Pre-tax wholesale price:') . '</td>
						<td style="padding-bottom:5px;">
							' . ($currency->format == 1 ? $currency->sign . ' ' : '') . '<input size="11" maxlength="14" name="wholesale_price" type="text" value="' . htmlentities($this->getFieldValue($obj, 'wholesale_price'), ENT_COMPAT, 'UTF-8') . '" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\');" />' . ($currency->format == 2 ? ' ' . $currency->sign : '') . '
							<span style="margin-left:10px">' . $this->l('The wholesale price at which you bought this product') . '</span>
						</td>
					</tr>';
        echo '
					<tr>
						<td class="col-left">' . $this->l('Pre-tax retail price:') . '</td>
						<td style="padding-bottom:5px;">
							' . ($currency->format == 1 ? $currency->sign . ' ' : '') . '<input size="11" maxlength="14" id="priceTE" name="price" type="text" value="' . $this->getFieldValue($obj, 'price') . '" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\'); calcPriceTI();" />' . ($currency->format == 2 ? ' ' . $currency->sign : '') . '<sup> *</sup>
							<span style="margin-left:2px">' . $this->l('The pre-tax retail price to sell this product') . '</span>
						</td>
					</tr>';
        $taxes = Tax::getTaxes(intval($cookie->id_lang));
        echo '<script type="text/javascript">';
        echo 'noTax = ' . (Tax::excludeTaxeOption() ? 'true' : 'false'), ";\n";
        echo 'taxesArray = new Array ();' . "\n";
        echo 'taxesArray[0] = 0', ";\n";
        foreach ($taxes as $k => $tax) {
            echo 'taxesArray[' . $tax['id_tax'] . ']=' . $tax['rate'] . "\n";
        }
        echo '
					</script>';
        echo '
					<tr>
						<td class="col-left">' . $this->l('Tax:') . '</td>
						<td style="padding-bottom:5px;">
							<select onChange="javascript:calcPriceTI();" name="id_tax" id="id_tax" ' . (Tax::excludeTaxeOption() ? 'disabled="disabled"' : '') . '>
								<option value="0"' . ($this->getFieldValue($obj, 'id_tax') == 0 ? ' selected="selected"' : '') . '>' . $this->l('No tax') . '</option>';
        foreach ($taxes as $k => $tax) {
            echo '
								<option value="' . $tax['id_tax'] . '"' . ($this->getFieldValue($obj, 'id_tax') == $tax['id_tax'] ? ' selected="selected"' : '') . '>' . stripslashes($tax['name']) . ' (' . $tax['rate'] . '%)</option>';
        }
        echo '
							</select>';
        if (Tax::excludeTaxeOption()) {
            echo '<span style="margin-left:10px; color:red;">' . $this->l('Taxes are currently disabled') . '</span> (<b><a href="index.php?tab=AdminTaxes&token=' . Tools::getAdminToken('AdminTaxes' . intval(Tab::getIdFromClassName('AdminTaxes')) . intval($cookie->id_employee)) . '">' . $this->l('Tax options') . '</a></b>)';
            echo '<input type="hidden" value="' . intval($this->getFieldValue($obj, 'id_tax')) . '" name="id_tax" />';
        }
        echo '</td>
					</tr>
					<tr>
						<td class="col-left">' . $this->l('Retail price with tax:') . '</td>
						<td style="padding-bottom:5px;">
							' . ($currency->format == 1 ? ' ' . $currency->sign : '') . ' <input size="11" maxlength="14" id="priceTI" type="text" value="" onKeyUp="noComma(\'priceTI\'); calcPriceTE();" />' . ($currency->format == 2 ? ' ' . $currency->sign : '') . '
							<span style="margin-left:10px">
						</td>
					</tr>
					<tr>
						<td class="col-left">' . $this->l('Eco-tax:') . '</td>
						<td style="padding-bottom:5px;">
							' . ($currency->format == 1 ? $currency->sign . ' ' : '') . '<input size="11" maxlength="14" id="ecotax" name="ecotax" type="text" value="' . $this->getFieldValue($obj, 'ecotax') . '" onKeyUp="javascript:this.value = this.value.replace(/,/g, \'.\'); if (parseInt(this.value) > getE(\'priceTE\').value) this.value = getE(\'priceTE\').value; if (isNaN(this.value)) this.value = 0;" />' . ($currency->format == 2 ? ' ' . $currency->sign : '') . '
							<span style="margin-left:10px">(' . $this->l('already included in price') . ')</span>
						</td>
					</tr>
					<tr>
						<td class="col-left">' . $this->l('Reduction amount:') . '</td>
						<td style="padding-bottom:5px;">
							' . ($currency->format == 1 ? ' ' . $currency->sign . ' ' : '') . '<input size="11" maxlength="14" type="text" name="reduction_price" id="reduction_price" value="' . $this->getFieldValue($obj, 'reduction_price') . '" onkeyup="javascript:this.value = this.value.replace(/,/g, \'.\'); var key = window.event ? window.event.keyCode : event.which; if (key != 9) reductionPrice();" /> ' . ($currency->format == 2 ? ' ' . $currency->sign : '') . '
							<span style="padding-right: 15px; padding-left: 15px; font-weight: bold">' . $this->l('OR') . '</span>
							<input size="10" maxlength="14" type="text" name="reduction_percent" id="reduction_percent" value="' . $this->getFieldValue($obj, 'reduction_percent') . '" onkeyup="javascript:this.value = this.value.replace(/,/g, \'.\'); var key = window.event ? window.event.keyCode : event.which; if (key != 9) reductionPercent();" /> %
						</td>
					</tr>
					<tr>
						<td class="col-left">&nbsp;</td>
						<td>' . $this->l('available from') . ' <input type="text" id="reduction_from" name="reduction_from" value="' . (($from = $this->getFieldValue($obj, 'reduction_from') and $from != '0000-00-00' and $from != '1942-01-01') ? $from : date('Y-m-d')) . '" />
							' . $this->l('to') . ' <input type="text" id="reduction_to" name="reduction_to" value="' . (($to = $this->getFieldValue($obj, 'reduction_to') and $to != '0000-00-00' and $to != '1942-01-01') ? $to : date('Y-m-d')) . '" />
							<p>' . $this->l('Leave same dates for undefined duration') . '</p>
						</td>
					</tr>
					<tr>
						<td class="col-left">&nbsp;</td>
						<td style="padding-bottom:5px;">
							<input type="checkbox" name="on_sale" id="on_sale" style="padding-top: 5px;" ' . ($this->getFieldValue($obj, 'on_sale') ? 'checked="checked"' : '') . 'value="1" />&nbsp;<label for="on_sale" class="t">' . $this->l('Display "on sale" icon on product page and text on product listing') . '</label>
						</td>
					</tr>
					<tr>
						<td class="col-left"><b>' . $this->l('Final retail price:') . '</b></td>
						<td style="padding-bottom:5px;">
							' . ($currency->format == 1 ? $currency->sign . ' ' : '') . '<span id="finalPrice" style="font-weight: bold;"></span>' . ($currency->format == 2 ? ' ' . $currency->sign : '') . '
						</td>
					</tr>
					<tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:730px;"></td></tr>
					<tr>
						<td class="col-left">' . $this->l('Quantity:') . '</td>
						<td style="padding-bottom:5px;"><input size="3" maxlength="6" ' . $qty_state . ' name="quantity" type="text" value="' . $qty . '" ' . ((isset($_POST['attQty']) and $_POST['attQty']) ? 'onclick="alert(\'' . $this->l('Quantity is already defined by Attributes') . '.<br />' . $this->l('Delete attributes first') . '.\');" readonly="readonly" ' : '') . '/><sup> *</sup>
					</tr>
					<tr>
						<td class="col-left">' . $this->l('Displayed text when in-stock:') . '</td>
						<td style="padding-bottom:5px;">';
        foreach ($languages as $language) {
            echo '
							<div id="cavailable_now_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;">
								<input size="30" type="text" id="available_now_' . $language['id_lang'] . '" name="available_now_' . $language['id_lang'] . '"
								value="' . stripslashes(htmlentities($this->getFieldValue($obj, 'available_now', $language['id_lang']), ENT_COMPAT, 'UTF-8')) . '" />
								<span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
							</div>';
        }
        $this->displayFlags($languages, $defaultLanguage, $divLangName, 'cavailable_now');
        echo '			</td>
					</tr>
					<tr>
						<td class="col-left">' . $this->l('Displayed text when allowed to be back-ordered:') . '</td>
						<td style="padding-bottom:5px;">';
        foreach ($languages as $language) {
            echo '
							<div id="cavailable_later_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;">
								<input size="30" type="text" id="available_later_' . $language['id_lang'] . '" name="available_later_' . $language['id_lang'] . '"
								value="' . stripslashes(htmlentities($this->getFieldValue($obj, 'available_later', $language['id_lang']), ENT_COMPAT, 'UTF-8')) . '" />
								<span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
							</div>';
        }
        $this->displayFlags($languages, $defaultLanguage, $divLangName, 'cavailable_later');
        echo '			</td>
					</tr>

					<script type="text/javascript" src="../js/price.js"></script>
					<script type="text/javascript">
						calcPriceTI();
					</script>

					<tr>
						<td class="col-left">' . $this->l('When out of stock:') . '</td>
						<td style="padding-bottom:5px;">
							<input type="radio" name="out_of_stock" id="out_of_stock_1" value="0" ' . (intval($this->getFieldValue($obj, 'out_of_stock')) == 0 ? 'checked="checked"' : '') . '/> <label for="out_of_stock_1" class="t" id="label_out_of_stock_1">' . $this->l('Deny orders') . '</label>
							<br /><input type="radio" name="out_of_stock" id="out_of_stock_2" value="1" ' . ($this->getFieldValue($obj, 'out_of_stock') == 1 ? 'checked="checked"' : '') . '/> <label for="out_of_stock_2" class="t" id="label_out_of_stock_2">' . $this->l('Allow orders') . '</label>
							<br /><input type="radio" name="out_of_stock" id="out_of_stock_3" value="2" ' . ($this->getFieldValue($obj, 'out_of_stock') == 2 ? 'checked="checked"' : '') . '/> <label for="out_of_stock_3" class="t" id="label_out_of_stock_3">' . $this->l('Default:') . ' <i>' . $this->l(intval(Configuration::get('PS_ORDER_OUT_OF_STOCK')) ? 'Allow orders' : 'Deny orders') . '</i> (' . $this->l('as set in') . ' <a href="index.php?tab=AdminPPreferences&token=' . Tools::getAdminToken('AdminPPreferences' . intval(Tab::getIdFromClassName('AdminPPreferences')) . intval($cookie->id_employee)) . '"  onclick="return confirm(\'' . $this->l('Are you sure you want to delete entered product information?', __CLASS__, true, false) . '\');">' . $this->l('Preferences') . '</a>)</label>
						</td>
					</tr>

					<tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:730px;"></td></tr>
					<tr>
						<td class="col-left"><label for="id_category_default" class="t">' . $this->l('Default category:') . '</label></td>
						<td>
							<select id="id_category_default" name="id_category_default" onchange="checkDefaultCategory(this.value);">';
        $categories = Category::getCategories(intval($cookie->id_lang), false);
        Category::recurseCategory($categories, $categories[0][1], 1, $this->getFieldValue($obj, 'id_category_default') ? $this->getFieldValue($obj, 'id_category_default') : Tools::getValue('id_category', 1));
        echo '
							</select>
						</td>
					</tr>
					<tr>
						<td class="col-left">' . $this->l('Catalog:') . '</td>
						<td>
							<div style="overflow: auto; min-height: 300px; padding-top: 0.6em;" id="categoryList">
							<table cellspacing="0" cellpadding="0" class="table">
									<tr>
										<th><input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, \'categoryBox[]\', this.checked)" /></th>
										<th>' . $this->l('ID') . '</th>
										<th style="width: 400px">' . $this->l('Name') . '</th>
									</tr>';
        $done = array();
        $index = array();
        $indexedCategories = isset($_POST['categoryBox']) ? $_POST['categoryBox'] : ($obj->id ? Product::getIndexedCategories($obj->id) : array());
        foreach ($indexedCategories as $k => $row) {
            $index[] = $row['id_category'];
        }
        $this->recurseCategoryForInclude($index, $categories, $categories[0][1], 1, $obj->id_category_default);
        echo '
							</table>
							<p style="padding:0px; margin:0px 0px 10px 0px;">' . $this->l('Mark all checkbox(es) of categories in which product is to appear') . '<sup> *</sup></p>
							</div>
						</td>
					</tr>
					<tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:730px;"></td></tr>
					<tr><td colspan="2">
						<span onclick="javascript:openCloseLayer(\'seo\');" style="cursor: pointer"><img src="../img/admin/arrow.gif" alt="' . $this->l('SEO') . '" title="' . $this->l('SEO') . '" style="float:left; margin-right:5px;"/>' . $this->l('Click here to improve product\'s rank in search engines (SEO)') . '</span><br />
						<div id="seo" style="display: none; padding-top: 15px;">
							<table>
								<tr>
									<td class="col-left">' . $this->l('Meta title:') . '</td>
									<td>';
        foreach ($languages as $language) {
            echo '
										<div id="cmeta_title_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;">
											<input size="55" type="text" id="meta_title_' . $language['id_lang'] . '" name="meta_title_' . $language['id_lang'] . '"
											value="' . htmlentities($this->getFieldValue($obj, 'meta_title', $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" />
											<span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
										</div>';
        }
        $this->displayFlags($languages, $defaultLanguage, $divLangName, 'cmeta_title');
        echo '
										<p style="clear: both">' . $this->l('Product page title; leave blank to use product name') . '</p>
									</td>
								</tr>
								<tr>
									<td class="col-left">' . $this->l('Meta description:') . '</td>
									<td>';
        foreach ($languages as $language) {
            echo '
										<div id="cmeta_description_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;">
											<input size="55" type="text" id="meta_description_' . $language['id_lang'] . '" name="meta_description_' . $language['id_lang'] . '"
											value="' . htmlentities($this->getFieldValue($obj, 'meta_description', $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" />
											<span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
										</div>';
        }
        $this->displayFlags($languages, $defaultLanguage, $divLangName, 'cmeta_description');
        echo '
										<p style="clear: both">' . $this->l('A single sentence for HTML header') . '</p>
									</td>
								</tr>
								<tr>
									<td class="col-left">' . $this->l('Meta keywords:') . '</td>
									<td>';
        foreach ($languages as $language) {
            echo '
										<div id="cmeta_keywords_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;">
											<input size="55" type="text" id="meta_keywords_' . $language['id_lang'] . '" name="meta_keywords_' . $language['id_lang'] . '"
											value="' . htmlentities($this->getFieldValue($obj, 'meta_keywords', $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" />
											<span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
										</div>';
        }
        $this->displayFlags($languages, $defaultLanguage, $divLangName, 'cmeta_keywords');
        echo '
										<p style="clear: both">' . $this->l('Keywords for HTML header, separated by a comma') . '</p>
									</td>
								</tr>
								<tr>
									<td class="col-left">' . $this->l('Friendly URL:') . '</td>
									<td>';
        foreach ($languages as $language) {
            echo '
										<div id="clink_rewrite_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;">
											<input size="55" type="text" id="link_rewrite_' . $language['id_lang'] . '" name="link_rewrite_' . $language['id_lang'] . '"
											value="' . htmlentities($this->getFieldValue($obj, 'link_rewrite', $language['id_lang']), ENT_COMPAT, 'UTF-8') . '" onkeyup="this.value = str2url(this.value); updateFriendlyURL();" /><sup> *</sup>
											<span class="hint" name="help_box">' . $this->l('Only letters and the "less" character are allowed') . '<span class="hint-pointer">&nbsp;</span></span>
										</div>';
        }
        $this->displayFlags($languages, $defaultLanguage, $divLangName, 'clink_rewrite');
        global $cookie;
        $iso = Language::getIsoById(intval($cookie->id_lang));
        echo '
										<p style="clear: both; width: 360px; word-wrap: break-word; overflow: auto;">' . $this->l('Product link will look like this:') . ' ' . (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . '/id_product-<span id="friendly-url"></span>.html</p>
									</td>
								</tr>
								<script type="text/javascript">updateFriendlyURL();</script>';
        echo '</td></tr></table>
						</div>
					</td></tr>
					<tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:730px;"></td></tr>
					<tr>
						<td class="col-left">' . $this->l('Short description:') . '<br /><br /><i>(' . $this->l('appears in search results') . ')</i></td>
						<td style="padding-bottom:5px;">';
        foreach ($languages as $language) {
            echo '
							<div id="cdesc_short_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . ';float: left;">
								<textarea class="rte" cols="100" rows="10" id="description_short_' . $language['id_lang'] . '" name="description_short_' . $language['id_lang'] . '">' . htmlentities(stripslashes($this->getFieldValue($obj, 'description_short', $language['id_lang'])), ENT_COMPAT, 'UTF-8') . '</textarea>
							</div>';
        }
        $this->displayFlags($languages, $defaultLanguage, $divLangName, 'cdesc_short');
        echo '
						</td>
					</tr>
					<tr>
						<td class="col-left">' . $this->l('Description:') . '</td>
						<td style="padding-bottom:5px;">';
        foreach ($languages as $language) {
            echo '
							<div id="cdesc_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . ';float: left;">
								<textarea class="rte" cols="100" rows="20" id="description_' . $language['id_lang'] . '" name="description_' . $language['id_lang'] . '">' . htmlentities(stripslashes($this->getFieldValue($obj, 'description', $language['id_lang'])), ENT_COMPAT, 'UTF-8') . '</textarea>
							</div>';
        }
        $this->displayFlags($languages, $defaultLanguage, $divLangName, 'cdesc');
        echo '
						</td>
					</tr>';
        echo '<tr><td class="col-left">' . $this->l('Tags:') . '</td><td style="padding-bottom:5px;">';
        foreach ($languages as $language) {
            echo '<div id="ctags_' . $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;">
							<input size="55" type="text" id="tags_' . $language['id_lang'] . '" name="tags_' . $language['id_lang'] . '"
							value="' . htmlentities(Tools::getValue('tags_' . $language['id_lang'], $obj->getTags($language['id_lang'], true)), ENT_COMPAT, 'UTF-8') . '" />
							<span class="hint" name="help_box">' . $this->l('Forbidden characters:') . ' !<>;?=+#"&deg;{}_$%<span class="hint-pointer">&nbsp;</span></span>
						  </div>';
        }
        $this->displayFlags($languages, $defaultLanguage, $divLangName, 'ctags');
        echo '<p style="clear: both">' . $this->l('Tags separated by commas (e.g., dvd, dvd player, hifi)') . '</p>';
        echo '</td>
					</tr>';
        $accessories = Product::getAccessoriesLight(intval($cookie->id_lang), $obj->id);
        if ($postAccessories = Tools::getValue('inputAccessories')) {
            $postAccessoriesTab = explode('-', Tools::getValue('inputAccessories'));
            foreach ($postAccessoriesTab as $accessoryId) {
                if (!$this->haveThisAccessory($accessoryId, $accessories) and $accessory = Product::getAccessoryById($accessoryId)) {
                    $accessories[] = $accessory;
                }
            }
        }
        echo '
					<tr>
						<td class="col-left">' . $this->l('Accessories:') . '<br /><br /><i>' . $this->l('(Do not forget to Save the product afterward)') . '</i></td>
						<td style="padding-bottom:5px;">
							<div id="divAccessories">';
        foreach ($accessories as $accessory) {
            echo $accessory['name'] . '<span onclick="delAccessory(' . $accessory['id_product'] . ');" style="cursor: pointer;"><img src="../img/admin/delete.gif" /></span><br />';
        }
        echo '</div>
							<input type="hidden" name="inputAccessories" id="inputAccessories" value="';
        foreach ($accessories as $accessory) {
            echo $accessory['id_product'] . '-';
        }
        echo '" />
							<input type="hidden" name="nameAccessories" id="nameAccessories" value="';
        foreach ($accessories as $accessory) {
            echo $accessory['name'] . '¤';
        }
        echo '" />
							<script type="text/javascript">
								var formProduct;
								var accessories = new Array();
								
								function fillAccessories()
								{
									$.getJSON("' . dirname($currentIndex) . '/ajax.php",{ajaxProductAccessories:1,id_lang:' . intval($cookie->id_lang) . ',id_product:' . ($obj->id ? intval($obj->id) : 0) . '},
										function(j)
										{
											for (var i = 0; i < j.length; i++)
												accessories[i] = new Array(j[i].value, j[i].text);
												
											formProduct = document.layers ? document.forms.product : document.product;
											formProduct.selectAccessories.length = accessories.length + 1;
											for (i = 0, j = 1; i < accessories.length; i++)
											{
												if (formProduct.filter.value)
													if (accessories[i][1].toLowerCase().indexOf(formProduct.filter.value.toLowerCase()) == -1)
														continue;
												formProduct.selectAccessories.options[j].value = accessories[i][0];
												formProduct.selectAccessories.options[j].text = accessories[i][1];
												j++;
											}
											if (j == 1)
											{
												formProduct.selectAccessories.length = 2;
												formProduct.selectAccessories.options[1].value = -1;
												formProduct.selectAccessories.options[1].text = \'' . $this->l('No match found') . '\';
												formProduct.selectAccessories.options.selectedIndex = 1;
											}
											else
											{
												formProduct.selectAccessories.length = j;
												formProduct.selectAccessories.options.selectedIndex = (formProduct.filter.value == \'\' ? 0 : 1);
											}
										}
									);
								}
							</script>
							<select id="selectAccessories" name="selectAccessories" style="width: 380px;">
								<option value="0" selected="selected">-- ' . $this->l('Choose') . ' --</option>
							</select>
							<script type="text/javascript">
								fillAccessories();
							</script>
							<span onclick="addAccessory();" style="cursor: pointer;"><img src="../img/admin/add.gif" alt="' . $this->l('Add an accessory') . '" title="' . $this->l('Add an accessory') . '" /></span>
							<br />' . $this->l('Filter:') . ' <input type="text" size="25" name="filter" onkeyup="fillAccessories();" class="space" />
						</td>
					</tr>
					<tr><td colspan="2" style="padding-bottom:10px;"><hr style="width:730px;"></td></tr>
					<tr>
						<td colspan="2" style="text-align:center;">
							<input type="submit" value="' . $this->l('Save') . '" name="submitAdd' . $this->table . '" class="button" />
							&nbsp;<input type="submit" value="' . $this->l('Save and stay') . '" name="submitAdd' . $this->table . 'AndStay" class="button" /></td>
					</tr>
				</table>
			</div>

			<script type="text/javascript" src="' . __PS_BASE_URI__ . 'js/tinymce/jscripts/tiny_mce/jquery.tinymce.js"></script>
			<script type="text/javascript">
			function tinyMCEInit(element)
			{
				$().ready(function() {
					$(element).tinymce({
						// Location of TinyMCE script
						script_url : \'' . __PS_BASE_URI__ . 'js/tinymce/jscripts/tiny_mce/tiny_mce.js\',
						// General options
						theme : "advanced",
						plugins : "safari,pagebreak,style,layer,table,advimage,advlink,inlinepopups,media,searchreplace,contextmenu,paste,directionality,fullscreen",
						// Theme options
						theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
						theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,,|,forecolor,backcolor",
						theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,media,|,ltr,rtl,|,fullscreen",
						theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,pagebreak",
						theme_advanced_toolbar_location : "top",
						theme_advanced_toolbar_align : "left",
						width : "100",
						theme_advanced_statusbar_location : "bottom",
						theme_advanced_resizing : true,
						content_css : "' . __PS_BASE_URI__ . 'themes/' . _THEME_NAME_ . '/css/global.css",
						// Drop lists for link/image/media/template dialogs
						template_external_list_url : "lists/template_list.js",
						external_link_list_url : "lists/link_list.js",
						external_image_list_url : "lists/image_list.js",
						media_external_list_url : "lists/media_list.js",
						elements : "nourlconvert",
						convert_urls : false,
						language : "' . (file_exists(_PS_ROOT_DIR_ . '/js/tinymce/jscripts/tiny_mce/langs/' . $iso . '.js') ? $iso : 'en') . '"
					});
				});
			}
			tinyMCEInit(\'textarea.rte\');
			toggleVirtualProduct(getE(\'is_virtual_good\'));
			</script>
		';
    }