public function renderDetails($tpl = null) { $supplierModel = new JeproshopSupplierModelSupplier(); $suppliers = $supplierModel->getSuppliersList(); $this->assignRef('suppliers', $suppliers); $this->addToolBar(); $this->sideBar = JHtmlSideBar::render(); parent::display($tpl); }
public function __construct($product_id = NULL, $full = FALSE, $lang_id = NULL, $shop_id = NULL, JeproshopContext $context = NULL) { $db = JFactory::getDBO(); if ($lang_id !== NULL) { $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) ? (int) $lang_id : JeproshopSettingModelSetting::getValue('default_lang'); } if ($shop_id && $this->isMultiShop()) { $this->shop_id = (int) $shop_id; $this->getShopFromContext = FALSE; } if ($this->isMultiShop() && !$this->shop_id) { $this->shop_id = JeproshopContext::getContext()->shop->shop_id; } if ($product_id) { $cache_id = 'jeproshop_product_model_' . $product_id . '_' . $lang_id . '_' . $shop_id; if (!JeproshopCache::isStored($cache_id)) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_product') . " AS product "; $where = ""; /** get language information **/ if ($lang_id) { $query .= "LEFT JOIN " . $db->quoteName('#__jeproshop_product_lang') . " AS product_lang "; $query .= "ON (product.product_id = product_lang.product_id AND product_lang.lang_id = " . (int) $lang_id . ") "; if ($this->shop_id && !empty($this->multiLangShop)) { $where = " AND product_lang.shop_id = " . $this->shop_id; } } /** Get shop informations **/ if (JeproshopShopModelShop::isTableAssociated('product')) { $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_product_shop') . " AS product_shop ON ("; $query .= "product.product_id = product_shop.product_id AND product_shop.shop_id = " . (int) $this->shop_id . ")"; } $query .= " WHERE product.product_id = " . (int) $product_id . $where; $db->setQuery($query); $product_data = $db->loadObject(); if ($product_data) { if (!$lang_id && isset($this->multiLang) && $this->multiLang) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_product_lang'); $query .= " WHERE product_id = " . (int) $product_id; $db->setQuery($query); $product_lang_data = $db->loadObjectList(); if ($product_lang_data) { foreach ($product_lang_data as $row) { foreach ($row as $key => $value) { if (array_key_exists($key, $this) && $key != 'product_id') { if (!isset($product_data->{$key}) || !is_array($product_data->{$key})) { $product_data->{$key} = array(); } $product_data->{$key}[$row->lang_id] = $value; } } } } } JeproshopCache::store($cache_id, $product_data); } } else { $product_data = JeproshopCache::retrieve($cache_id); } if ($product_data) { $product_data->product_id = $product_id; foreach ($product_data as $key => $value) { if (array_key_exists($key, $this)) { $this->{$key} = $value; } } } } if (!$context) { $context = JeproshopContext::getContext(); } if ($full && $this->product_id) { $this->isFullyLoaded = $full; $this->manufacturer_name = JeproshopManufacturerModelManufacturer::getNameById((int) $this->manufacturer_id); $this->supplier_name = JeproshopSupplierModelSupplier::getNameById((int) $this->supplier_id); if ($this->getProductType() == self::VIRTUAL_PRODUCT) { $this->developer_name = JeproshopDeveloperModelDeveloper::getNameById((int) $this->developer_id); } $address = NULL; if (is_object($context->cart) && $context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')} != null) { $address = $context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}; } $this->tax_rate = $this->getTaxesRate(new JeproshopAddressModelAddress($address)); $this->is_new = $this->isNew(); $this->base_price = $this->price; $this->price = JeproshopProductModelProduct::getStaticPrice((int) $this->product_id, false, null, 6, null, false, true, 1, false, null, null, null, $this->specific_price); $this->unit_price = $this->unit_price_ratio != 0 ? $this->price / $this->unit_price_ratio : 0; if ($this->product_id) { $this->tags = JeproshopTagModelTag::getProductTags((int) $this->product_id); } $this->loadStockData(); } if ($this->default_category_id) { $this->category = JeproshopCategoryModelCategory::getLinkRewrite((int) $this->default_category_id, (int) $lang_id); } }
/** * Post treatment for suppliers */ public function processSuppliers() { $app = JFactory::getApplication(); $db = JFactory::getDBO(); $product = new JeproshopProductModelProduct((int) $app->input->get('product_id')); if (JeproshopTools::isLoadedObject($product, 'product_id')) { // Get all id_product_attribute $attributes = $product->getAttributesResume($this->context->language->lang_id); if (empty($attributes)) { $attribute = new JObject(); $attribute->set('product_attribute_id', 0); $attribute->set('attribute_designation', ''); $attributes[] = $attribute; } // Get all available suppliers $suppliers = JeproshopSupplierModelSupplier::getSuppliers(); // Get already associated suppliers $associated_suppliers = JeproshopProductSupplierModelProductSupplier::getSupplierCollection($product->product_id); $input = JRequest::get('post'); $product_data = $input['supplier']; $suppliers_to_associate = array(); $new_default_supplier = 0; if (isset($product_data['default_supplier'])) { $new_default_supplier = (int) $product_data['default_supplier']; } // Get new associations foreach ($suppliers as $supplier) { if (isset($product_data['check_supplier_' . $supplier->supplier_id])) { $suppliers_to_associate[] = $supplier->supplier_id; } } // Delete already associated suppliers if needed foreach ($associated_suppliers as $key => $associated_supplier) { if (!in_array($associated_supplier->supplier_id, $suppliers_to_associate)) { $associated_supplier->delete(); unset($associated_suppliers[$key]); } } // Associate suppliers foreach ($suppliers_to_associate as $supplier_id) { $to_add = true; foreach ($associated_suppliers as $as) { if ($supplier_id == $as->supplier_id) { $to_add = false; } } if ($to_add) { $product_supplier = new JeproshopProductSupplierModelProductSupplier(); $product_supplier->product_id = $product->product_id; $product_supplier->product_attribute_id = 0; $product_supplier->supplier_id = $supplier_id; if ($this->context->currency->currency_id) { $product_supplier->currency_id = (int) $this->context->currency->currency_id; } else { $product_supplier->currency_id = (int) JeproshopSettingModelSetting::getValue('default_currency'); } $product_supplier->save(); $associated_suppliers[] = $product_supplier; } } // Manage references and prices foreach ($attributes as $attribute) { foreach ($associated_suppliers as $supplier) { if ($product_data['supplier_reference_' . $product->product_id . '_' . $attribute->product_attribute_id . '_' . $supplier->supplier_id] || $product_data['product_price_' . $product->product_id . '_' . $attribute->product_attribute_id . '_' . $supplier->supplier_id] && $product_data['product_price_currency_' . $product->product_id . '_' . $attribute->product_attribute_id . '_' . $supplier->supplier_id]) { $reference = JFactory::getDBO()->quote($app->input->get('supplier_reference_' . $product->product_id . '_' . $attribute->product_attribute_id . '_' . $supplier->supplier_id, '')); $price = (double) str_replace(array(' ', ','), array('', '.'), $app->input->get('product_price_' . $product->product_id . '_' . $attribute->product_attribute_id . '_' . $supplier->supplier_id, 0)); $price = JeproshopTools::roundPrice($price, 6); $currency_id = (int) $app->input->get('product_price_currency_' . $product->product_id . '_' . $attribute->product_attribute_id . '_' . $supplier->supplier_id, 0); if ($currency_id <= 0 || (!($result = JeproshopCurrencyModelCurrency::getCurrency($currency_id)) || empty($result))) { $this->context->controller->has_errors = JText::_('The selected currency is not valid' . __FILE__ . 'on line ' . __LINE__); } // Save product-supplier data $product_supplier_id = (int) JeproshopProductSupplierModelProductSupplier::getIdByProductAndSupplier($product->product_id, $attribute->product_attribute_id, $supplier->supplier_id); if (!$product_supplier_id) { $product->addSupplierReference($supplier->supplier_id, (int) $attribute->product_attribute_id, $reference, (double) $price, (int) $currency_id); if ($product->supplier_id == $supplier->supplier_id) { if ((int) $attribute->product_attribute_id > 0) { $data = new JObject(); $data->set('supplier_reference', $db->quote($reference)); $data->set('wholesale_price', (double) JeproshopTools::convertPrice($price, $currency_id)); $where = " combination.product_id = " . (int) $product->product_id . " AND combination.product_attribute_id = " . (int) $attribute->product_attribute_id; JeproshopCombinationModelCombination::updateMultishopTable($data, $where); } else { $product->wholesale_price = (double) Tools::convertPrice($price, $currency_id); //converted in the default currency $product->supplier_reference = $db->quote($reference); $product->update(); } } } else { $product_supplier = new JeproshopProductSupplierModelProductSupplier($product_supplier_id); $product_supplier->currency_id = (int) $currency_id; $product_supplier->product_supplier_price_te = (double) $price; $product_supplier->product_supplier_reference = $db->quote($reference); $product_supplier->update(); } } elseif ($app->input->get('supplier_reference_' . $product->product_id . '_' . $attribute->product_attribute_id . '_' . $supplier->supplier_id)) { //int attribute with default values if possible if ((int) $attribute->product_attribute_id > 0) { $product_supplier = new JeproshopProductSupplierModelProductSupplier(); $product_supplier->product_id = $product->product_id; $product_supplier->product_attribute_id = (int) $attribute->product_attribute_id; $product_supplier->supplier_id = $supplier->supplier_id; $product_supplier->save(); } } } } /* // Manage default supplier for product if ($new_default_supplier != $product->supplier_id) { $product->supplier_id = $new_default_supplier; $query = "UPDATE " . $db->quoteName('#__jeproshop_product') . " SET " . $db->quoteName('supplier_id') . " = " . (int)$new_default_supplier; $query .= " WHERE " . $db->quoteName('product_id') . " = " . (int)$product->product_id; $db->setQuery($query); $db->query(); } */ } }
private function addToolBar() { switch ($this->getLayout()) { case 'edit': JToolbarHelper::title(JText::_('COM_JEPROSHOP_PRODUCT_EDIT_PRODUCT_TITLE'), 'product-jeproshop'); JToolbarHelper::apply('update', JText::_('COM_JEPROSHOP_UPDATE_LABEL')); /*JToolbarHelper::custom('association', 'association.png', 'association.png', JText::_('COM_JEPROSHOP_SAVE_ASSOCIATION_LABEL'), true); JToolbarHelper::custom('price', 'price.png', 'price.png', JText::_('COM_JEPROSHOP_SAVE_PRICE_LABEL'), true); JToolbarHelper::custom('declination', 'declination.png', 'declination.png', JText::_('COM_JEPROSHOP_SAVE_DECLINATION_LABEL'), true); JToolbarHelper::custom('quantities', 'quantities.png', 'quantities.png', JText::_('COM_JEPROSHOP_SAVE_QUANTITIES_LABEL'), true); JToolbarHelper::custom('images', '.png', 'images.png', JText::_('COM_JEPROSHOP_SAVE_IMAGES_LABEL'), true); JToolbarHelper::custom('feature', 'features.png', 'features.png', JText::_('COM_JEPROSHOP_SAVE_FEATURES_LABEL'), true); JToolbarHelper::custom('customization', 'customization.png', 'customization.png', JText::_('COM_JEPROSHOP_SAVE_CUSTOMIZATION_LABEL'), true); JToolbarHelper::custom('attachment', 'attachment.png', 'attachment.png', JText::_('COM_JEPROSHOP_SAVE_ATTACHMENT_LABEL'), true); JToolbarHelper::custom('shipping', 'shipping.png', 'shipping.png', JText::_('COM_JEPROSHOP_SAVE_SHIPPING_LABEL'), true); JToolbarHelper::custom('supplier', 'supplier.png', 'supplier.png', JText::_('COM_JEPROSHOP_SAVE_SUPPLIER_LABEL'), true); JToolbarHelper::custom('developer', 'product_developer.png', 'preview_product_1.png', JText::_('COM_JEPROSHOP_SAVE_DEVELOPER_LABEL'), true); JToolbarHelper::custom('preview', 'preview_product.png', 'preview_product_1.png', JText::_('COM_JEPROSHOP_PREVIEW_LABEL'), true); */ JToolbarHelper::custom('sales', 'sales.png', 'sales.png', JText::_('COM_JEPROSHOP_SALES_LABEL'), true); JToolbarHelper::deleteList('delete'); JToolbarHelper::cancel('cancel'); break; case 'add': JToolbarHelper::title(JText::_('COM_JEPROSHOP_PRODUCT_ADD_PRODUCT_TITLE'), 'jeproshop-product'); JToolbarHelper::apply('save'); JToolbarHelper::save('save_close'); JToolbarHelper::save2new('add2new'); JToolbarHelper::cancel('cancel'); break; default: JToolbarHelper::title(JText::_('COM_JEPROSHOP_PRODUCTS_LIST_TITLE'), 'product-jeproshop'); JToolbarHelper::addNew('add'); JToolbarHelper::editList('edit'); JToolbarHelper::publish('publish'); JToolbarHelper::unpublish('unpublish'); JToolbarHelper::trash('delete'); JToolbarHelper::preferences('com_jeproshop'); JToolbarHelper::help('COM_JEPROSHOP_PRODUCT_MANAGER'); $filter_product_type_options = '<option value="1" >' . JText::_('COM_JEPROSHOP_PRODUCT_SIMPLE_PRODUCT_LABEL') . '</option>'; $filter_product_type_options .= '<option value="2" >' . JText::_('COM_JEPROSHOP_PRODUCT_PACKAGE_LABEL') . '</option>'; $filter_product_type_options .= '<option value="3" >' . JText::_('COM_JEPROSHOP_PRODUCT_VIRTUAL_LABEL') . '</option>'; JHtmlSidebar::addFilter(JText::_('COM_JEPROSHOP_SELECT_PRODUCT_TYPE_LABEL'), 'jform[filter_product_type]', $filter_product_type_options, FALSE); $filter_state_options = '<option value="1" >' . JText::_('COM_JEPROSHOP_FILTER_LABEL') . '</option>'; JHtmlSidebar::addFilter(JText::_('COM_JEPROSHOP_SELECT_STATUS_LABEL'), 'jform[filter_state]', $filter_state_options, FALSE); $categories = JeproshopCategoryModelCategory::getCategories(); $filter_category_options = ''; foreach ($categories as $category) { $filter_category_options .= '<option value="' . $category->category_id . '" >' . ucfirst($category->name) . '</option>'; } JHtmlSidebar::addFilter(JText::_('COM_JEPROSHOP_SELECT_CATEGORY_LABEL'), 'jform[filter_category]', $filter_category_options, FALSE); $manufacturers = JeproshopManufacturerModelManufacturer::getManufacturers(); $filter_manufacturers_options = ''; foreach ($manufacturers as $manufacturer) { $filter_manufacturers_options .= '<option value="' . (int) $manufacturer->manufacturer_id . '" >' . ucfirst($manufacturer->name) . '</option>'; } JHtmlSidebar::addFilter(JText::_('COM_JEPROSHOP_SELECT_MANUFACTURER_LABEL'), 'jform[filter_manufacturer]', $filter_manufacturers_options, FALSE); $suppliers = JeproshopSupplierModelSupplier::getSuppliers(); $filter_suppliers_options = ''; foreach ($suppliers as $supplier) { $filter_suppliers_options .= '<option value="' . (int) $supplier->supplier_id . '" >' . ucfirst($supplier->name) . '</option>'; } JHtmlSidebar::addFilter(JText::_('COM_JEPROSHOP_SELECT_SUPPLIER_LABEL'), 'jform[filter_supplier]', $filter_suppliers_options, FALSE); break; } JHtmlSidebar::addEntry(JText::_('COM_JEPROSHOP_DASHBOARD_LABEL'), 'index.php?option=com_jeproshop'); JHtmlSidebar::addEntry(JText::_('COM_JEPROSHOP_CATALOG_LABEL'), 'index.php?option=com_jeproshop&task=catalog', true); JHtmlSidebar::addEntry(JText::_('COM_JEPROSHOP_ORDERS_LABEL'), 'index.php?option=com_jeproshop&task=orders'); JHtmlSidebar::addEntry(JText::_('COM_JEPROSHOP_CUSTOMERS_LABEL'), 'index.php?option=com_jeproshop&task=customers'); JHtmlSidebar::addEntry(JText::_('COM_JEPROSHOP_PRICE_RULES_LABEL'), 'index.php?option=com_jeproshop&task=price_rules'); JHtmlSidebar::addEntry(JText::_('COM_JEPROSHOP_SHIPPING_LABEL'), 'index.php?option=com_jeproshop&task=shipping'); JHtmlSidebar::addEntry(JText::_('COM_JEPROSHOP_LOCALIZATION_LABEL'), 'index.php?option=com_jeproshop&task=localization'); JHtmlSidebar::addEntry(JText::_('COM_JEPROSHOP_SETTINGS_LABEL'), 'index.php?option=com_jeproshop&task=settings'); JHtmlSidebar::addEntry(JText::_('COM_JEPROSHOP_ADMINISTRATION_LABEL'), 'index.php?option=com_jeproshop&task=administration'); JHtmlSidebar::addEntry(JText::_('COM_JEPROSHOP_STATS_LABEL'), 'index.php?option=com_jeproshop&task=stats'); }
/** * Create a link to a product * * @param mixed $product Product object (can be an ID product, but deprecated) * @param string $alias * @param string $category * @param string $ean13 * @param null $lang_id * @param null $shop_id * @param int $product_attribute_id ID product attribute * @param bool $force_routes * @throws JException * @internal param int $id_lang * @internal param int $id_shop (since 1.5.0) ID shop need to be used when we generate a product link for a product in a cart * @return string */ public function getProductLink($product, $alias = null, $category = null, $ean13 = null, $lang_id = null, $shop_id = null, $product_attribute_id = 0, $force_routes = false) { if (!$lang_id) { $lang_id = JeproshopContext::getContext()->language->lang_id; } if (!is_object($product)) { if (is_array($product) && isset($product['product_id'])) { $product = new JeproshopProductModelProduct($product['product_id'], false, $lang_id, $shop_id); } elseif ((int) $product) { $product = new JeproshopProductModelProduct((int) $product, false, $lang_id, $shop_id); } else { throw new JException(JText::_('COM_JEPROSHOP_INVALID_PRODUCT_VARS_MESSAGE')); } } // Set available keywords $anchor = '&task=view&product_id=' . $product->product_id . (!$alias ? '&rewrite=' . $product->getFieldByLang('link_rewrite') : $alias) . (!$ean13 ? '&ean13=' . $product->ean13 : $ean13); $anchor .= '&meta_keywords=' . JeproshopTools::str2url($product->getFieldByLang('meta_keywords')) . '&meta_title=' . JeproshopTools::str2url($product->getFieldByLang('meta_title')); if ($this->hasKeyword('product', $lang_id, 'manufacturer', $shop_id)) { $params['manufacturer'] = JeproshopTools::str2url($product->isFullyLoaded ? $product->manufacturer_name : JeproshopManufacturerModelManufacturer::getNameById($product->manufacturer_id)); } if ($this->hasKeyword('product', $lang_id, 'supplier', $shop_id)) { $params['supplier'] = JeproshopTools::str2url($product->isFullyLoaded ? $product->supplier_name : JeproshopSupplierModelSupplier::getNameById($product->supplier_id)); } if ($this->hasKeyword('product', $lang_id, 'price', $shop_id)) { $params['price'] = $product->isFullyLoaded ? $product->price : JeproshopProductModelProduct::getStaticPrice($product->product_id, false, null, 6, null, false, true, 1, false, null, null, null, $product->specific_price); } if ($this->hasKeyword('product', $lang_id, 'tags', $shop_id)) { $params['tags'] = JeproshopTools::str2url($product->getTags($lang_id)); } if ($this->hasKeyword('product', $lang_id, 'category', $shop_id)) { $params['category'] = !is_null($product->category) && !empty($product->category) ? JeproshopTools::str2url($product->category) : JeproshopTools::str2url($category); } if ($this->hasKeyword('product', $lang_id, 'reference', $shop_id)) { $params['reference'] = JeproshopTools::str2url($product->reference); } if ($this->hasKeyword('product', $lang_id, 'categories', $shop_id)) { $params['category'] = !$category ? $product->category : $category; $cats = array(); foreach ($product->getParentCategories() as $cat) { if (!in_array($cat->category_id, Link::$category_disable_rewrite)) { //remove root and home category from the URL $cats[] = $cat->link_rewrite; } } $params['categories'] = implode('/', $cats); } $anchor .= $product_attribute_id ? '&product_attribute_id=' . $product_attribute_id : ''; return JRoute::_('index.php?option=com_jeproshop&view=product' . $anchor); }