public function execute()
 {
     $tag_model = new shopTagModel();
     $product_tags_model = new shopProductTagsModel();
     $delete_tags = waRequest::post('delete_tags', array(), waRequest::TYPE_ARRAY_INT);
     $tags = waRequest::post('tags', '', waRequest::TYPE_STRING_TRIM);
     $tags = $tags ? explode(',', $tags) : array();
     if (!$delete_tags && !$tags) {
         return;
     }
     $hash = waRequest::post('hash', '');
     // delete tags of selected products
     if (!$hash) {
         $product_ids = waRequest::post('product_id', array(), waRequest::TYPE_ARRAY_INT);
         if (!$product_ids) {
             return;
         }
         // delete tags of selected products
         if ($delete_tags) {
             $product_tags_model->delete($product_ids, $delete_tags);
         }
         // assign tags to selected products
         if ($tags) {
             $tag_ids = $tag_model->getIds($tags);
             $product_tags_model->assign($product_ids, $tag_ids);
         }
     } else {
         // maintain all products of collection with this hash
         $collection = new shopProductsCollection($hash);
         $offset = 0;
         $count = 100;
         $total_count = $collection->count();
         $tag_ids = array();
         if ($offset < $total_count) {
             $tag_ids = $tag_model->getIds($tags);
         }
         while ($offset < $total_count) {
             $product_ids = array_keys($collection->getProducts('*', $offset, $count));
             // delete tags
             if ($delete_tags) {
                 $product_tags_model->delete($product_ids, $delete_tags);
             }
             // assign tags
             if ($tag_ids) {
                 $product_tags_model->assign($product_ids, $tag_ids);
             }
             $offset += count($product_ids);
         }
     }
     $this->response['cloud'] = $tag_model->getCloud('id');
 }
예제 #2
0
 public function deleteTags($product_id, $tags)
 {
     if (!is_array($tags)) {
         $tags = explode(',', $tags);
     }
     $tag_model = new shopTagModel();
     $tag_ids = $tag_model->getIds($tags);
     $old_tag_ids = $this->query("SELECT tag_id FROM " . $this->table . "\n            WHERE product_id = i:id", array('id' => $product_id))->fetchAll(null, true);
     $delete_tag_ids = array_intersect($tag_ids, $old_tag_ids);
     if ($delete_tag_ids) {
         $this->deleteByField(array('product_id' => $product_id, 'tag_id' => $delete_tag_ids));
         $tag_model->incCounters($delete_tag_ids, -1);
     }
     if ($cache = wa()->getCache()) {
         $cache->delete('tags');
     }
     return true;
 }