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() { $id = $this->get('id', true); $this->getProduct($id); $tags = $this->post('tags', true); $product_tags_model = new shopProductTagsModel(); $product_tags_model->deleteTags($id, $tags); $this->response = true; }
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'); }
private function stepExportProduct(&$current_stage, &$count, &$processed) { static $products; static $product_feature_model; static $feature_model; static $tags_model; static $size; if (!$products) { $offset = $current_stage[self::STAGE_PRODUCT] - ifset($this->data['map'][self::STAGE_PRODUCT], 0); $fields = '*'; if (!empty($this->data['options']['images'])) { $fields .= ', images'; } $products = $this->getCollection()->getProducts($fields, $offset, 50, false); } $chunk = 5; $non_sku_fields = array('summary', 'meta_title', 'meta_keywords', 'meta_description', 'description', 'sort', 'tags', 'images'); while ($chunk-- > 0 && ($product = reset($products))) { $exported = false; /* check rights per product type && settlement options */ $rights = empty($product['type_id']) || in_array($product['type_id'], $this->data['types']); $category_id = isset($product['category_id']) ? intval($product['category_id']) : null; /* check category match*/ $category_match = !$this->data['export_category'] || $category_id === $this->data['map'][self::STAGE_CATEGORY]; if ($rights && $category_match) { $shop_product = new shopProduct($product); if (!empty($this->data['options']['features'])) { if (!isset($product['features'])) { if (!$product_feature_model) { $product_feature_model = new shopProductFeaturesModel(); } $product['features'] = $product_feature_model->getValues($product['id']); } foreach ($product['features'] as $code => &$feature) { if (!empty($this->data['composite_features'][$code])) { $feature = str_replace('×', 'x', $feature); } unset($feature); } } if (!isset($product['tags'])) { if (!$tags_model) { $tags_model = new shopProductTagsModel(); } $product['tags'] = implode(',', $tags_model->getTags($product['id'])); } if (!empty($this->data['options']['images'])) { if (isset($product['images'])) { if (!$size) { /** * @var shopConfig $config */ $config = $this->getConfig(); $size = $config->getImageSize('big'); } foreach ($product['images'] as &$image) { $image = 'http://' . ifempty($this->data['base_url'], 'localhost') . shopImage::getUrl($image, $size); } $product['images'] = array_values($product['images']); } } $product['type_name'] = $shop_product->type['name']; $skus = $shop_product->skus; if (false && $product['sku_id']) { #default SKU reorder if (isset($skus[$product['sku_id']])) { $sku = $skus[$product['sku_id']]; $sku['stock'][0] = $sku['count']; $product['skus'] = array(-1 => $sku); unset($skus[$product['sku_id']]); } $this->writer->write($product); if (!empty($this->data['options']['images'])) { if (isset($product['images'])) { $processed[self::STAGE_IMAGE] += count($product['images']); } } $exported = true; if (!empty($this->data['options']['features'])) { unset($product['features']); } } if (!empty($product['tax_id'])) { $product['tax_name'] = ifset($this->data['taxes'][$product['tax_id']]); } if (!isset($product['features'])) { $product['features'] = array(); } foreach ($skus as $sku_id => $sku) { if ($exported) { foreach ($non_sku_fields as $field) { if (isset($product[$field])) { unset($product[$field]); } } } $sku['stock'][0] = $sku['count']; if (!empty($this->data['options']['features'])) { $sku['features'] = $product_feature_model->getValues($product['id'], -$sku_id); if ($product['sku_type'] == shopProductModel::SKU_TYPE_SELECTABLE) { if (!$exported) { $features_selectable_model = new shopProductFeaturesSelectableModel(); if ($selected = $features_selectable_model->getByProduct($product['id'])) { if (!$feature_model) { $feature_model = new shopFeatureModel(); } $features = $feature_model->getById(array_keys($selected)); $enclosure = $this->writer->enclosure; $pattern = sprintf("/(?:%s|%s|%s)/", preg_quote(',', '/'), preg_quote($enclosure, '/'), preg_quote($enclosure, '/')); foreach ($features as $feature_id => $feature) { $values = shopFeatureModel::getValuesModel($feature['type'])->getValues(array('feature_id' => $feature_id, 'id' => $selected[$feature_id])); if (!empty($values[$feature['id']])) { $f_values = $values[$feature['id']]; if (!isset($product['features'])) { $product['features'] = array(); } if (isset($sku['features'][$feature['code']])) { array_unshift($f_values, (string) $sku['features'][$feature['code']]); } foreach ($f_values as &$value) { if (preg_match($pattern, $value)) { $value = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $value) . $enclosure; } unset($value); } $f_values = array_unique($f_values); $product['features'][$feature['code']] = '<{' . implode(',', $f_values) . '}>'; } } } $virtual_product = $product; if (isset($skus[$product['sku_id']])) { $virtual_product['skus'] = array(-1 => $skus[$product['sku_id']]); } else { $virtual_product['skus'] = array(-1 => $sku); } $virtual_product['skus'][-1]['stock'] = array(0 => $product['count']); $this->writer->write($virtual_product); } $product['features'] = $sku['features']; } else { if (!$exported) { foreach ($product['features'] as $code => &$values) { if (isset($sku['features'][$code])) { $values = array_unique(array_merge($values, $sku['features'][$code])); } unset($values); } } else { $product['features'] = $sku['features']; } } } $product['skus'] = array(-1 => $sku); $this->writer->write($product); if (isset($product['images'])) { $processed[self::STAGE_IMAGE] += count($product['images']); } $exported = true; ++$current_stage[self::STAGE_SKU]; ++$processed[self::STAGE_SKU]; } } elseif (count($products) > 1) { ++$chunk; } array_shift($products); ++$current_stage[self::STAGE_PRODUCT]; if ($exported) { ++$processed[self::STAGE_PRODUCT]; } } return $current_stage[self::STAGE_PRODUCT] < $count[self::STAGE_PRODUCT]; }
<?php $model = new waModel(); // correct tag counters $sql = "\n UPDATE `shop_tag` t JOIN (\n SELECT t.id, t.name, t.count, COUNT(pt.product_id) AS product_count\n FROM `shop_tag` t\n LEFT JOIN `shop_product_tags` pt ON t.id = pt.tag_id\n GROUP BY t.id\n ) r ON t.id = r.id\n SET t.count = r.product_count\n"; $model->exec($sql); $sql = "\n SELECT DISTINCT pt.tag_id\n FROM `shop_product_tags` pt\n LEFT JOIN `shop_tag` t ON pt.tag_id = t.id\n WHERE t.id IS NULL\n"; // delete hanging product-tag items $ids = array_keys($model->query($sql)->fetchAll('tag_id')); if ($ids) { $shop_product_tag = new shopProductTagsModel(); $shop_product_tag->deleteByField('tag_id', $ids); }