public function execute() { $type_model = new shopTypeModel(); $types = $type_model->getAll('id'); $category_model = new shopCategoryModel(); $categories = $category_model->getFullTree('id, name, depth', true); $features_model = new shopFeatureModel(); $features = $features_model->getAll('id'); $data = array(); $type_values = array(); foreach ($types as $type_id => $type) { $type_values[] = array($type_id, $type['name']); $data[$type_id]['price'] = array('feature' => 'price'); $data[$type_id]['type_id'] = array('feature' => 'type_id'); $data[$type_id]['tag'] = array('feature' => 'tag'); } $type_features_model = new shopTypeFeaturesModel(); $rows = $type_features_model->getAll(); foreach ($rows as $row) { if (isset($features[$row['feature_id']])) { $code = $features[$row['feature_id']]['code']; $data[$row['type_id']][$code] = array('feature' => $code, 'feature_id' => $row['feature_id']); } } $type_upselling_model = new shopTypeUpsellingModel(); $rows = $type_upselling_model->getAll(); foreach ($rows as $row) { $data[$row['type_id']][$row['feature']] = array('feature_id' => $row['feature_id'], 'feature' => $row['feature'], 'cond' => $row['cond'], 'value' => $row['value']); } foreach ($data as &$row) { $row = array_values($row); } unset($row); foreach ($types as &$type) { if ($type['upselling']) { $type['upselling_html'] = self::getConditionHTML($data[$type['id']], $features); } } unset($type); $fids = array(); foreach ($features as $f_key => $f) { $features[$f_key]['selectable'] = (int) $f['selectable']; $features[$f_key]['multiple'] = (int) $f['multiple']; if ($f['selectable']) { $fids[$f['id']] = $f; } } if ($fids) { $fids = $features_model->getValues($fids); foreach ($fids as $feature_id => $f) { foreach ($f['values'] as $value_id => $value) { $features[$feature_id]['values'][] = array($value_id, $value); } } unset($fids); } $features['type_id'] = array('name' => _w('Type'), 'type' => 'varchar', 'selectable' => 1, 'values' => $type_values); $this->view->assign(array('types' => $types, 'categories' => $categories, 'features' => $features, 'data' => $data)); }
public function execute() { $feature_model = new shopFeatureModel(); if ($type_id = waRequest::get('type_id')) { $features = $feature_model->getByType($type_id, 'id'); } else { $features = $feature_model->getAll('id'); } $selectable = array(); foreach ($features as $f_id => $f) { if ($f['selectable']) { $selectable[$f_id] = $f; } } if ($selectable) { $selectable = $feature_model->getValues($selectable); foreach ($selectable as $f_id => $f) { $f['values'] = array_values($f['values']); $f['values']['_element'] = 'value'; $features[$f_id] = $f; } } $this->response = $features; $this->response['_element'] = 'feature'; }
public function execute() { $this->setLayout(new shopBackendLayout()); if ($data = waRequest::post('lang_plugin')) { $this->save($data); } $plugin = wa('shop')->getPlugin('lang'); $lang = $plugin->getSettings('langs'); $this->view->assign('langs', $lang); $fm = new shopFeatureModel(); $features = $fm->getAll(); $features = $fm->getValues($features, true); $this->view->assign('features', $features); $lm = new shopLangPluginFeatureModel(); $data = $lm->getTree(); $this->view->assign('data', $data); }
private function initExport() { $hash = shopImportexportHelper::getCollectionHash(); $this->data['export_category'] = !in_array($hash['type'], array('id', 'set', 'type')); $this->data['timestamp'] = time(); $this->data['hash'] = $hash['hash']; $encoding = waRequest::post('encoding', 'utf-8'); $options = array(); $config = array('encoding' => $encoding, 'delimiter' => waRequest::post('delimiter', ';'), 'features' => !!waRequest::post('features'), 'images' => !!waRequest::post('images'), 'extra' => !!waRequest::post('extra'), 'domain' => waRequest::post('domain'), 'hash' => $hash['hash']); $map = shopCsvProductuploadController::getMapFields(true, $config['extra']); $this->data['composite_features'] = array(); $features_model = new shopFeatureModel(); if (!empty($config['features'])) { if (preg_match('@^id/(.+)$@', $this->data['hash'], $matches)) { $product_ids = array_unique(array_map('intval', explode(',', $matches[1]))); $features = $features_model->getByProduct($product_ids); $feature_selectable_model = new shopProductFeaturesSelectableModel(); $feature_ids = $feature_selectable_model->getFeatures($product_ids); if ($feature_ids = array_diff($feature_ids, array_keys($features))) { $features += $features_model->getById($feature_ids); } $parents = array(); foreach ($features as $feature) { if (!empty($feature['parent_id'])) { if (!isset($parents[$feature['parent_id']])) { $parents[$feature['parent_id']] = $feature['parent_id']; } } } if ($parents) { $features += $features_model->getById($parents); } } else { $features = $features_model->getAll(); } if ($features) { $options['features'] = true; foreach ($features as $feature) { if (!preg_match('/\\.\\d$/', $feature['code']) && $feature['type'] != shopFeatureModel::TYPE_DIVIDER) { $map[sprintf('features:%s', $feature['code'])] = $feature['name']; if ($encoding != 'UTF-8') { $this->data['composite_features'][$feature['code']] = true; } } } } } $tax_model = new shopTaxModel(); if ($taxes = $tax_model->getAll()) { $this->data['taxes'] = array(); foreach ($taxes as $tax) { $this->data['taxes'][$tax['id']] = $tax['name']; } } if (!empty($config['images'])) { $sql = 'SELECT COUNT(1) AS `cnt` FROM `shop_product_images` GROUP BY `product_id` ORDER BY `cnt` DESC LIMIT 1'; if ($cnt = $features_model->query($sql)->fetchField('cnt')) { $options['images'] = true; for ($n = 0; $n < $cnt; $n++) { $field = sprintf('images:%d', $n); $map[$field] = _w('Product images'); } } if (isset($map['images'])) { unset($map['images']); } } else { if (isset($map['images'])) { unset($map['images']); } foreach (array_keys($map) as $field) { if (preg_match('@^images:\\d+$@', $field)) { unset($map[$field]); } } } $profile_helper = new shopImportexportHelper('csv:product:export'); $profile = $profile_helper->setConfig($config); $profile_raw = waRequest::request('profile', array(), waRequest::TYPE_ARRAY); $profile_name = substr(waLocale::transliterate(ifempty($profile_raw['name'], $profile)), 0, 32); $name = sprintf('products(%s)_%s_%s.csv', $profile_name, date('Y-m-d'), strtolower($encoding)); $name = preg_replace('@[^A-Za-z0-9\\-\\(\\),_\\.]+@', '', $name); $file = wa()->getTempPath('csv/download/' . $profile . '/' . $name); $this->writer = new shopCsvWriter($file, $config['delimiter'], $encoding); $this->writer->setMap($map); $this->data['file'] = serialize($this->writer); $this->data['map'][self::STAGE_CATEGORY] = null; $this->data['map'][self::STAGE_PRODUCT] = 0; $this->data['config'] = $config; $this->data['options'] = $options; $this->initRouting(); $this->data['count'] = array(self::STAGE_PRODUCT => $this->getCollection()->count(), self::STAGE_CATEGORY => 0, self::STAGE_SKU => null, self::STAGE_IMAGE => null); if ($this->data['export_category']) { $model = new shopCategoryModel(); if (preg_match('@^category/(\\d+)$@', $this->data['hash'], $matches)) { $this->data['count'][self::STAGE_CATEGORY] = count($model->getPath($matches[1])) + 1; //TODO add subcategories for nested //$model->getTree($matches[1]); } else { $this->data['count'][self::STAGE_CATEGORY] = $model->countByField('type', shopCategoryModel::TYPE_STATIC); } } }