public function execute() { $hash = $this->get('hash'); $collection = new shopProductsCollection($hash); $offset = waRequest::get('offset', 0, 'int'); if ($offset < 0) { throw new waAPIException('invalid_param', 'Param offset must be greater than or equal to zero'); } $limit = waRequest::get('limit', 100, 'int'); if ($limit < 0) { throw new waAPIException('invalid_param', 'Param limit must be greater than or equal to zero'); } if ($limit > 1000) { throw new waAPIException('invalid_param', 'Param limit must be less or equal 1000'); } $this->response['count'] = $collection->count(); $this->response['offset'] = $offset; $this->response['limit'] = $limit; $this->response['products'] = array_values($collection->getProducts('*', $offset, $limit)); $image_size = wa('shop')->getConfig()->getImageSize('thumb'); foreach ($this->response['products'] as &$p) { if ($p['image_id']) { $p['image_url'] = shopImage::getUrl(array('id' => $p['image_id'], 'product_id' => $p['id'], 'ext' => $p['ext']), $image_size, true); } } unset($p); }
public function execute() { $product_tags_model = new shopProductTagsModel(); $tags = array(); $hash = waRequest::post('hash', ''); // get tags by products if (!$hash) { $product_ids = waRequest::post('product_id', array(), waRequest::TYPE_ARRAY_INT); if (!$product_ids) { return; } $tags = $product_tags_model->getTags($product_ids); // get tags by hash of collection } 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)); $tags += $product_tags_model->getTags($ids); $offset += count($ids); } } $tag_model = new shopTagModel(); $this->view->assign(array('tags' => $tags, 'popular_tags' => $tag_model->popularTags())); }
public function addProducts($id, $type) { $model = $this->getProductsModel($type); if ($model) { $hash = waRequest::post('hash', ''); // hash of 'source' list (which provides products) if (!$hash) { $product_ids = waRequest::post('product_id', array(), waRequest::TYPE_ARRAY_INT); if (!$product_ids) { return; } $model->add($product_ids, $id); } else { $collection = new shopProductsCollection($hash); $offset = 0; $count = 100; $total_count = $collection->count(); while ($offset < $total_count) { $product_ids = array_keys($collection->getProducts('*', $offset, $count)); $model->add($product_ids, $id); $offset += count($product_ids); } } } }
public function execute() { $type_id = $this->getType(); if (!$type_id) { return; } $hash = waRequest::post('hash', '', waRequest::TYPE_STRING_TRIM); if (!$hash) { $product_ids = waRequest::post('product_id', array(), waRequest::TYPE_ARRAY_INT); $product_ids = $this->product_model->filterAllowedProductIds($product_ids); if (!$product_ids) { return; } $this->product_model->updateType($product_ids, $type_id); $this->response['types'] = $this->type_model->getTypes(); } else { if (substr($hash, 0, 5) != 'type/') { $collection = new shopProductsCollection($hash); $offset = 0; $count = 100; $total_count = $collection->count(); while ($offset < $total_count) { $ids = array_keys($collection->getProducts('*', $offset, $count)); $filtered = $this->product_model->filterAllowedProductIds($ids); $this->product_model->updateType($filtered, $type_id); $offset += count($ids); } $this->response['types'] = $this->type_model->getTypes(); } else { $this->product_model->changeType(substr($hash, 5), $type_id); $this->response['types'] = $this->type_model->getTypes(); } } }
public function execute() { $app_settings_model = new waAppSettingsModel(); $settings = $app_settings_model->get(array('shop', 'yoss')); if ($settings['status'] === 'on') { $query = waRequest::post('query', '', waRequest::TYPE_STRING_TRIM); $page = waRequest::post('page', 1, 'int'); $result = array(); $result['products'] = array(); $result['product_count'] = 0; $collection = new shopProductsCollection('search/query=' . $query); $product_limit = $settings['product_limit']; if (!$product_limit) { $product_limit = $this->getConfig()->getOption('products_per_page'); } $products = $collection->getProducts('*', ($page - 1) * $product_limit, $product_limit); if ($products) { $brands = array(); $categories = array(); $feature_model = new shopFeatureModel(); $result['searh_all_url'] = wa()->getRouteUrl('/frontend/search/query=') . '?query=' . $query; foreach ($products as $p) { $brand_feature = $feature_model->getByCode('brand'); $brand = ''; if ($brand_feature) { $feature_value_model = $feature_model->getValuesModel($brand_feature['type']); $product_brands = $feature_value_model->getProductValues($p['id'], $brand_feature['id']); $brands = array(); foreach ($product_brands as $k => $v) { $brand_id = $feature_value_model->getValueId($brand_feature['id'], $v); $brands[] = array('id' => $brand_id, 'brand' => '<a href="' . wa()->getRouteUrl('shop/frontend/brand', array('brand' => str_replace('%2F', '/', urlencode($v)))) . '">' . $v . '</a>'); } } $category_model = new shopCategoryModel(); $category = $category_model->getById($p['category_id']); $res_category = ''; if ($category) { $res_category = '<a href="' . wa()->getRouteUrl('/frontend/category', array('category_url' => $category['full_url'])) . '">' . $category['name'] . '</a>'; } $result['products'][] = array("name" => $p['name'], "url" => $p['frontend_url'], "image" => $p['image_id'] ? "<img src='" . shopImage::getUrl(array("product_id" => $p['id'], "id" => $p['image_id'], "ext" => $p['ext']), "48x48") . "' />" : "", "price" => shop_currency_html($p['price'], true), "brands" => $brands, "category" => $res_category); } $product_model = new shopProductModel(); $product_count = $collection->count(); $result['product_count'] = $product_count; if ($product_count > ($page - 1) * $product_limit + $product_limit) { $result['next_page'] = $page + 1; } else { $result['next_page'] = false; } } $this->response = $result; } else { $this->response = false; } }
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'); }
protected function setCollection(shopProductsCollection $collection) { $collection->filters(waRequest::get()); $limit = (int) waRequest::cookie('products_per_page'); if (!$limit || $limit < 0 || $limit > 500) { $limit = $this->getConfig()->getOption('products_per_page'); } $page = waRequest::get('page', 1, 'int'); if ($page < 1) { $page = 1; } $offset = ($page - 1) * $limit; $products = $collection->getProducts('*', $offset, $limit); $count = $collection->count(); $pages_count = ceil((double) $count / $limit); $this->view->assign('pages_count', $pages_count); $this->view->assign('products', $products); $this->view->assign('products_count', $count); }
public function execute() { $category_ids = waRequest::post('category_id', array(), waRequest::TYPE_ARRAY_INT); // create new category $new_category_id = null; if (waRequest::post('new_category')) { $new_category_id = $this->createCategory(waRequest::post('new_category_name')); $category_ids[] = $new_category_id; } if (!$category_ids) { return; } // add products to categories $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->category_products_model->add($product_ids, $category_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->category_products_model->add($ids, $category_ids); $offset += count($ids); } } // form a response $categories = $this->category_model->getByField('id', $category_ids, 'id'); if (isset($categories[$new_category_id])) { $this->response['new_category'] = $categories[$new_category_id]; unset($categories[$new_category_id]); } $this->response['categories'] = $categories; }
private function delete($hash, $count, $del_list = false) { $collection = new shopProductsCollection(implode('/', $hash)); // check rights to prevent infinite ajax-polling $types = $this->getModel('type')->getTypes(false); if (is_array($types)) { if (empty($types)) { $this->response['rest_count'] = 0; $this->response['count'] = $count; return true; } else { $collection->addWhere('p.type_id IN (' . implode(',', array_keys($types)) . ')'); } } if ($count) { $product_ids = array_keys($collection->getProducts('*', 0, $count, false)); $this->deleteProducts($product_ids); // DECREASE count. // Ignoring this case for dynamic set lead to tricky BUG, result of which in worst case is deleting ALL products $info = $collection->getInfo(); if ($hash[0] == 'set' || $hash[0] == 'category' || $hash[0] == 'type') { $model = $this->getModel($hash[0]); $model->updateById($hash[1], array('count' => max($info['count'] - $count, 0))); } } $rest_count = $collection->count(); $this->response['rest_count'] = $rest_count; $this->response['count'] = $count; if ($rest_count == 0) { $this->response['lists'] = $this->getLists(); if ($del_list) { return $this->deleteList($hash); } } return true; }
public function productsCount($hash = '') { $collection = new shopProductsCollection($hash); return $collection->count(); }