Пример #1
0
 /**
  * Deletes the product and all it entries and files from DB and FS
  *
  * @param integer $id
  * @return number of deleted entries
  */
 function deleteProductById($id = '')
 {
     if ((int) $id) {
         $itemCat = new struct_corecatalog_catalog(array('cat_id' => $id));
         $itemCat->load();
         rad_instances::get('model_core_image')->deleteItemsByCat($id);
         $modelTags = rad_instances::get('model_coreresource_tags')->setState('tag_type', 'product');
         $modelTags->deleteTagsInItem($id);
         $res = $this->query('DELETE FROM ' . RAD . 'cat_in_tree where cit_cat_id=?', array($id));
         $res += $this->query('DELETE FROM ' . RAD . 'cat_special where cs_catid=?', array($id));
         $res += $this->query('DELETE FROM ' . RAD . 'cat_val_values where vv_cat_id=?', array($id));
         $res += $this->query('DELETE FROM ' . RAD . 'cat_files where rcf_cat_id=?', array($id));
         //DELETE COMMENTS
         $itemsComments = rad_instances::get('model_coreresource_comments')->setState('rcm_type', model_coreresource_comments::TYPE_PRODUCT)->setState('item_id', $id)->getItems();
         if (!empty($itemsComments)) {
             foreach ($itemsComments as $itemComment) {
                 $res += $itemComment->remove();
             }
         }
         $res += $itemCat->remove();
         rad_cleanurl::removeAlias('product', $id);
         return $res;
     }
 }