コード例 #1
0
ファイル: product.php プロジェクト: jeprodev/jeproshop
 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);
     }
 }
コード例 #2
0
ファイル: controller.php プロジェクト: jeprodev/jeproshop
 /**
  * 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);
 }