/** * Assign price and tax to the template */ protected function assignPriceAndTax() { $customer_id = isset($this->context->customer) ? (int) $this->context->customer->customer_id : 0; $group_id = (int) JeproshopGroupModelGroup::getCurrent()->group_id; $country_id = (int) $customer_id ? JeproshopCustomerModelCustomer::getCurrentCountry($customer_id) : JeproshopSettingModelSetting::getValue('default_country'); $group_reduction = JeproshopGroupReductionModelGroupReduction::getValueForProduct($this->product->product_id, $group_id); if ($group_reduction === false) { $group_reduction = JeproshopGroupModelGroup::getReduction((int) $this->context->cookie->customer_id) / 100; } // Tax $tax = (double) $this->product->getTaxesRate(new JeproshopAddressModelAddress((int) $this->context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')})); $this->assignRef('tax_rate', $tax); $product_price_with_tax = JeproshopProductModelProduct::getStaticPrice($this->product->product_id, true, null, 6); if (JeproshopProductModelProduct::$_taxCalculationMethod == COM_JEPROSHOP_TAX_INCLUDED) { $product_price_with_tax = JeproshopTools::roundPrice($product_price_with_tax, 2); } $product_price_without_eco_tax = (double) $product_price_with_tax - $this->product->ecotax; $ecotax_rate = (double) JeproshopTaxModelTax::getProductEcotaxRate($this->context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}); $ecotax_tax_amount = JeproshopTools::roundPrice($this->product->ecotax, 2); if (JeproshopProductModelProduct::$_taxCalculationMethod == COM_JEPROSHOP_TAX_INCLUDED && (int) JeproshopSettingModelSetting::getValue('use_tax')) { $ecotax_tax_amount = JeproshopTools::roundPrice($ecotax_tax_amount * (1 + $ecotax_rate / 100), 2); } $currency_id = (int) $this->context->cookie->currency_id; $product_id = (int) $this->product->product_id; $shop_id = $this->context->shop->shop_id; $quantity_discounts = JeproshopSpecificPriceModelSpecificPrice::getQuantityDiscounts($product_id, $shop_id, $currency_id, $country_id, $group_id, null, true, (int) $this->context->customer->customer_id); foreach ($quantity_discounts as &$quantity_discount) { if ($quantity_discount->product_attribute_id) { $combination = new JeproshopCombinationModelCombination((int) $quantity_discount->product_attribute_id); $attributes = $combination->getAttributesName((int) $this->context->language->lang_id); foreach ($attributes as $attribute) { $quantity_discount->attributes = $attribute->name . ' - '; } $quantity_discount->attributes = rtrim($quantity_discount->attributes, ' - '); } if ((int) $quantity_discount->currency_id == 0 && $quantity_discount->reduction_type == 'amount') { $quantity_discount->reduction = JeproshopTools::convertPriceFull($quantity_discount->reduction, null, JeproshopContext::getContext()->currency); } } $product_price = $this->product->getPrice(JeproshopProductModelProduct::$_taxCalculationMethod == COM_JEPROSHOP_TAX_INCLUDED, false); $address = new JeproshopAddressModelAddress($this->context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}); $quantity_discounts = $this->formatQuantityDiscounts($quantity_discounts, $product_price, (double) $tax, $ecotax_tax_amount); $this->assignRef('quantity_discounts', $quantity_discounts); $this->assignRef('ecotax_tax_included', $ecotax_tax_amount); $ecotax_tax_excluded = JeproshopTools::roundPrice($this->product->ecotax, 2); $this->assignRef('ecotax_tax_excluded', $ecotax_tax_excluded); $this->assignRef('ecotaxTax_rate', $ecotax_rate); $display_price = JeproshopSettingModelSetting::getValue('display_price'); $this->assignRef('display_price', $display_price); $product_price_without_eco_tax = (double) $product_price_without_eco_tax; $this->assignRef('product_price_without_ecotax', $product_price_without_eco_tax); $this->assignRef('group_reduction', $group_reduction); $no_tax = JeproshopTaxModelTax::taxExcludedOption() || !$this->product->getTaxesRate($address); $this->assignRef('no_tax', $no_tax); $ecotax = !count($this->errors) && $this->product->ecotax > 0 ? JeproshopTools::convertPrice((double) $this->product->ecotax) : 0; $this->assignRef('ecotax', $ecotax); $tax_enabled = JeproshopSettingModelSetting::getValue('use_tax'); $this->assignRef('tax_enabled', $tax_enabled); $customer_group_without_tax = JeproshopGroupModelGroup::getPriceDisplayMethod($this->context->customer->default_group_id); $this->assignRef('customer_group_without_tax', $customer_group_without_tax); }
private function displaySpecificPriceModificationForm($default_currency, $shops, $currencies, $countries, $groups) { $content = ''; if (!$this->product) { return null; } $specificPrices = JeproshopSpecificPriceModelSpecificPrice::getSpecificPricesByProductId((int) $this->product->product_id); $specificPricePriorities = JeproshopSpecificPriceModelSpecificPrice::getPriority((int) $this->product->product_id); $app = JFactory::getApplication(); $taxRate = $this->product->getTaxesRate(JeproshopAddressModelAddress::initialize()); $tmp = array(); foreach ($shops as $shop) { $tmp[$shop->shop_id] = $shop; } $shops = $tmp; $tmp = array(); foreach ($currencies as $currency) { $tmp[$currency->currency_id] = $currency; } $currencies = $tmp; $tmp = array(); foreach ($countries as $country) { $tmp[$country->country_id] = $country; } $countries = $tmp; $tmp = array(); foreach ($groups as $group) { $tmp[$group->group_id] = $group; } $groups = $tmp; $content .= '<table class="table table-striped" ><thead><tr><th>' . JText::_('COM_JEPROSHOP_RULES_LABEL'); $content .= '</th><th>' . JText::_('COM_JEPROSHOP_COMBINATION_LABEL') . '</th>'; $multi_shop = JeproshopShopModelShop::isFeaturePublished(); if ($multi_shop) { $content .= '<th>' . JText::_('COM_JEPROSHOP_SHOP_LABEL') . '</th>'; } $content .= '<th>' . JText::_('COM_JEPROSHOP_CURRENCY_LABEL') . '</th><th>'; $content .= JText::_('COM_JEPROSHOP_COUNTRY_LABEL') . '</th><th>' . JText::_('COM_JEPROSHOP_GROUP_LABEL'); $content .= '</th><th>' . JText::_('COM_JEPROSHOP_CUSTOMER_LABEL') . '</th><th>'; $content .= JText::_('COM_JEPROSHOP_FIXED_PRICE_LABEL') . '</th><th>' . JText::_('COM_JEPROSHOP_IMPACT_LABEL'); $content .= '</th><th>' . JText::_('COM_JEPROSHOP_PERIOD_LABEL') . '</th><th>' . JText::_('COM_JEPROSHOP_FROM_LABEL'); $content .= '</th><th>' . JText::_('COM_JEPROSHOP_ACTIONS_LABEL') . '</th></tr></thead><tbody>'; if (!is_array($specificPrices) || !count($specificPrices)) { $content .= '<tr><td class="text-center" colspan="13" ><i class="icon-warning-sign"></i> '; $content .= JText::_('COM_JEPROSHOP_NO_SPECIFIC_PRICES_MESSAGE') . '</td></tr>'; } else { $i = 0; foreach ($specificPrices as $specificPrice) { $currentSpecificCurrency = $currencies[$specificPrice->currency_id ? $specificPrice->currency_id : $default_currency->currency_id]; if ($specificPrice->reduction_type == 'percentage') { $impact = '- ' . $specificPrice->reduction * 100 . ' %'; } elseif ($specificPrice->reduction > 0) { $impact = '- ' . JeproshopTools::displayPrice(Tools::ps_round($specificPrice->reduction, 2), $currentSpecificCurrency); } else { $impact = '--'; } if ($specificPrice->from == '0000-00-00 00:00:00' && $specificPrice->to == '0000-00-00 00:00:00') { $period = JText::_('COM_JEPROSHOP_UNLIMITED_LABEL'); } else { $period = JText::_('COM_JEPROSHOP_FROM_LABEL') . ' ' . ($specificPrice->from != '0000-00-00 00:00:00' ? $specificPrice['from'] : '0000-00-00 00:00:00') . '<br />' . $this->l('To') . ' ' . ($specificPrice['to'] != '0000-00-00 00:00:00' ? $specificPrice['to'] : '0000-00-00 00:00:00'); } if ($specificPrice->product_attribute_id) { $combination = new JeproshopCombinationModelCombination((int) $specificPrice->product_attribute_id); $attributes = $combination->getAttributesName((int) $this->context->language->lang_id); $attributes_name = ''; foreach ($attributes as $attribute) { $attributes_name .= $attribute->name . ' - '; } $attributes_name = rtrim($attributes_name, ' - '); } else { $attributes_name = JText::_('COM_JEPROSHOP_ALL_COMBINATIONS_LABEL'); } $rule = new JeproshopSpecificPriceRuleModelSpecificPriceRule((int) $specificPrice->specific_price_rule_id); $rule_name = $rule->specific_price_rule_id ? $rule->name : '--'; if ($specificPrice->customer_id) { $customer = new JeproshopCustomerModelCustomer((int) $specificPrice->customer_id); if (JeproshopTools::isLoadedObject($customer, 'customer_id')) { $customer_full_name = $customer->firstname . ' ' . $customer->lastname; } unset($customer); } if (!$specificPrice->shop_id || in_array($specificPrice->shop_id, JeoroshopShopModelShop::getContextListShopID())) { $content .= '<tr class="row_' . ($i % 2 ? '0' : '1') . '"><td>' . $rule_name . '</td><td>' . $attributes_name . '</td>'; $can_delete_specific_prices = true; if (JeproshopShopModelShop::isFeaturePublished()) { $sp_shop_id = $specificPrice->shop_id; $can_delete_specific_prices = count($this->context->employee->getAssociatedShops()) > 1 && !$sp_shop_id || $sp_shop_id; $content .= '<td>' . ($sp_shop_id ? $shops[$sp_shop_id]['name'] : JText::_('COM_JEPROSHOP_ALL_SHOPS_LABEL')) . '</td>'; } $price = JeproshopTools::roundPrice($specificPrice->price, 2); $fixed_price = $price == JeproshopTools::roundPrice($this->product->price, 2) || $specificPrice->price == -1 ? '--' : JeproshopTools::displayPrice($price, $current_specific_currency); $content .= '<td>' . ($specificPrice->currency_id ? $currencies[$specificPrice->currency_id]->name : JText::_('COM_JEPROSHOP_ALL_CURRENCIES_LABEL')) . '</td>'; $content .= '<td>' . ($specificPrice->country_id ? $countries[$specificPrice->country_id]->name : JText::_('COM_JEPROSHOP_ALL_COUNTRIES_LABEL')) . '</td>'; $content .= '<td>' . ($specificPrice->group_id ? $groups[$specificPrice->group_id]->name : JText::_('COM_JEPROSHOP_ALL_GROUPS_LABEL')) . '</td>'; $content .= '<td title="' . JText::_('COM_JEPROSHOP_ID_LABEL') . ' ' . $specificPrice->customer_id . '">' . (isset($customer_full_name) ? $customer_full_name : JText::_('COM_JEPROSHOP_ALL_CUSTOMERS_LABEL')) . '</td>'; $content .= '<td>' . $fixed_price . '</td><td>' . $impact . '</td><td>' . $period . '</td><td>' . $specificPrice->from_quantity . '</th>'; $content .= '<td>' . (!$rule->specific_price_rule_id && $can_delete_specific_prices ? '<a class="btn btn-default" name="delete_link" href="' . JRoute::_('index.php?option=com_jeproshop&view=price&product_id=' . (int) $app->input->get('product_id') . '&task=delete_specific_price&specific_price_id=' . (int) $specificPrice->specific_price_id . '&' . JSession::getFormToken() . '=1') . '"><i class="icon-trash"></i></a>' : '') . '</td>'; $content .= '</tr>'; $i++; unset($customer_full_name); } } } $content .= '</tbody></table>'; // Not use id_customer if ($specificPricePriorities[0] == 'customer_id') { unset($specificPricePriorities[0]); } // Reindex array starting from 0 $specificPricePriorities = array_values($specificPricePriorities); $content .= '<div class="panel"><div class="panel-title" >' . JText::_('Priority management') . '</div><div class="panel-content well" ><div class="alert alert-info">'; $content .= JText::_('Sometimes one customer can fit into multiple price rules. Priorities allow you to define which rule applies to the customer.') . '</div>'; $content .= '<div class="input-group" ><select id="jform_specific_price_priority_1" name="price_field[specific_price_priority[]]" class="middle_size" ><option value="shop_id"'; $content .= ($specificPricePriorities[0] == 'shop_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_SHOP_LABEL') . '</option><option value="currency_id"'; $content .= ($specificPricePriorities[0] == 'currency_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_CURRENCY_LABEL') . '</option><option value="country_id"'; $content .= ($specificPricePriorities[0] == 'country_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_COUNTRY_LABEL') . '</option><option value="group_id"'; $content .= ($specificPricePriorities[0] == 'group_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_GROUP_LABEL') . '</option></select> <span class="'; $content .= 'input-group-addon"><i class="icon-chevron-right"></i></span> <select name="price_field[specific_price_priority[]]" class="middle_size" ><option value="shop_id"'; $content .= ($specificPricePriorities[1] == 'shop_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_SHOP_LABEL') . '</option><option value="currency_id"'; $content .= ($specificPricePriorities[1] == 'currency_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_CURRENCY_LABEL') . '</option><option value="country_id"'; $content .= ($specificPricePriorities[1] == 'country_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_COUNTRY_LABEL') . '</option><option value="group_id"'; $content .= ($specificPricePriorities[1] == 'group_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_GROUP_LABEL') . '</option></select> <span class="'; $content .= 'input-group-addon"><i class="icon-chevron-right"></i></span> <select name="price_field[specific_price_priority[]]" class="middle_size" ><option value="shop_id"'; $content .= ($specificPricePriorities[2] == 'shop_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_SHOP_LABEL') . '</option><option value="currency_id"'; $content .= ($specificPricePriorities[2] == 'currency_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_CURRENCY_LABEL') . '</option><option value="country_id"'; $content .= ($specificPricePriorities[2] == 'country_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_COUNTRY_LABEL') . '</option><option value="group_id"'; $content .= ($specificPricePriorities[2] == 'group_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_GROUP_LABEL') . '</option></select><span class="'; $content .= 'input-group-addon"><i class="icon-chevron-right"></i></span> <select name="price_field[specific_price_priority[]]" class="middle_size" ><option value="shop_id"'; $content .= ($specificPricePriorities[3] == 'shop_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_SHOP_LABEL') . '</option><option value="currency_id"'; $content .= ($specificPricePriorities[3] == 'currency_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_CURRENCY_LABEL') . '</option><option value="country_id"'; $content .= ($specificPricePriorities[3] == 'country_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_COUNTRY_LABEL') . '</option><option value="group_id"'; $content .= ($specificPricePriorities[3] == 'group_id' ? ' selected="selected"' : '') . '>' . JText::_('COM_JEPROSHOP_GROUP_LABEL') . '</option></select></div></div></div>'; $content .= '<p class="checkbox"><label for="jform_specific_price_priority_to_all"><input type="checkbox" name="price_field[specific_price_priority_to_all]" id="jform_specific_'; $content .= 'price_priority_to_all" />' . JText::_('Apply to all products') . '</label></p>'; /*<div class="form-group"> <label class="control-label col-lg-3" for="specificPricePriority1">'.$this->l('Priorities').'</label> col-lg-9"> </div> </div> <div class="form-group"> <div class="col-lg-9 col-lg-offset-3"> </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> '; */ $content .= '<script type="text/javascript">var currencies = new Array(); currencies[0] = new Array(); '; $content .= 'currencies[0]["sign"] = "' . $default_currency->sign . '"; currencies[0]["format"] = ' . $default_currency->format . '; '; foreach ($currencies as $currency) { $content .= ' currencies[' . $currency->currency_id . '] = new Array(); currencies[' . $currency->currency_id . ']["sign"] = "' . $currency->sign . '"; currencies[' . $currency->currency_id . ']["format"] = ' . $currency->format . ';'; } $content .= '</script>'; return $content; }