예제 #1
0
파일: catalog.php 프로젝트: JexyRu/Ksenmart
 function getSet($categories = array())
 {
     $this->onExecuteBefore('getSet', array(&$categories));
     $id = JRequest::getInt('id');
     $ids = JRequest::getVar('ids', array());
     $set = KSSystem::loadDbItem($id, 'products');
     $set = KSMedia::setItemMedia($set, 'product');
     if (count($categories)) {
         $query = $this->_db->getQuery(true);
         $query->select('category_id')->from('#__ksenmart_products_categories')->where('product_id=' . $id)->where('is_default=1');
         $this->_db->setQuery($query);
         $is_default = $this->_db->loadResult();
         foreach ($categories as $category_id) {
             $category = new stdClass();
             $category->category_id = $category_id;
             $category->is_default = $category->category_id == $is_default ? 1 : 0;
             $set->categories[$category_id] = $category;
         }
     } else {
         $query = $this->_db->getQuery(true);
         $query->select('category_id, is_default')->from('#__ksenmart_products_categories')->where('product_id=' . $id);
         $this->_db->setQuery($query);
         $set->categories = $this->_db->loadObjectList('category_id');
     }
     if (count($ids)) {
         $query = $this->_db->getQuery(true);
         $query->select('p.*')->from('#__ksenmart_products as p')->where('p.id in (' . implode(',', $ids) . ')');
         $query = KSMedia::setItemMainImageToQuery($query);
         $this->_db->setQuery($query);
         $set->relative = $this->_db->loadObjectList('id');
     } else {
         $query = $this->_db->getQuery(true);
         $query->select('p.*')->from('#__ksenmart_products as p')->innerjoin('#__ksenmart_products_relations as pr on pr.relative_id=p.id')->where('pr.relation_type=' . $this->_db->quote('set'))->where('pr.product_id=' . $id);
         $query = KSMedia::setItemMainImageToQuery($query);
         $this->_db->setQuery($query);
         $set->relative = $this->_db->loadObjectList('id');
     }
     $set->old_price = 0;
     foreach ($set->relative as &$prd) {
         $prd->small_img = KSMedia::resizeImage($prd->filename, $prd->folder, 36, 36, json_decode($prd->params, true));
         KSMProducts::productPricesTransform($prd);
         $set->old_price += $prd->price;
     }
     $this->onExecuteAfter('getSet', array(&$set));
     return $set;
 }