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 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(); $set_products_model->add($id, $set_id); $this->response = true; }