コード例 #1
0
 /**
  * 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)));
 }
コード例 #2
0
require_once dirname(__FILE__) . '/../../config/config.inc.php';
require_once dirname(__FILE__) . '/../../init.php';
$context = Context::getContext();
$action = Tools::getValue('action');
$add = !strcmp($action, 'add') ? 1 : 0;
$id_product = (int) Tools::getValue('id_product');
$quantity = (int) Tools::getValue('quantity');
$id_product_attribute = (int) Tools::getValue('id_product_attribute');
$result = array();
$data = array();
$result['data'] = date('Y-m-d H:i:s');
$result['action'] = $action;
$product = new Product($id_product, false, $context->cookie->id_lang);
$result['name'] = $product->name;
$result['quantity'] = $quantity ? $quantity : 1;
$result['price'] = $product->price;
if ($id_product_attribute) {
    $combination = new Combination($id_product_attribute);
    $attributes = $combination->getAttributesName($context->cookie->id_lang);
    $name = array();
    foreach ($attributes as $a) {
        $name[] = $a['name'];
    }
    $name = implode(' ', $name);
    $result['name'] = $result['name'] . ' ' . $name;
    $result['price'] = $result['price'] + $combination->price;
}
$result['price'] = Tools::displayPrice($result['price']);
$data['params'] = $result;
$data['number'] = Configuration::get('YA_METRIKA_NUMBER');
die(Tools::jsonEncode($data));
コード例 #3
0
    protected function _displaySpecificPriceModificationForm($defaultCurrency, $shops, $currencies, $countries, $groups)
    {
        $content = '';
        if (!($obj = $this->loadObject())) {
            return;
        }
        $specific_prices = SpecificPrice::getByProductId((int) $obj->id);
        $specific_price_priorities = SpecificPrice::getPriority((int) $obj->id);
        $tax_rate = $obj->getTaxesRate(Address::initialize());
        $tmp = array();
        foreach ($shops as $shop) {
            $tmp[$shop['id_shop']] = $shop;
        }
        $shops = $tmp;
        $tmp = array();
        foreach ($currencies as $currency) {
            $tmp[$currency['id_currency']] = $currency;
        }
        $currencies = $tmp;
        $tmp = array();
        foreach ($countries as $country) {
            $tmp[$country['id_country']] = $country;
        }
        $countries = $tmp;
        $tmp = array();
        foreach ($groups as $group) {
            $tmp[$group['id_group']] = $group;
        }
        $groups = $tmp;
        if (!is_array($specific_prices) || !count($specific_prices)) {
            $content .= '
				<tr>
					<td class="text-center" colspan="13"><i class="icon-warning-sign"></i>&nbsp;' . $this->l('No specific prices.') . '</td>
				</tr>';
        } else {
            $i = 0;
            foreach ($specific_prices as $specific_price) {
                $current_specific_currency = $currencies[$specific_price['id_currency'] ? $specific_price['id_currency'] : $defaultCurrency->id];
                if ($specific_price['reduction_type'] == 'percentage') {
                    $impact = '- ' . $specific_price['reduction'] * 100 . ' %';
                } elseif ($specific_price['reduction'] > 0) {
                    $impact = '- ' . Tools::displayPrice(Tools::ps_round($specific_price['reduction'], 2), $current_specific_currency);
                } else {
                    $impact = '--';
                }
                if ($specific_price['from'] == '0000-00-00 00:00:00' && $specific_price['to'] == '0000-00-00 00:00:00') {
                    $period = $this->l('Unlimited');
                } else {
                    $period = $this->l('From') . ' ' . ($specific_price['from'] != '0000-00-00 00:00:00' ? $specific_price['from'] : '0000-00-00 00:00:00') . '<br />' . $this->l('To') . ' ' . ($specific_price['to'] != '0000-00-00 00:00:00' ? $specific_price['to'] : '0000-00-00 00:00:00');
                }
                if ($specific_price['id_product_attribute']) {
                    $combination = new Combination((int) $specific_price['id_product_attribute']);
                    $attributes = $combination->getAttributesName((int) $this->context->language->id);
                    $attributes_name = '';
                    foreach ($attributes as $attribute) {
                        $attributes_name .= $attribute['name'] . ' - ';
                    }
                    $attributes_name = rtrim($attributes_name, ' - ');
                } else {
                    $attributes_name = $this->l('All combinations');
                }
                $rule = new SpecificPriceRule((int) $specific_price['id_specific_price_rule']);
                $rule_name = $rule->id ? $rule->name : '--';
                if ($specific_price['id_customer']) {
                    $customer = new Customer((int) $specific_price['id_customer']);
                    if (Validate::isLoadedObject($customer)) {
                        $customer_full_name = $customer->firstname . ' ' . $customer->lastname;
                    }
                    unset($customer);
                }
                if (!$specific_price['id_shop'] || in_array($specific_price['id_shop'], Shop::getContextListShopID())) {
                    $content .= '
					<tr ' . ($i % 2 ? 'class="alt_row"' : '') . '>
						<td>' . $rule_name . '</td>
						<td>' . $attributes_name . '</td>';
                    $can_delete_specific_prices = true;
                    if (Shop::isFeatureActive()) {
                        $id_shop_sp = $specific_price['id_shop'];
                        $can_delete_specific_prices = count($this->context->employee->getAssociatedShops()) > 1 && !$id_shop_sp || $id_shop_sp;
                        $content .= '
						<td>' . ($id_shop_sp ? $shops[$id_shop_sp]['name'] : $this->l('All shops')) . '</td>';
                    }
                    $price = Tools::ps_round($specific_price['price'], 2);
                    $fixed_price = $price == Tools::ps_round($obj->price, 2) || $specific_price['price'] == -1 ? '--' : Tools::displayPrice($price, $current_specific_currency);
                    $content .= '
						<td>' . ($specific_price['id_currency'] ? $currencies[$specific_price['id_currency']]['name'] : $this->l('All currencies')) . '</td>
						<td>' . ($specific_price['id_country'] ? $countries[$specific_price['id_country']]['name'] : $this->l('All countries')) . '</td>
						<td>' . ($specific_price['id_group'] ? $groups[$specific_price['id_group']]['name'] : $this->l('All groups')) . '</td>
						<td title="' . $this->l('ID:') . ' ' . $specific_price['id_customer'] . '">' . (isset($customer_full_name) ? $customer_full_name : $this->l('All customers')) . '</td>
						<td>' . $fixed_price . '</td>
						<td>' . $impact . '</td>
						<td>' . $period . '</td>
						<td>' . $specific_price['from_quantity'] . '</th>
						<td>' . (!$rule->id && $can_delete_specific_prices ? '<a class="btn btn-default" name="delete_link" href="' . self::$currentIndex . '&id_product=' . (int) Tools::getValue('id_product') . '&action=deleteSpecificPrice&id_specific_price=' . (int) $specific_price['id_specific_price'] . '&token=' . Tools::getValue('token') . '"><i class="icon-trash"></i></a>' : '') . '</td>
					</tr>';
                    $i++;
                    unset($customer_full_name);
                }
            }
        }
        $content .= '
				</tbody>
			</table>
			</div>
			<div class="panel-footer">
				<a href="' . $this->context->link->getAdminLink('AdminProducts') . '" class="btn btn-default"><i class="process-icon-cancel"></i> ' . $this->l('Cancel') . '</a>
				<button id="product_form_submit_btn"  type="submit" name="submitAddproduct" class="btn btn-default pull-right"><i class="process-icon-save"></i> ' . $this->l('Save') . '</button>
				<button id="product_form_submit_btn"  type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right"><i class="process-icon-save"></i> ' . $this->l('Save and stay') . '</button>
			</div>
		</div>';
        $content .= '
		<script type="text/javascript">
			var currencies = new Array();
			currencies[0] = new Array();
			currencies[0]["sign"] = "' . $defaultCurrency->sign . '";
			currencies[0]["format"] = ' . $defaultCurrency->format . ';
			';
        foreach ($currencies as $currency) {
            $content .= '
				currencies[' . $currency['id_currency'] . '] = new Array();
				currencies[' . $currency['id_currency'] . ']["sign"] = "' . $currency['sign'] . '";
				currencies[' . $currency['id_currency'] . ']["format"] = ' . $currency['format'] . ';
				';
        }
        $content .= '
		</script>
		';
        // Not use id_customer
        if ($specific_price_priorities[0] == 'id_customer') {
            unset($specific_price_priorities[0]);
        }
        // Reindex array starting from 0
        $specific_price_priorities = array_values($specific_price_priorities);
        $content .= '<div class="panel">
		<h3>' . $this->l('Priority management') . '</h3>
		<div class="alert alert-info">
				' . $this->l('Sometimes one customer can fit into multiple price rules. Priorities allow you to define which rule applies to the customer.') . '
		</div>';
        $content .= '
		<div class="form-group">
			<label class="control-label col-lg-3" for="specificPricePriority1">' . $this->l('Priorities') . '</label>
			<div class="input-group col-lg-9">
				<select id="specificPricePriority1" name="specificPricePriority[]">
					<option value="id_shop"' . ($specific_price_priorities[0] == 'id_shop' ? ' selected="selected"' : '') . '>' . $this->l('Shop') . '</option>
					<option value="id_currency"' . ($specific_price_priorities[0] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option>
					<option value="id_country"' . ($specific_price_priorities[0] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option>
					<option value="id_group"' . ($specific_price_priorities[0] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option>
				</select>
				<span class="input-group-addon"><i class="icon-chevron-right"></i></span>
				<select name="specificPricePriority[]">
					<option value="id_shop"' . ($specific_price_priorities[1] == 'id_shop' ? ' selected="selected"' : '') . '>' . $this->l('Shop') . '</option>
					<option value="id_currency"' . ($specific_price_priorities[1] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option>
					<option value="id_country"' . ($specific_price_priorities[1] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option>
					<option value="id_group"' . ($specific_price_priorities[1] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option>
				</select>
				<span class="input-group-addon"><i class="icon-chevron-right"></i></span>
				<select name="specificPricePriority[]">
					<option value="id_shop"' . ($specific_price_priorities[2] == 'id_shop' ? ' selected="selected"' : '') . '>' . $this->l('Shop') . '</option>
					<option value="id_currency"' . ($specific_price_priorities[2] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option>
					<option value="id_country"' . ($specific_price_priorities[2] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option>
					<option value="id_group"' . ($specific_price_priorities[2] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option>
				</select>
				<span class="input-group-addon"><i class="icon-chevron-right"></i></span>
				<select name="specificPricePriority[]">
					<option value="id_shop"' . ($specific_price_priorities[3] == 'id_shop' ? ' selected="selected"' : '') . '>' . $this->l('Shop') . '</option>
					<option value="id_currency"' . ($specific_price_priorities[3] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option>
					<option value="id_country"' . ($specific_price_priorities[3] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option>
					<option value="id_group"' . ($specific_price_priorities[3] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option>
				</select>
			</div>
		</div>
		<div class="form-group">
			<div class="col-lg-9 col-lg-offset-3">
				<p class="checkbox">
					<label for="specificPricePriorityToAll"><input type="checkbox" name="specificPricePriorityToAll" id="specificPricePriorityToAll" />' . $this->l('Apply to all products') . '</label>
				</p>
			</div>
		</div>
		<div class="panel-footer">
				<a href="' . $this->context->link->getAdminLink('AdminProducts') . '" class="btn btn-default"><i class="process-icon-cancel"></i> ' . $this->l('Cancel') . '</a>
				<button id="product_form_submit_btn"  type="submit" name="submitAddproduct" class="btn btn-default pull-right"><i class="process-icon-save"></i> ' . $this->l('Save') . '</button>
				<button id="product_form_submit_btn"  type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right"><i class="process-icon-save"></i> ' . $this->l('Save and stay') . '</button>
			</div>
		</div>
		';
        return $content;
    }
コード例 #4
0
 public function postProduct($iId, $type, $id_attribute = 0, $title = '', $overrideCategories = false)
 {
     $mResult = false;
     $product = new Product((int) $iId, true, (int) $this->_configuration['FBWALLPOSTS_LANG_ID']);
     if ($product && Validate::isLoadedObject($product)) {
         // use case - post in FB now for active product or forced product
         if ($product->active || $overrideCategories) {
             if (!$overrideCategories) {
                 if (!$this->productIsInModuleCategories((int) $product->id)) {
                     return $mResult;
                 }
             }
             if (version_compare(_PS_VERSION_, '1.5', '>')) {
                 $link = Context::getContext()->link;
             } else {
                 $link = new Link();
             }
             /* Image */
             $image = Image::getCover((int) $product->id);
             if ($image) {
                 if ($this->_configuration['FBWALLPOSTS_IMG_SIZE']) {
                     $image_link = $link->getImageLink($product->link_rewrite, (int) $product->id . '-' . (int) $image['id_image'], $this->_configuration['FBWALLPOSTS_IMG_SIZE']);
                 } else {
                     $image_link = $link->getImageLink($product->link_rewrite, (int) $product->id . '-' . (int) $image['id_image']);
                 }
                 /* Before version 1.4 */
                 if (strpos($image_link, 'http://') === FALSE && strpos($image_link, 'https://') === FALSE && version_compare(_PS_VERSION_, '1.4', '<')) {
                     $image_link = 'http://' . $_SERVER['HTTP_HOST'] . $image_link;
                 }
             } else {
                 $image_link = false;
             }
             /* Product URL */
             $category = new Category((int) $product->id_category_default, (int) $this->_configuration['FBWALLPOSTS_LANG_ID']);
             if (version_compare(_PS_VERSION_, '1.5.5', '>=')) {
                 $product_url = $link->getProductLink((int) $product->id, null, null, null, (int) $this->_configuration['FBWALLPOSTS_LANG_ID'], null, 0, false);
             } elseif (version_compare(_PS_VERSION_, '1.5', '>')) {
                 if (Configuration::get('PS_REWRITING_SETTINGS')) {
                     $product_url = $link->getProductLink((int) $product->id, null, null, null, (int) $this->_configuration['FBWALLPOSTS_LANG_ID'], null, 0, true);
                 } else {
                     $product_url = $link->getProductLink((int) $product->id, null, null, null, (int) $this->_configuration['FBWALLPOSTS_LANG_ID'], null, 0, false);
                 }
             } else {
                 $product_url = $link->getProductLink((int) $product->id, $product->link_rewrite, $category->link_rewrite, $product->ean13, (int) $this->_configuration['FBWALLPOSTS_LANG_ID']);
             }
             /* Product description */
             $product_description = strip_tags($product->{$this->_configuration['FBWALLPOSTS_P_DESCR_TYPE']});
             if ($type == 'free') {
                 $mResult = $this->createFBPost($title, $product->name, $product_url, $product_description, $image_link);
             } elseif ($type == 'new') {
                 $mResult = $this->createFBPost($this->_configuration['FBWALLPOSTS_NEW_PROD_TXT'], $product->name, $product_url, $product_description, $image_link);
             } elseif ($type == 'stock' && (int) $id_attribute == 0) {
                 $this->deleteProductFromOOS((int) $product->id, 0);
                 $mResult = $this->createFBPost($this->_configuration['FBWALLPOSTS_STOCK_PROD_TXT'], $product->name, $product_url, $product_description, $image_link);
             } elseif ($type == 'stock' && (int) $id_attribute != 0) {
                 // Version 1.x to 1.4
                 if (version_compare(_PS_VERSION_, '1.5', '<')) {
                     /* Attribute names */
                     if (Tools::getValue('attribute_combinaison_list') || Tools::getValue('attribute_combination_list')) {
                         if (Tools::getValue('attribute_combinaison_list')) {
                             $combo_list = Tools::getValue('attribute_combinaison_list');
                         } elseif (Tools::getValue('attribute_combination_list')) {
                             $combo_list = Tools::getValue('attribute_combination_list');
                         }
                         $attributes_txt = ' -';
                         $combo_labels = $this->getProductComboAttributes($combo_list, (int) $this->_configuration['FBWALLPOSTS_LANG_ID']);
                         if ($combo_labels && is_array($combo_labels) && sizeof($combo_labels)) {
                             foreach ($combo_labels as $c) {
                                 $attributes_txt .= ' ' . stripslashes($c['name']);
                             }
                         }
                     } else {
                         $attributes_txt = '';
                     }
                 } else {
                     /* Attribute names */
                     $attributes_txt = ' -';
                     $combination = new Combination((int) $id_attribute);
                     $combo_labels = $combination->getAttributesName((int) $this->_configuration['FBWALLPOSTS_LANG_ID']);
                     if ($combo_labels && is_array($combo_labels) && sizeof($combo_labels)) {
                         foreach ($combo_labels as $c) {
                             $attributes_txt .= ' ' . stripslashes($c['name']);
                         }
                     } else {
                         $attributes_txt = '';
                     }
                 }
                 $this->deleteProductFromOOS((int) $product->id, (int) $id_attribute);
                 $mResult = $this->createFBPost($this->_configuration['FBWALLPOSTS_STOCK_PROD_TXT'], $product->name . $attributes_txt, $product_url, $product_description, $image_link);
             }
         }
     }
     unset($product);
     return $mResult;
 }