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 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 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');
 }
 public function execute()
 {
     $app_settings_model = new waAppSettingsModel();
     $query = waRequest::get('term');
     $count = $app_settings_model->get($this->plugin_id, 'autocomplete_count');
     $collection = new shopProductsCollection('search/query=' . $query);
     $products = $collection->getProducts('*', 0, $count);
     $result = array();
     foreach ($products as $product) {
         $size = $app_settings_model->get($this->plugin_id, 'img_size');
         $product['value'] = $product['name'];
         $product['price_str'] = shop_currency($product['price']);
         $product['img_url'] = $product['image_id'] ? shopImage::getUrl(array('id' => $product['image_id'], 'product_id' => $product['id'], 'filename' => $product['image_filename'], 'ext' => $product['ext']), $size) : '';
         array_push($result, $product);
     }
     $this->response = $result;
 }
Exemplo n.º 8
0
 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;
 }
Exemplo n.º 10
0
 /**
  *
  * Get data array from product collection
  * @param string $hash selector hash
  * @param int $offset optional parameter
  * @param int $limit optional parameter
  *
  * If $limit is omitted but $offset is not than $offset is interpreted as 'limit' and method returns first 'limit' items
  * If $limit and $offset are omitted that method returns first 500 items
  *
  * @return array
  */
 public function products($hash = '', $offset = null, $limit = null, $options = array())
 {
     if (is_array($offset)) {
         $options = $offset;
         $offset = null;
     }
     if (is_array($limit)) {
         $options = $limit;
         $limit = null;
     }
     $collection = new shopProductsCollection($hash, $options);
     if (!$limit && $offset) {
         $limit = $offset;
         $offset = 0;
     }
     if (!$offset && !$limit) {
         $offset = 0;
         $limit = 500;
     }
     return $collection->getProducts('*', $offset, $limit, true);
 }
 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;
 }
Exemplo n.º 12
0
 /**
  * Returns products identified as cross-selling items for current product.
  *
  * @param int $limit Maximum number of items to be returned
  * @param bool $available_only Whether only products with positive or unlimited stock count must be returned
  *
  * @return array Array of cross-selling products' data sub-arrays
  */
 public function crossSelling($limit = 5, $available_only = false)
 {
     $cross_selling = $this->getData('cross_selling');
     // upselling on (usign similar settting for type)
     if ($cross_selling == 1 || $cross_selling === null) {
         $type = $this->getType();
         if ($type['cross_selling']) {
             $collection = new shopProductsCollection($type['cross_selling'] . ($type['cross_selling'] == 'alsobought' ? '/' . $this->getId() : ''));
             if ($available_only) {
                 $collection->addWhere('(p.count > 0 OR p.count IS NULL)');
             }
             if ($type['cross_selling'] != 'alsobought') {
                 $collection->orderBy('RAND()');
             }
             $result = $collection->getProducts('*', $limit);
             if (isset($result[$this->getId()])) {
                 unset($result[$this->getId()]);
             }
             return $result;
         } else {
             return array();
         }
     } elseif (!$cross_selling) {
         return array();
     } else {
         $collection = new shopProductsCollection('related/cross_selling/' . $this->getId());
         if ($available_only) {
             $collection->addWhere('(p.count > 0 OR p.count IS NULL)');
         }
         return $collection->getProducts('*', $limit);
     }
 }
Exemplo n.º 13
0
 public function execute()
 {
     $ids = waRequest::param('id', array(), waRequest::TYPE_ARRAY_INT);
     if (!$ids) {
         $ids = waRequest::cookie('shop_compare', array(), waRequest::TYPE_ARRAY_INT);
     }
     $collection = new shopProductsCollection('id/' . implode(',', $ids));
     $products = $collection->getProducts();
     $features = array();
     $i = 0;
     $compare_link = wa()->getRouteUrl('/frontend/compare', array('id' => '%ID%'));
     foreach ($products as &$p) {
         $p = new shopProduct($p);
         $temp_ids = $ids;
         unset($temp_ids[array_search($p['id'], $temp_ids)]);
         $p['delete_url'] = str_replace('%ID%', implode(',', $temp_ids), $compare_link);
         if (!$temp_ids) {
             $p['delete_url'] = substr($p['delete_url'], 0, -1);
         }
         foreach ($p->features as $code => $v) {
             if (is_object($v)) {
                 $v = trim(isset($v['compare']) ? $v['compare'] : $v['value']);
             } elseif (is_array($v)) {
                 foreach ($v as &$_v) {
                     if (is_object($_v)) {
                         $_v = trim(isset($_v['compare']) ? $_v['compare'] : $_v['value']);
                     } else {
                         $_v = trim($_v);
                     }
                     unset($_v);
                 }
                 sort($v, SORT_STRING);
                 $v = serialize($v);
             } else {
                 $v = trim($v);
             }
             if (isset($features[$code]) && $features[$code]['same']) {
                 if ($v !== $features[$code]['value']) {
                     $features[$code]['same'] = false;
                 }
             } else {
                 if (!isset($features[$code])) {
                     $features[$code] = array();
                 }
                 if (!$i) {
                     $features[$code]['same'] = true;
                     $features[$code]['value'] = $v;
                 } else {
                     $features[$code]['same'] = false;
                 }
             }
         }
         foreach ($features as $code => $v) {
             if (!isset($p->features[$code])) {
                 $features[$code]['same'] = false;
             }
         }
         $i++;
         unset($p);
     }
     if ($features) {
         $feature_model = new shopFeatureModel();
         foreach ($all_features = $feature_model->getByCode(array_keys($features)) as $code => $f) {
             $features[$code] += $f;
         }
     }
     $this->view->assign('features', $features);
     $this->view->assign('products', $products);
     $this->setLayout(new shopFrontendLayout());
     $this->setThemeTemplate('compare.html');
 }