public static function cacheSomeAttributesLists($product_attribute_list, $lang_id) { if (!JeproshopCombinationModelCombination::isFeaturePublished()) { return; } $product_attribute_implode = array(); foreach ($product_attribute_list as $product_attribute_id) { if ((int) $product_attribute_id && !array_key_exists($product_attribute_id . '_' . $lang_id, self::$_attributesLists)) { $product_attribute_implode[] = (int) $product_attribute_id; $attribute = new JObject(); $attribute->attributes = ''; $attribute->attributes_small = ''; self::$_attributesLists[(int) $product_attribute_id . '_' . $lang_id] = $attribute; } } if (!count($product_attribute_implode)) { return; } $db = JFactory::getDBO(); $query = "SELECT product_attribute_combination." . $db->quoteName('product_attribute') . ", attribute_group_lang." . $db->quoteName('public_name'); $query .= " AS public_group_name, attribute_lang." . $db->quoteName('name') . " AS attribute_name FROM " . $db->quoteName('#__jeproshop_product_attribute_combination'); $query .= " AS product_attribute_combination LEFT JOIN " . $db->quoteName('#__jeproshop_attribute') . " AS attribute ON (attribute." . $db->quoteName('attribute_id'); $query .= " = product_attribute_combination." . $db->quoteName('attribute_id') . " LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_group') . " AS attribute_group "; $query .= " ON attribute_group." . $db->quoteName('attribute_group_id') . " = attribute." . $db->quoteName('attribute_group_id') . " LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_lang'); $query .= " AS attribute_lang ON ( attribute." . $db->quoteName('attribute_id') . " = attribute_lang." . $db->quoteName('attribute_id') . " AND attribute_lang."; $query .= $db->quoteName('lang_id') . " = " . (int) $lang_id . ") LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_group_lang') . " AS attribute_group_lang ON ( "; $query .= "attribute_group." . $db->quoteName('attribute_group_id') . " = attribute_group_lang." . $db->quoteName('attribute_group_id') . " AND attribute_group_lang."; $query .= $db->quoteName('lang_id') . " = " . (int) $lang_id . ") WHERE product_attribute_combination." . $db->quoteName('product_attribute_id') . " IN ("; $query .= implode(',', $product_attribute_implode) . ") ORDER BY attribute_group_lang." . $db->quoteName('public_name') . " ASC "; $db->setQuery($query); $result = $db->loadObjectList(); foreach ($result as $row) { self::$_attributesLists[$row->product_attribute_id . '_' . $lang_id]->attributes .= $row->public_group_name . ' : ' . $row->attribute_name . ', '; self::$_attributesLists[$row->product_attribute_id . '_' . $lang_id]->attributes_small .= $row->attribute_name . ', '; } foreach ($product_attribute_implode as $product_attribute_id) { self::$_attributesLists[$product_attribute_id . '-' . $lang_id]->attributes = rtrim(self::$_attributesLists[$product_attribute_id . '_' . $lang_id]->attributes, ', '); self::$_attributesLists[$product_attribute_id . '-' . $lang_id]->attributes_small = rtrim(self::$_attributesLists[$product_attribute_id . '_' . $lang_id]->attributes_small, ', '); } }
/** * Get all attributes groups for a given language * * @param integer $lang_id Language id * @return array Attributes groups */ public static function getAttributesGroups($lang_id) { if (!JeproshopCombinationModelCombination::isFeaturePublished()) { return array(); } $db = JFactory::getDBO(); $query = "SELECT DISTINCT attribute_group_lang." . $db->quoteName('name') . ", attribute_group.*, "; $query .= "attribute_group_lang.* FROM " . $db->quoteName('#__jeproshop_attribute_group') . " AS "; $query .= "attribute_group " . JeproshopShopModelShop::addSqlAssociation('attribute_group') . " LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_attribute_group_lang') . " AS attribute_group_lang ON (attribute_group."; $query .= $db->quoteName('attribute_group_id') . " = attribute_group_lang." . $db->quoteName('attribute_group_id'); $query .= " AND " . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") ORDER BY " . $db->quoteName('name') . " ASC"; $db->setQuery($query); return $db->loadObjectList(); }
/** * Check if product has attributes combinations * * @return integer Attributes combinations number */ public function hasAttributes() { if (!JeproshopCombinationModelCombination::isFeaturePublished()) { return 0; } $db = JFactory::getDBO(); $query = "SELECT COUNT(*) FROM " . $db->quoteName('#__jeproshop_product_attribute') . " AS product_attribute "; $query .= JeproshopShopModelShop::addSqlAssociation('product_attribute') . " WHERE product_attribute." . $db->quoteName('product_id') . " = " . (int) $this->product_id; $db->setQuery($query); return $db->loadResult(); }
public static function getAttributes($db, $product_id, $lang_id) { if (!JeproshopCombinationModelCombination::isFeaturePublished()) { return ''; } $attributes = ''; $query = "SELECT attribute_lang.name FROM " . $db->quoteName('#__jeproshop_product_attribute') . " AS product_attribute "; $query .= "INNER JOIN " . $db->quoteName('#__jeproshop_product_attribute_combination') . " AS _product_attribute_combination"; $query .= " ON product_attribute.product_attribute_id = product_attribute_combination.product_attribute_id INNER JOIN "; $query .= $db->quoteName('#__jeproshop_attribute_lang') . " AS attribute_lang ON (product_attribute_combination.attribute_id"; $query .= " = attribute_lang.attribute_id AND attribute_lang.lang_id = " . (int) $lang_id . ") " . JeproshopShopModelShop::addSqlAssociation('product_attribute'); $query .= "\tWHERE product_attribute.product_id = " . (int) $product_id; $attributesArray = $db->loadObjectList(); foreach ($attributesArray as $attribute) { $attributes .= $attribute->name . ' '; } return $attributes; }
/** * 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); }
/** * Return cart weight * * @param $products * @return float Cart weight */ public function getTotalWeight($products = null) { if (!is_null($products)) { $total_weight = 0; foreach ($products as $product) { if (!isset($product->weight_attribute) || is_null($product->weight_attribute)) { $total_weight += $product->weight * $product->cart_quantity; } else { $total_weight += $product->weight_attribute * $product->cart_quantity; } } return $total_weight; } if (!isset(self::$_totalWeight[$this->cart_id])) { $db = JFactory::getDBO(); if (JeproshopCombinationModelCombination::isFeaturePublished()) { $query = "SELECT SUM((product." . $db->quoteName('weight') . " + product_attribute." . $db->quoteName('weight') . ") * cart_product."; $query .= $db->quoteName('quantity') . ") AS nb FROM " . $db->quoteName('#__jeproshop_cart_product') . " AS cart_product LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_product') . " AS product ON (cart_product." . $db->quoteName('product_id') . " = product."; $query .= $db->quoteName('product_id') . ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_attribute') . " AS product_attribute "; $query .= " ON (cart_product." . $db->quoteName('product_attribute_id') . " = product_attribute." . $db->quoteName('product_attribute_id'); $query .= ") WHERE (cart_product." . $db->quoteName('product_attribute_id') . " IS NOT NULL AND cart_product." . $db->quoteName('product_attribute_id'); $query .= " != 0) AND cart_product." . $db->quoteName('cart_id') . " = " . (int) $this->cart_id; $db->setQuery($query); $weight_product_with_attribute = $db->loadResult(); } else { $weight_product_with_attribute = 0; } $query = "SELECT SUM(product." . $db->quoteName('weight') . " * cart_product." . $db->quoteName('quantity') . ") AS nb FROM " . $db->quoteName('#__jeproshop_cart_product'); $query .= " cart_product LEFT JOIN " . $db->quoteName('#__jeproshop_product') . " AS product ON (cart_product." . $db->quoteName('product_id') . " = product."; $query .= $db->quoteName('product_id') . ") WHERE (cart_product." . $db->quoteName('product_attribute_id') . " IS NULL OR cart_product." . $db->quoteName('product_attribute_id'); $query .= " = 0) AND cart_product." . $db->quoteName('cart_id') . " = " . (int) $this->cart_id; $db->setQuery($query); $weight_product_without_attribute = $db->loadResult(); self::$_totalWeight[$this->cart_id] = round((double) $weight_product_with_attribute + (double) $weight_product_without_attribute, 3); } return self::$_totalWeight[$this->cart_id]; }
public function attribute() { $app = JFactory::getApplication(); // Don't process if the combination fields have not been submitted if (!JeproshopCombinationModelCombination::isFeaturePublished() || !$app->input->get('attribute_combination_list')) { return; } if (Validate::isLoadedObject($product = $this->object)) { if ($this->isProductFieldUpdated('attribute_price') && (!Tools::getIsset('attribute_price') || Tools::getIsset('attribute_price') == null)) { $this->has_errors = Tools::displayError('The price attribute is required.'); } if (!Tools::getIsset('attribute_combination_list') || Tools::isEmpty(Tools::getValue('attribute_combination_list'))) { $this->has_errors = Tools::displayError('You must add at least one attribute.'); } $array_checks = array('reference' => 'isReference', 'supplier_reference' => 'isReference', 'location' => 'isReference', 'ean13' => 'isEan13', 'upc' => 'isUpc', 'wholesale_price' => 'isPrice', 'price' => 'isPrice', 'ecotax' => 'isPrice', 'quantity' => 'isInt', 'weight' => 'isUnsignedFloat', 'unit_price_impact' => 'isPrice', 'default_on' => 'isBool', 'minimal_quantity' => 'isUnsignedInt', 'available_date' => 'isDateFormat'); foreach ($array_checks as $property => $check) { if (Tools::getValue('attribute_' . $property) !== false && !call_user_func(array('Validate', $check), Tools::getValue('attribute_' . $property))) { $this->errors[] = sprintf(Tools::displayError('Field %s is not valid'), $property); } } if (!count($this->errors)) { if (!isset($_POST['attribute_wholesale_price'])) { $_POST['attribute_wholesale_price'] = 0; } if (!isset($_POST['attribute_price_impact'])) { $_POST['attribute_price_impact'] = 0; } if (!isset($_POST['attribute_weight_impact'])) { $_POST['attribute_weight_impact'] = 0; } if (!isset($_POST['attribute_ecotax'])) { $_POST['attribute_ecotax'] = 0; } if (Tools::getValue('attribute_default')) { $product->deleteDefaultAttributes(); } // Change existing one if (($id_product_attribute = (int) Tools::getValue('id_product_attribute')) || ($id_product_attribute = $product->productAttributeExists(Tools::getValue('attribute_combination_list'), false, null, true, true))) { if ($this->tabAccess['edit'] === '1') { if ($this->isProductFieldUpdated('available_date_attribute') && (Tools::getValue('available_date_attribute') != '' && !Validate::isDateFormat(Tools::getValue('available_date_attribute')))) { $this->errors[] = Tools::displayError('Invalid date format.'); } else { $product->updateAttribute((int) $id_product_attribute, $this->isProductFieldUpdated('attribute_wholesale_price') ? Tools::getValue('attribute_wholesale_price') : null, $this->isProductFieldUpdated('attribute_price_impact') ? Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact') : null, $this->isProductFieldUpdated('attribute_weight_impact') ? Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact') : null, $this->isProductFieldUpdated('attribute_unit_impact') ? Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact') : null, $this->isProductFieldUpdated('attribute_ecotax') ? Tools::getValue('attribute_ecotax') : null, Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_ean13'), $this->isProductFieldUpdated('attribute_default') ? Tools::getValue('attribute_default') : null, Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), $this->isProductFieldUpdated('attribute_minimal_quantity') ? Tools::getValue('attribute_minimal_quantity') : null, $this->isProductFieldUpdated('available_date_attribute') ? Tools::getValue('available_date_attribute') : null, false); StockAvailable::setProductDependsOnStock((int) $product->id, $product->depends_on_stock, null, (int) $id_product_attribute); StockAvailable::setProductOutOfStock((int) $product->id, $product->out_of_stock, null, (int) $id_product_attribute); } } else { $this->errors[] = Tools::displayError('You do not have permission to add this.'); } } else { if ($this->tabAccess['add'] === '1') { if ($product->productAttributeExists(Tools::getValue('attribute_combination_list'))) { $this->errors[] = Tools::displayError('This combination already exists.'); } else { $id_product_attribute = $product->addCombinationEntity(Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'), Tools::getValue('attribute_ecotax'), 0, Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), null, Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), Tools::getValue('attribute_minimal_quantity'), array(), Tools::getValue('available_date_attribute')); StockAvailable::setProductDependsOnStock((int) $product->id, $product->depends_on_stock, null, (int) $id_product_attribute); StockAvailable::setProductOutOfStock((int) $product->id, $product->out_of_stock, null, (int) $id_product_attribute); } } else { $this->errors[] = Tools::displayError('You do not have permission to') . '<hr>' . Tools::displayError('edit here.'); } } if (!count($this->errors)) { $combination = new Combination((int) $id_product_attribute); $combination->setAttributes(Tools::getValue('attribute_combination_list')); // images could be deleted before $id_images = Tools::getValue('id_image_attr'); if (!empty($id_images)) { $combination->setImages($id_images); } $product->checkDefaultAttributes(); if (Tools::getValue('attribute_default')) { Product::updateDefaultAttribute((int) $product->id); if (isset($id_product_attribute)) { $product->cache_default_attribute = (int) $id_product_attribute; } if ($available_date = Tools::getValue('available_date_attribute')) { $product->setAvailableDate($available_date); } } } } } }
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; }
/** * Delete product attributes * * @return array Deletion result */ public function deleteProductAttributes() { //Hook::exec('actionProductAttributeDelete', array('id_product_attribute' => 0, 'id_product' => $this->id, 'deleteAllAttributes' => true)); $result = true; $db = JFactory::getDBO(); $query = "SELECT " . $db->quoteName('product_attribute_id') . " FROM " . $db->quoteName('#__jeproshop_product_attribute') . " WHERE " . $db->quoteName('product_id') . " = " . (int) $this->product_id; $db->setQuery($query); $combinations = $db->loadObjectList(); foreach ($combinations as $combination_id) { $combination = new JeproshopCombinationModelCombination($combination_id); $result &= $combination->delete(); } JeproshopSpecificPriceRuleModelSpecificPriceRule::applyAllRules(array((int) $this->product_id)); JeproshopTools::clearColorListCache($this->product_id); return $result; }