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 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 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() { $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; }
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; }
protected function workupProducts(&$products) { $currency = $this->getConfig()->getCurrency(); foreach ($products as &$p) { if ($p['min_price'] == $p['max_price']) { $p['price_range'] = wa_currency($p['min_price'], $currency); } else { $p['price_range'] = wa_currency($p['min_price'], $currency) . '...' . wa_currency($p['max_price'], $currency); } if ($p['badge']) { $p['badge'] = shopHelper::getBadgeHtml($p['badge']); } unset($p['meta_description'], $p['meta_keywords'], $p['meta_title'], $p['description'], $p['summary']); } unset($p); if ($this->sort == 'count') { foreach ($products as &$p) { $p['icon'] = shopHelper::getStockCountIcon($p['count']); } } else { if ($this->sort == 'create_datetime') { foreach ($products as &$p) { $p['create_datetime_str'] = wa_date('humandatetime', $p['create_datetime']); } } else { if ($this->sort == 'rating') { foreach ($products as &$p) { $p['rating_str'] = shopHelper::getRatingHtml($p['rating'], 10, true); } } else { if ($this->sort == 'total_sales') { $currency = wa('shop')->getConfig()->getCurrency(); foreach ($products as &$p) { $p['total_sales_str'] = wa_currency($p['total_sales'], $currency); } } } } } unset($p); $info = $this->collection->getInfo(); if ($info['hash'] == 'category') { $product_ids = array_keys($products); $category_products_model = new shopCategoryProductsModel(); $ids = $category_products_model->filterByEnteringInCategories($product_ids, $info['id']); $ids = array_flip($ids); foreach ($products as $id => &$product) { $product['alien'] = $info['type'] == shopCategoryModel::TYPE_STATIC && !isset($ids[$id]); } unset($product); } }
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; }
/** * 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); } }
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'); }
private function getCategorySettings($id) { $category_model = new shopCategoryModel(); $category_params_model = new shopCategoryParamsModel(); $settings = $category_model->getById($id); if (!$settings) { return array(); } /** * @event backend_category_dialog * @param array $category * @return array[string][string] $return[%plugin_id%] html output for dialog */ $this->view->assign('event_dialog', wa()->event('backend_category_dialog', $settings)); $category_routes_model = new shopCategoryRoutesModel(); $settings['routes'] = $category_routes_model->getRoutes($id); $settings['frontend_urls'] = array(); foreach ($category_model->getFrontendUrls($id) as $frontend_url) { $pos = strrpos($frontend_url, $settings['url']); $settings['frontend_urls'][] = array('url' => $frontend_url, 'base' => $pos !== false ? rtrim(substr($frontend_url, 0, $pos), '/') . '/' : ''); } $settings['params'] = $category_params_model->get($id); if (isset($settings['params']['enable_sorting'])) { $settings['enable_sorting'] = 1; unset($settings['params']['enable_sorting']); } else { $settings['enable_sorting'] = 0; } $feature_model = new shopFeatureModel(); $selectable_and_boolean_features = $feature_model->select('*')->where("(selectable=1 OR type='boolean' OR type='double' OR type LIKE 'dimension\\.%' OR type LIKE 'range\\.%') AND parent_id IS NULL")->fetchAll('id'); if ($settings['type'] == shopCategoryModel::TYPE_DYNAMIC) { if ($settings['conditions']) { $settings['conditions'] = shopProductsCollection::parseConditions($settings['conditions']); } else { $settings['conditions'] = array(); } $tag_model = new shopTagModel(); $cloud = $tag_model->getCloud('name'); if (!empty($settings['conditions']['tag'][1])) { foreach ($settings['conditions']['tag'][1] as $tag_name) { $cloud[$tag_name]['checked'] = true; } } $settings['cloud'] = $cloud; // extract conditions for features foreach ($settings['conditions'] as $name => $value) { if (substr($name, -9) === '.value_id') { unset($settings['conditions'][$name]); $settings['conditions']['feature'][substr($name, 0, -9)] = $value; } } $settings['custom_conditions'] = $this->extractCustomConditions($settings['conditions']); $settings['features'] = $selectable_and_boolean_features; $settings['features'] = $feature_model->getValues($settings['features']); } $filter = $settings['filter'] !== null ? explode(',', $settings['filter']) : null; $feature_filter = array(); $features['price'] = array('id' => 'price', 'name' => 'Price'); $features += $selectable_and_boolean_features; if (!empty($filter)) { foreach ($filter as $feature_id) { $feature_id = trim($feature_id); if (isset($features[$feature_id])) { $feature_filter[$feature_id] = $features[$feature_id]; $feature_filter[$feature_id]['checked'] = true; unset($features[$feature_id]); } } } $settings['allow_filter'] = (bool) $filter; $settings['filter'] = $feature_filter + $features; return $settings; }
public function execute() { $category = $this->getCategory(); $this->addCanonical(); // breadcrumbs $root_category_id = $category['id']; if ($category['parent_id']) { $breadcrumbs = array(); $path = array_reverse($this->getModel()->getPath($category['id'])); $root_category = reset($path); $root_category_id = $root_category['id']; foreach ($path as $row) { $breadcrumbs[] = array('url' => wa()->getRouteUrl('/frontend/category', array('category_url' => waRequest::param('url_type') == 1 ? $row['url'] : $row['full_url'])), 'name' => $row['name']); } if ($breadcrumbs) { $this->view->assign('breadcrumbs', $breadcrumbs); } } $this->view->assign('root_category_id', $root_category_id); // sort if ($category['type'] == shopCategoryModel::TYPE_DYNAMIC && !$category['sort_products']) { $category['sort_products'] = 'create_datetime DESC'; } if ($category['sort_products'] && !waRequest::get('sort')) { $sort = explode(' ', $category['sort_products']); $this->view->assign('active_sort', $sort[0] == 'count' ? 'stock' : $sort[0]); } elseif (!$category['sort_products'] && !waRequest::get('sort')) { $this->view->assign('active_sort', ''); } $this->view->assign('category', $category); // products $collection = new shopProductsCollection('category/' . $category['id']); // filters if ($category['filter']) { $filter_ids = explode(',', $category['filter']); $feature_model = new shopFeatureModel(); $features = $feature_model->getById(array_filter($filter_ids, 'is_numeric')); if ($features) { $features = $feature_model->getValues($features); } $category_value_ids = $collection->getFeatureValueIds(); $filters = array(); foreach ($filter_ids as $fid) { if ($fid == 'price') { $range = $collection->getPriceRange(); if ($range['min'] != $range['max']) { $filters['price'] = array('min' => shop_currency($range['min'], null, null, false), 'max' => shop_currency($range['max'], null, null, false)); } } elseif (isset($features[$fid]) && isset($category_value_ids[$fid])) { $filters[$fid] = $features[$fid]; $min = $max = $unit = null; foreach ($filters[$fid]['values'] as $v_id => $v) { if (!in_array($v_id, $category_value_ids[$fid])) { unset($filters[$fid]['values'][$v_id]); } else { if ($v instanceof shopRangeValue) { $begin = $this->getFeatureValue($v->begin); if ($min === null || $begin < $min) { $min = $begin; } $end = $this->getFeatureValue($v->end); if ($max === null || $end > $max) { $max = $end; if ($v->end instanceof shopDimensionValue) { $unit = $v->end->unit; } } } else { $tmp_v = $this->getFeatureValue($v); if ($min === null || $tmp_v < $min) { $min = $tmp_v; } if ($max === null || $tmp_v > $max) { $max = $tmp_v; if ($v instanceof shopDimensionValue) { $unit = $v->unit; } } } } } if (!$filters[$fid]['selectable'] && ($filters[$fid]['type'] == 'double' || substr($filters[$fid]['type'], 0, 6) == 'range.' || substr($filters[$fid]['type'], 0, 10) == 'dimension.')) { if ($min == $max) { unset($filters[$fid]); } else { $type = preg_replace('/^[^\\.]*\\./', '', $filters[$fid]['type']); if ($type != 'double') { $filters[$fid]['base_unit'] = shopDimension::getBaseUnit($type); $filters[$fid]['unit'] = shopDimension::getUnit($type, $unit); if ($filters[$fid]['base_unit']['value'] != $filters[$fid]['unit']['value']) { $dimension = shopDimension::getInstance(); $min = $dimension->convert($min, $type, $filters[$fid]['unit']['value']); $max = $dimension->convert($max, $type, $filters[$fid]['unit']['value']); } } $filters[$fid]['min'] = $min; $filters[$fid]['max'] = $max; } } } } $this->view->assign('filters', $filters); $this->setCollection($collection); // fix prices $products = $this->view->getVars('products'); $product_ids = array(); foreach ($products as $p_id => $p) { if ($p['sku_count'] > 1) { $product_ids[] = $p_id; } } if ($product_ids) { $min_price = $max_price = null; $tmp = array(); foreach ($filters as $fid => $f) { if ($fid == 'price') { $min_price = waRequest::get('price_min'); if (!empty($min_price)) { $min_price = (double) $min_price; } else { $min_price = null; } $max_price = waRequest::get('price_max'); if (!empty($max_price)) { $max_price = (double) $max_price; } else { $max_price = null; } } else { $fvalues = waRequest::get($f['code']); if ($fvalues && !isset($fvalues['min']) && !isset($fvalues['max'])) { $tmp[$fid] = $fvalues; } } } $product_skus = array(); if ($tmp) { $pf_model = new shopProductFeaturesModel(); $product_skus = $pf_model->getSkusByFeatures($product_ids, $tmp); } elseif ($min_price || $max_price) { $ps_model = new shopProductSkusModel(); $rows = $ps_model->getByField('product_id', $product_ids, true); foreach ($rows as $row) { $product_skus[$row['product_id']][] = $row; } } $default_currency = $this->getConfig()->getCurrency(true); if ($product_skus) { foreach ($product_skus as $product_id => $skus) { $currency = $products[$product_id]['currency']; usort($skus, array($this, 'sortSkus')); $k = 0; if ($min_price || $max_price) { foreach ($skus as $i => $sku) { if ($min_price) { $tmp_price = shop_currency($min_price, true, $currency, false); if ($sku['price'] < $tmp_price) { continue; } } if ($max_price) { $tmp_price = shop_currency($max_price, true, $currency, false); if ($sku['price'] > $tmp_price) { continue; } } $k = $i; break; } } $sku = $skus[$k]; if ($products[$product_id]['sku_id'] != $sku['id']) { $products[$product_id]['sku_id'] = $sku['id']; $products[$product_id]['frontend_url'] .= '?sku=' . $sku['id']; $products[$product_id]['price'] = shop_currency($sku['price'], $currency, $default_currency, false); $products[$product_id]['compare_price'] = shop_currency($sku['compare_price'], $currency, $default_currency, false); } } $this->view->assign('products', $products); } } } else { $this->setCollection($collection); } //отображение дополнительных размеров $products = $this->view->getVars('products'); $product_features_model = new shopProductFeaturesSelectableModel(); foreach ($products as &$p) { $sku_features = $product_features_model->getByProduct($p['id']); $sizes = $sku_features[3]; if (!$sizes) { $p['sizes'] = array(); continue; } $pf_names = $product_features_model->query("SELECT `id`, `value` FROM shop_feature_values_varchar where `id` IN (" . implode(',', $sizes) . ') ORDER BY `sort`;')->fetchAll(); foreach ($pf_names as $key => $val) { $sizes[$val['id']] = $val['value']; } $p['sizes'] = $pf_names; } //отображение всех картинок foreach ($products as &$p) { $images_full = shopViewHelper::images($p['id']); if (isset($images_full[$p['id']])) { $p['image_ids'] = array_keys($images_full[$p['id']]); } } $this->view->assign('products', $products); // set meta $title = $category['meta_title'] ? $category['meta_title'] : $category['name']; wa()->getResponse()->setTitle($title); wa()->getResponse()->setMeta('keywords', $category['meta_keywords']); wa()->getResponse()->setMeta('description', $category['meta_description']); /** * @event frontend_category * @return array[string]string $return[%plugin_id%] html output for category */ $this->view->assign('frontend_category', wa()->event('frontend_category', $category)); $this->setThemeTemplate('category.html'); }
public function productsCount($hash = '') { $collection = new shopProductsCollection($hash); return $collection->count(); }