Ejemplo n.º 1
0
 public static function getProduct($id)
 {
     self::onExecuteBefore(array(&$id));
     global $ext_name;
     $old_ext_name = $ext_name;
     $ext_name = 'ksenmart';
     $db = JFactory::getDBO();
     $params = JComponentHelper::getParams('com_ksenmart');
     $query = $db->getQuery(true);
     $query = KSMProducts::setProductMainImageToQuery($query);
     $query->select('`p`.*')->select($db->qn(array('m.title', 'u.form1'), array('manufacturer_title', 'unit')))->from($db->qn('#__ksenmart_products', 'p'))->leftjoin($db->qn('#__ksenmart_manufacturers', 'm') . ' ON ' . $db->qn('p.manufacturer') . '=' . $db->qn('m.id'))->leftjoin($db->qn('#__ksenmart_product_units', 'u') . ' ON ' . $db->qn('p.product_unit') . '=' . $db->qn('u.id'))->where($db->qn('p.id') . '=' . $db->q($id))->group($db->qn('p.id'));
     $db->setQuery($query);
     $row = $db->loadObject();
     if ($row && !empty($row)) {
         $row->properties = KSMProducts::getProperties($id);
         if (empty($row->folder)) {
             $row->folder = 'products';
         }
         if (empty($row->filename)) {
             $row->filename = 'no.jpg';
         }
         if ($row->product_packaging == 0) {
             $row->product_packaging = 1;
         }
         $row->product_packaging = rtrim(rtrim($row->product_packaging, '0'), '.');
         if ($row->parent_id > 0) {
             $row->parent = self::getProduct($row->parent_id);
         }
         self::productPricesTransform($row);
         $row->link = JRoute::_('index.php?option=com_ksenmart&view=product&id=' . $row->id . ':' . $row->alias . '&Itemid=' . KSSystem::getShopItemid());
         $row->mini_small_img = KSMedia::resizeImage($row->filename, $row->folder, $params->get('mini_thumb_width'), $params->get('mini_thumb_height'), json_decode($row->params, true));
         $row->small_img = KSMedia::resizeImage($row->filename, $row->folder, $params->get('thumb_width'), $params->get('thumb_height'), json_decode($row->params, true));
         $row->img = KSMedia::resizeImage($row->filename, $row->folder, $params->get('middle_width'), $params->get('middle_height'), json_decode($row->params, true));
         $row->img_link = KSMedia::resizeImage($row->filename, $row->folder, $params->get('full_width', 900), $params->get('full_height', 900));
         $row->rate = KSMProducts::getProductRate($row->id);
         $row->add_link_cart = KSFunctions::getAddToCartLink($row->price, 2);
         $row->tags = new JHelperTags();
         $row->tags->getItemTags('com_ksenmart.product', $row->id);
     }
     $ext_name = $old_ext_name;
     self::onExecuteAfter(array(&$row));
     return $row;
 }
Ejemplo n.º 2
0
 public function get_product_price_with_properties()
 {
     $pid = $this->input->get('id', 0, 'int');
     $val_prop_id = $this->input->get('val_prop_id', 0, 'int');
     $prop_id = $this->input->get('prop_id', 0, 'int');
     $selectedProperties = $this->input->get('properties', array(), 'array');
     $db = JFactory::getDBO();
     $app = JFactory::getApplication();
     $properties = KSMProducts::getProperties($pid, $prop_id, $val_prop_id);
     $productProperties = KSMProducts::getProperties($pid);
     $prices = KSMProducts::getProductPrices($pid);
     $price = $prices->price;
     $price_type = $prices->price_type;
     $checked = array();
     foreach ($productProperties as $property) {
         foreach ($selectedProperties as $selectedPropId => $selectedProperty) {
             foreach ($selectedProperty as $selectedValueId => $selectedValue) {
                 if (isset($selectedValue['checked'])) {
                     $checked[$selectedValue['valueId']] = $selectedValue['checked'];
                 }
                 if ($property->property_id == $selectedValue['propId'] && $val_prop_id != $property->values[$selectedValueId]->id) {
                     $edit_priceC = $property->values[$selectedValueId]->price;
                     $edit_price_symC = substr($edit_priceC, 0, 1);
                     $this->getCalcPriceAsProperties($edit_price_symC, $edit_priceC, $price);
                     $property->values[$selectedValueId]->id . '-' . $price . "\n\t";
                 }
             }
         }
     }
     foreach ($properties as $property) {
         $edit_price = null;
         if ($property->edit_price) {
             if ($property->view == 'checkbox') {
                 $value = array_pop($property->values);
                 if ($checked[$value->id]) {
                     $edit_price = $value->price;
                 }
             } elseif ($property->view == 'select' || $property->view == 'radio') {
                 if ($val_prop_id != 0) {
                     $edit_price = $property->values[$val_prop_id]->price;
                 }
             }
         }
         if ($edit_price) {
             $edit_price_sym = substr($edit_price, 0, 1);
             $this->getCalcPriceAsProperties($edit_price_sym, $edit_price, $price);
         }
     }
     $price = KSMPrice::getPriceInCurrentCurrency($price, $price_type);
     $app->close($price . '^^^' . $price);
 }