function listProductUpdateData($products, $setUrl = 0) { $jshopConfig = JSFactory::getConfig(); $userShop = JSFactory::getUserShop(); $taxes = JSFactory::getAllTaxes(); if ($jshopConfig->product_list_show_manufacturer) { $manufacturers = JSFactory::getAllManufacturer(); } if ($jshopConfig->product_list_show_vendor) { $vendors = JSFactory::getAllVendor(); } if ($jshopConfig->show_delivery_time) { $deliverytimes = JSFactory::getAllDeliveryTime(); } $image_path = $jshopConfig->image_product_live_path; $noimage = $jshopConfig->noimage; JPluginHelper::importPlugin('jshoppingproducts'); $dispatcher = JDispatcher::getInstance(); foreach ($products as $key => $value) { $dispatcher->trigger('onListProductUpdateDataProduct', array(&$products, &$key, &$value)); $use_userdiscount = 1; if ($jshopConfig->user_discount_not_apply_prod_old_price && $products[$key]->product_old_price > 0) { $use_userdiscount = 0; } $products[$key]->_original_product_price = $products[$key]->product_price; $products[$key]->product_price_wp = $products[$key]->product_price; $products[$key]->product_price_default = 0; if ($jshopConfig->product_list_show_min_price) { if ($products[$key]->min_price > 0) { $products[$key]->product_price = $products[$key]->min_price; } } $products[$key]->show_price_from = 0; if ($jshopConfig->product_list_show_min_price && $value->different_prices) { $products[$key]->show_price_from = 1; } $products[$key]->product_price = getPriceFromCurrency($products[$key]->product_price, $products[$key]->currency_id); $products[$key]->product_old_price = getPriceFromCurrency($products[$key]->product_old_price, $products[$key]->currency_id); $products[$key]->product_price_wp = getPriceFromCurrency($products[$key]->product_price_wp, $products[$key]->currency_id); $products[$key]->product_price = getPriceCalcParamsTax($products[$key]->product_price, $products[$key]->tax_id); $products[$key]->product_old_price = getPriceCalcParamsTax($products[$key]->product_old_price, $products[$key]->tax_id); $products[$key]->product_price_wp = getPriceCalcParamsTax($products[$key]->product_price_wp, $products[$key]->tax_id); if ($userShop->percent_discount && $use_userdiscount) { $products[$key]->product_price_default = $products[$key]->_original_product_price; $products[$key]->product_price_default = getPriceFromCurrency($products[$key]->product_price_default, $products[$key]->currency_id); $products[$key]->product_price_default = getPriceCalcParamsTax($products[$key]->product_price_default, $products[$key]->tax_id); $products[$key]->product_price = getPriceDiscount($products[$key]->product_price, $userShop->percent_discount); $products[$key]->product_old_price = getPriceDiscount($products[$key]->product_old_price, $userShop->percent_discount); $products[$key]->product_price_wp = getPriceDiscount($products[$key]->product_price_wp, $userShop->percent_discount); } if ($jshopConfig->list_products_calc_basic_price_from_product_price) { $products[$key]->basic_price_info = getProductBasicPriceInfo($value, $products[$key]->product_price_wp); } else { $products[$key]->basic_price_info = getProductBasicPriceInfo($value, $products[$key]->product_price); } if ($value->tax_id) { $products[$key]->tax = $taxes[$value->tax_id]; } if ($jshopConfig->product_list_show_manufacturer && $value->product_manufacturer_id && isset($manufacturers[$value->product_manufacturer_id])) { $products[$key]->manufacturer = $manufacturers[$value->product_manufacturer_id]; } else { $products[$key]->manufacturer = new stdClass(); $products[$key]->manufacturer->name = ''; } if ($jshopConfig->admin_show_product_extra_field) { $products[$key]->extra_field = getProductExtraFieldForProduct($value); } else { $products[$key]->extra_field = ''; } if ($jshopConfig->product_list_show_vendor) { $vendordata = $vendors[$value->vendor_id]; $vendordata->products = SEFLink("index.php?option=com_jshopping&controller=vendor&task=products&vendor_id=" . $vendordata->id, 1); $products[$key]->vendor = $vendordata; } else { $products[$key]->vendor = ''; } if ($jshopConfig->hide_delivery_time_out_of_stock && $products[$key]->product_quantity <= 0) { $products[$key]->delivery_times_id = 0; $value->delivery_times_id = 0; } if ($jshopConfig->show_delivery_time && $value->delivery_times_id) { $products[$key]->delivery_time = $deliverytimes[$value->delivery_times_id]; } else { $products[$key]->delivery_time = ''; } $products[$key]->_display_price = getDisplayPriceForProduct($products[$key]->product_price); if (!$products[$key]->_display_price) { $products[$key]->product_old_price = 0; $products[$key]->product_price_default = 0; $products[$key]->basic_price_info['price_show'] = 0; $products[$key]->tax = 0; $jshopConfig->show_plus_shipping_in_product = 0; } if ($jshopConfig->product_list_show_qty_stock) { $products[$key]->qty_in_stock = getDataProductQtyInStock($products[$key]); } $image = getPatchProductImage($products[$key]->image, 'thumb'); $products[$key]->product_name_image = $products[$key]->image; $products[$key]->product_thumb_image = $image; if (!$image) { $image = $noimage; } $products[$key]->image = $image_path . "/" . $image; $products[$key]->template_block_product = "product.php"; if (!$jshopConfig->admin_show_product_labels) { $products[$key]->label_id = null; } if ($products[$key]->label_id) { $image = getNameImageLabel($products[$key]->label_id); if ($image) { $products[$key]->_label_image = $jshopConfig->image_labels_live_path . "/" . $image; } $products[$key]->_label_name = getNameImageLabel($products[$key]->label_id, 2); } if ($jshopConfig->display_short_descr_multiline) { $products[$key]->short_description = nl2br($products[$key]->short_description); } } if ($setUrl) { addLinkToProducts($products, 0, 1); } $dispatcher->trigger('onListProductUpdateData', array(&$products)); return $products; }
function getBuildSelectAttributes($attributeValues, $attributeActive, $displayonlyattrtype = null) { $jshopConfig = JSFactory::getConfig(); if (!$jshopConfig->admin_show_attributes) { return array(); } $dispatcher = JDispatcher::getInstance(); $attrib = JSFactory::getAllAttributes(); $userShop = JSFactory::getUserShop(); $selects = array(); foreach ($attrib as $k => $v) { $attr_id = $v->attr_id; if ($displayonlyattrtype) { $v->attr_type = $displayonlyattrtype; } if (isset($attributeValues[$attr_id]) && $attributeValues[$attr_id]) { if (isset($attributeActive[$attr_id])) { $_firstval = $attributeActive[$attr_id]; } else { $_firstval = 0; } $selects[$attr_id] = new stdClass(); $selects[$attr_id]->attr_id = $attr_id; $selects[$attr_id]->attr_name = $v->name; $selects[$attr_id]->attr_description = $v->description; $selects[$attr_id]->groupname = $v->groupname; $selects[$attr_id]->firstval = $_firstval; $options = $attributeValues[$attr_id]; $attrimage = array(); foreach ($options as $k2 => $v2) { $attrimage[$v2->val_id] = $v2->image; $addPrice = $v2->addprice; $addPrice = getPriceFromCurrency($addPrice, $this->currency_id); $addPrice = getPriceCalcParamsTax($addPrice, $this->product_tax_id); if ($userShop->percent_discount) { $addPrice = getPriceDiscount($addPrice, $userShop->percent_discount); } $options[$k2]->addprice = $addPrice; } if ($v->attr_type == 1) { // attribut type select if ($jshopConfig->attr_display_addprice) { foreach ($options as $k2 => $v2) { if (($v2->price_mod == "+" || $v2->price_mod == "-" || $jshopConfig->attr_display_addprice_all_sign) && $v2->addprice > 0) { $ext_price_info = " (" . $v2->price_mod . formatprice($v2->addprice, null, 0, -1) . ")"; $options[$k2]->value_name .= $ext_price_info; } } } if ($jshopConfig->product_attribut_first_value_empty) { $first = array(); $first[] = JHTML::_('select.option', '0', _JSHOP_SELECT, 'val_id', 'value_name'); $options = array_merge($first, $options); } if (isset($attributeActive[$attr_id]) && isset($attrimage[$attributeActive[$attr_id]])) { $_active_image = $attrimage[$attributeActive[$attr_id]]; } else { $_active_image = ''; } if (isset($attributeActive[$attr_id])) { $_select_active = $attributeActive[$attr_id]; } else { $_select_active = ''; } $html_select_attribute_param = 'class="' . $jshopConfig->frontend_attribute_select_class_css . '" size = "' . $jshopConfig->frontend_attribute_select_size . '" onchange="setAttrValue(\'' . $attr_id . '\', this.value);"'; $selects[$attr_id]->selects = JHTML::_('select.genericlist', $options, 'jshop_attr_id[' . $attr_id . ']', $html_select_attribute_param, 'val_id', 'value_name', $_select_active) . "<span class='prod_attr_img'>" . $this->getHtmlDisplayProdAttrImg($attr_id, $_active_image) . "</span>"; $selects[$attr_id]->selects = str_replace(array("\n", "\r", "\t"), "", $selects[$attr_id]->selects); } else { // attribut type radio foreach ($options as $k2 => $v2) { if ($v2->image) { $options[$k2]->value_name = "<img src='" . $jshopConfig->image_attributes_live_path . "/" . $v2->image . "' alt='' /> " . $v2->value_name; } } if ($jshopConfig->attr_display_addprice) { foreach ($options as $k2 => $v2) { if (($v2->price_mod == "+" || $v2->price_mod == "-" || $jshopConfig->attr_display_addprice_all_sign) && $v2->addprice > 0) { $ext_price_info = " (" . $v2->price_mod . formatprice($v2->addprice) . ")"; $options[$k2]->value_name .= $ext_price_info; } } } $radioseparator = ''; if ($jshopConfig->radio_attr_value_vertical) { $radioseparator = "<br/>"; } foreach ($options as $k2 => $v2) { $options[$k2]->value_name = "<span class='radio_attr_label'>" . $v2->value_name . "</span>"; } $selects[$attr_id]->selects = sprintRadioList($options, 'jshop_attr_id[' . $attr_id . ']', 'onclick="setAttrValue(\'' . $attr_id . '\', this.value);"', 'val_id', 'value_name', $attributeActive[$attr_id], $radioseparator); $selects[$attr_id]->selects = str_replace(array("\n", "\r", "\t"), "", $selects[$attr_id]->selects); } $dispatcher->trigger('onBuildSelectAttribute', array(&$attributeValues, &$attributeActive, &$selects, &$options, &$attr_id, &$v)); } } $grname = ''; foreach ($selects as $k => $v) { if ($v->groupname != $grname) { $grname = $v->groupname; $selects[$k]->grshow = 1; } else { $selects[$k]->grshow = 0; } } return $selects; }
public function getList() { /** * Get data */ $db = JFactory::getDBO(); $data = array(); //select from $source = trim($this->_params->get('source', 'js_categories')); if ($source == 'js_categories') { $catids = $this->_params->get('js_categories', ''); } else { if ($this->_params->get('js_ids', '')) { $ids = preg_split('/,/', $this->_params->get('js_ids', '')); $ids_tmp = array(); foreach ($ids as $id) { $ids_tmp[] = (int) trim($id); } } } if ($source == 'js_categories' && $catids && $this->_params->get('limit_items_for_each')) { foreach ($catids as $catid) { $query = $this->buildQuery($catid); $db->setQuery($query); $data = array_merge($data, $db->loadObjectlist()); } } else { if ($source == 'js_categories' && $catids) { $query = $this->buildQuery($catids); $db->setQuery($query); $data = array_merge($data, $db->loadObjectlist()); } else { if ($source == 'js_ids' && $ids_tmp && count($ids_tmp)) { $query = $this->buildQuery(false, $ids_tmp); $db->setQuery($query); $data = array_merge($data, $db->loadObjectlist()); } else { $query = $this->buildQuery(false, false); $db->setQuery($query); $data = array_merge($data, $db->loadObjectlist()); } } } //add link if (!class_exists('JSFactory')) { return null; } $jshopConfig = JSFactory::getConfig(); $userShop = JSFactory::getUserShop(); foreach ($data as $product) { $product->link = SEFLink('index.php?option=com_jshopping&controller=product&task=view&category_id=' . $product->category_id . '&product_id=' . $product->id, 1); if ($jshopConfig->show_buy_in_category) { if (!($jshopConfig->hide_buy_not_avaible_stock && $product->product_quantity <= 0)) { $product->add_to_cart = '<a class="bt-addtocart" href="' . SEFLink('index.php?option=com_jshopping&controller=cart&task=add&category_id=' . $product->category_id . '&product_id=' . $product->id, 1) . '" title="' . sprintf(JText::_('ADD_PRODUCT_TO_CART'), $product->name) . '">' . JText::_('ADD_TO_CART') . '</a>'; } } if ($jshopConfig->image_product_live_path) { $product->thumbnail = $jshopConfig->image_product_live_path . '/' . $product->thumbnail; } $product->category_link = SEFLink('index.php?option=com_jshopping&controller=category&task=view&category_id=' . $product->category_id, 1); //calculate price $product->product_price = getPriceFromCurrency($product->product_price, $product->currency_id); $product->product_old_price = getPriceFromCurrency($product->product_old_price, $product->currency_id); $product->product_price = getPriceCalcParamsTax($product->product_price, $product->product_tax_id); $product->product_old_price = getPriceCalcParamsTax($product->product_old_price, $product->product_tax_id); if ($userShop->percent_discount) { $product->product_price = getPriceDiscount($product->product_price, $userShop->percent_discount); $product->product_old_price = getPriceDiscount($product->product_old_price, $userShop->percent_discount); } $product->old_price = ''; if ($product->product_old_price) { $product->old_price = formatprice($product->product_old_price); } if ($product->product_price) { $product->sales_price = formatprice($product->product_price); } // title cut $titleMaxChars = $this->_params->get('title_max_chars', '100'); $limit_title_by = $this->_params->get('limit_title_by', 'char'); $replacer = $this->_params->get('replacer', '...'); $isStrips = $this->_params->get("auto_strip_tags", 1); $stringtags = ''; if ($limit_title_by == 'word' && $titleMaxChars > 0) { $product->name_cut = self::substrword($product->name, $titleMaxChars, $replacer, $isStrips); } elseif ($limit_title_by == 'char' && $titleMaxChars > 0) { $product->name_cut = self::substring($product->name, $titleMaxChars, $replacer, $isStrips); } } if (empty($data)) { return array(); } /** * Get display and config params */ /* title */ $isStrips = $this->_params->get("auto_strip_tags", 1); $stringtags = ''; if ($isStrips) { $allow_tags = $this->_params->get("allow_tags", ''); $stringtags = ''; if (!is_array($allow_tags)) { $allow_tags = explode(',', $allow_tags); } foreach ($allow_tags as $tag) { $stringtags .= '<' . $tag . '>'; } } if (!$this->_params->get('default_thumb', 1)) { $this->_defaultThumb = ''; } /* intro */ $maxDesciption = $this->_params->get('description_max_chars', 100); $limitDescriptionBy = $this->_params->get('limit_description_by', 'char'); $isThumb = $this->_params->get('image_thumb', 1); $dateFormat = $this->_params->get('date_format', 'DATE_FORMAT_LC3'); foreach ($data as $key => &$product) { if ($this->_params->get('show_date')) { $product->date = JHtml::_('date', $product->created_on, JText::_($dateFormat)); } if ($this->_params->get('show_intro')) { if ($limitDescriptionBy == 'word') { $product->description = self::substrword($product->introtext, $maxDesciption, $stringtags); } else { $product->description = self::substring($product->introtext, $maxDesciption, $stringtags); } } //if show image if ($this->_params->get('show_image')) { $product->thumbnail = explode(',', $product->thumbnail); $thumbnail = ''; foreach ($product->thumbnail as $tmpThumbnail) { $type = explode('.', $tmpThumbnail); $type = strtolower($type[count($type) - 1]); if (in_array($type, array('jpg', 'jpeg', 'png', 'png'))) { $thumbnail = $tmpThumbnail; break; } } $product->thumbnail = $thumbnail; $product = $this->generateImages($product, $isThumb); } //get label $product->label_image = $product->label_image ? $jshopConfig->image_labels_live_path . "/" . $product->label_image : ''; if ($this->_params->get('show_manufacturer')) { $product->manufacturer_link = SEFLink('index.php?option=com_jshopping&controller=manufacturer&task=view&manufacturer_id=' . $product->product_manufacturer_id); } } if ($this->_params->get('show_rating')) { foreach ($data as $key => &$product) { $count = floor($jshopConfig->max_mark / $jshopConfig->rating_starparts); $width = $count * 16; $rating = round($product->rating); $product->ratingSpan = '<span class="vote">'; if (empty($rating)) { $product->ratingSpan .= '<span style="width: ' . $width . 'px;" title="' . JText::_("RATING_UNRATE") . '" class="ratingbox" style="display:inline-block;">'; } else { $width_active = intval($rating * 16 / $jshopConfig->rating_starparts); $product->ratingSpan .= '<span style="width: ' . $width . 'px;" title="' . JText::_("RATING") . ' ' . $rating . '/' . $jshopConfig->max_mark . '" class="ratingbox" style="display:inline-block;">'; $product->ratingSpan .= '<span class="ratingactive" style="width: ' . $width_active . 'px"></span>'; } $product->ratingSpan .= '</span></span>'; } } return $data; }
function updateOtherPricesIncludeAllFactors() { $jshopConfig = JSFactory::getConfig(); $userShop = JSFactory::getUserShop(); $this->product_old_price = $this->getOldPrice(); $this->product_old_price = getPriceFromCurrency($this->product_old_price, $this->currency_id); $this->product_old_price = getPriceDiscount($this->product_old_price, $userShop->percent_discount); $this->product_old_price = getPriceCalcParamsTax($this->product_old_price, $this->product_tax_id); if (is_array($this->product_add_prices)) { foreach ($this->product_add_prices as $key => $value) { $this->product_add_prices[$key]->price = getPriceFromCurrency($this->product_add_prices[$key]->price, $this->currency_id); $this->product_add_prices[$key]->price = getPriceDiscount($this->product_add_prices[$key]->price, $userShop->percent_discount); $this->product_add_prices[$key]->price = getPriceCalcParamsTax($this->product_add_prices[$key]->price, $this->product_tax_id); } } JPluginHelper::importPlugin('jshoppingproducts'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('updateOtherPricesIncludeAllFactors', array(&$this)); }