Exemplo n.º 1
0
 /**
  * @return LibComment
  */
 static function getInstance()
 {
     if (empty(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Exemplo n.º 2
0
 function actGoods($goods_id = 0)
 {
     global $ST;
     if (!($id = $goods_id)) {
         $id = $this->getURINumVal('goods');
     }
     $field = array();
     //		$q="SELECT i.* FROM sc_shop_item i,sc_shop_offer of
     //			WHERE of.itemid=i.id  AND i.price>=0 AND of.in_stock>0 AND i.id=$id AND of.region='{$this->getRegion()}'";//@in_stock
     $q = "SELECT i.*,m.name AS m_name FROM sc_shop_item i\r\n\t\tLEFT JOIN sc_manufacturer AS m ON m.id=i.manufacturer_id\r\n\t\tWHERE i.price>=0 AND i.id={$id}";
     $units = $this->enum('sh_unit');
     $rs = $ST->select($q);
     if ($rs->next()) {
         $this->addLastView($id);
         $ST->update('sc_shop_item', array('views=views+1'), "id=" . (int) $id);
         //Увеличим счётчик просмотров
         $field = $rs->getRow();
         $field['class'] = 'goods';
         $field['unit'] = @$units[$field['unit']];
         $field['imgList'] = array();
         if ($field['img']) {
             $field['imgList'][] = $field['img'];
         }
         if ($field['img_add'] && ($img = explode(',', $field['img_add']))) {
             foreach ($img as $i) {
                 $field['imgList'][] = $i;
             }
         }
         $field += $this->getDeliveryCost($field['price']);
         $field['parentid'] = 0;
         $this->explorer[] = array('name' => $field['name']);
         $this->setTitle($field['name']);
         $this->setHeader($field['name']);
         //Хлебные крошки
         if ($parentid = $this->getURIIntVal('catalog')) {
             $field['category'] = $parentid;
         }
         $parent = $field['category'];
         $this->actCatalog[] = $parent;
         while ($parent) {
             $rs = $ST->select("SELECT id,name,parentid FROM sc_shop_catalog WHERE id=" . $parent);
             if ($rs->next()) {
                 $parent = $rs->getInt('parentid');
                 if (!$field['parentid']) {
                     $field['parentid'] = $parent;
                 }
                 $this->actCatalog[] = $parent;
                 $this->explorer[] = array('name' => $rs->get('name'), 'url' => $this->mod_uri . $rs->get('id') . '/');
             } else {
                 break;
             }
         }
         $field['prop'] = array();
         //Свойства
         $q = "SELECT v.value,p.name,p.grp,p.id,p.sort,pg.value_desc AS p_grp FROM sc_shop_prop p\r\n\t\t\t,sc_shop_prop_val v,\r\n\t\t\t(SELECT position,field_value,value_desc FROM sc_enum WHERE field_name='sh_prop_grp') AS pg\r\n\t\t\tWHERE pg.field_value=p.grp AND p.grp>0 AND position<0 AND v.item_id={$id} AND v.prop_id=p.id ORDER BY pg.position,p.sort";
         $q = "SELECT v.value,p.name,p.grp,p.id,p.sort,pg.value_desc AS p_grp FROM sc_shop_prop p\r\n\t\t\tLEFT JOIN (SELECT position,field_value,value_desc FROM sc_enum WHERE field_name='sh_prop_grp') AS pg ON pg.field_value=p.grp\r\n\t\t\t,sc_shop_prop_val v\r\n\t\t\t\r\n\t\t\tWHERE v.item_id={$id} AND v.prop_id=p.id AND p.grp>0 ORDER BY pg.position,p.sort";
         $rs = $ST->select($q);
         while ($rs->next()) {
             $field['prop'][$rs->get('grp')]['name'] = $rs->get('p_grp');
             $field['prop'][$rs->get('grp')]['p'][$rs->get('id')] = $rs->getRow();
         }
         //Товары связанные
         $field += LibCatalog::getInstance()->getRelation($id);
         $field['rait'] = LibComment::getInstance()->getGoodsRait($field['id'], $field['category']);
         $field += LibComment::getInstance()->getGoodsCommentData($field['id']);
         $field['comment'] = LibComment::getInstance()->getGoodsComment($field['id'], $this->isAdmin());
         $field['can_comment'] = LibComment::getInstance()->canGoodsComment($field['id']);
         $field['comment_enabled'] = Cfg::get('GOODS_COMMENT_ENABLED');
         //			$this->tplLeftComponent=dirname(__FILE__).'/catalog_left.tpl.php';
         //			$this->setContainer('common_container_lc.tpl.php');
         $this->setCommonCont();
         $this->display($field, dirname(__FILE__) . '/goods.tpl.php');
     } else {
         header("Location: /404/");
         exit;
     }
 }