public function execute()
 {
     $model = new shopSetProductsModel();
     if (waRequest::post('hash', '')) {
         $model->clearSet(waRequest::get('id'));
     } else {
         $model->deleteProducts(waRequest::get('id'), waRequest::post('product_id', array(), waRequest::TYPE_ARRAY_INT));
     }
 }
예제 #2
0
 public function update($id, $data)
 {
     $change_id = false;
     if (isset($data['id'])) {
         if ($data['id'] == $id) {
             unset($data['id']);
         } else {
             $change_id = true;
         }
     }
     $this->updateById($id, $data);
     if ($change_id) {
         $set_products_model = new shopSetProductsModel();
         $set_products_model->updateByField(array('set_id' => $id), array('set_id' => $data['id']));
     }
 }
 public function execute()
 {
     $id = $this->get('id', true);
     $this->getProduct($id);
     $set_id = $this->post('set_id', true);
     $set_model = new shopSetModel();
     $set = $set_model->getById($set_id);
     if (!$set) {
         throw new waAPIException('invalid_param', 'Set not found', 404);
     }
     if ($set['type'] == shopSetModel::TYPE_DYNAMIC) {
         throw new waAPIException('invalid_param', 'Set type must be static');
     }
     $set_products_model = new shopSetProductsModel();
     $this->response = $set_products_model->deleteProducts($set_id, $id);
 }
 public function execute()
 {
     $set_ids = waRequest::post('set_id', array());
     // create new set
     $new_set_id = null;
     if (waRequest::post('new_set')) {
         $new_set_id = $this->createSet(waRequest::post('new_set_name'));
         $set_ids[] = $new_set_id;
     }
     if (!$set_ids) {
         return;
     }
     // add products to sets
     $hash = waRequest::post('hash', '');
     if (!$hash) {
         $product_ids = waRequest::post('product_id', array(), waRequest::TYPE_ARRAY_INT);
         if (!$product_ids) {
             return;
         }
         // add just selected products
         $this->set_products_model->add($product_ids, $set_ids);
     } else {
         // add all products of collection with this hash
         $collection = new shopProductsCollection($hash);
         $offset = 0;
         $count = 100;
         $total_count = $collection->count();
         while ($offset < $total_count) {
             $ids = array_keys($collection->getProducts('*', $offset, $count));
             $this->set_products_model->add($ids, $set_ids);
             $offset += count($ids);
         }
     }
     // form a response
     $sets = $this->set_model->getByField('id', $set_ids, 'id');
     if (isset($sets[$new_set_id])) {
         $this->response['new_set'] = $sets[$new_set_id];
         unset($sets[$new_set_id]);
     }
     $this->response['sets'] = $sets;
 }
 public function moveInsideSet($product_ids, $before_id = null, $list_id = 0)
 {
     $set_products_model = new shopSetProductsModel();
     $set_products_model->move($product_ids, $before_id, $list_id);
 }