コード例 #1
0
 public function execute()
 {
     $this->tm = $tm = new shopTaxModel();
     $taxes = $tm->getAll('id');
     $tax_id = waRequest::request('id');
     if (!$tax_id) {
         $tax_id = $taxes ? key($taxes) : 'new';
     }
     if (!empty($taxes[$tax_id])) {
         $tax = $taxes[$tax_id];
     } else {
         if ($tax_id == 'new') {
             $tax = $tm->getEmptyRow();
             $tax_id = null;
         } else {
             throw new waException('Tax record not found.', 404);
         }
     }
     $this->trm = $trm = new shopTaxRegionsModel();
     $this->tzcm = $tzcm = new shopTaxZipCodesModel();
     $countries = $this->getCountryList();
     $tax = $this->processPostData($tax);
     if ($tax['id'] && !$tax_id) {
         $tax_id = $tax['id'];
     }
     if ($tax_id) {
         $taxes[$tax_id] = $tax;
     }
     uasort($taxes, wa_lambda('$a,$b', 'return strcmp($a["name"], $b["name"]);'));
     $this->view->assign('tax_countries', $this->getTaxCountries($tax, $countries));
     $this->view->assign('tax_zip_codes', $this->getTaxZipCodes($tax));
     $this->view->assign('countries', $countries);
     $this->view->assign('taxes', $taxes);
     $this->view->assign('tax', $tax);
     $checkout_settings = $this->getConfig()->getCheckoutSettings();
     $this->view->assign('billing_address_required', isset($checkout_settings['contactinfo']['fields']['address.billing']));
 }
コード例 #2
0
 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);
         }
     }
 }
コード例 #3
0
 public function getTaxes()
 {
     $tax_model = new shopTaxModel();
     return $tax_model->getAll('id');
 }
コード例 #4
0
 public function execute()
 {
     $product = new shopProduct(waRequest::get('id', 0, waRequest::TYPE_INT));
     if (!$product->id) {
         if (waRequest::get('id') == 'new') {
             $product->name = '';
             $product->id = 'new';
             $product->status = 1;
         } else {
             throw new waException("Product not found", 404);
         }
     }
     $counters = array('reviews' => 0, 'images' => 0, 'pages' => 0, 'services' => 0);
     $sidebar_counters = array();
     $config = $this->getConfig();
     /**
      * @var shopConfig $config
      */
     #load product types
     $type_model = new shopTypeModel();
     $product_types = $type_model->getTypes(true);
     $product_types_count = count($product_types);
     if (intval($product->id)) {
         # 1 fill extra product data
         # 1.1 fill product reviews
         $product_reviews_model = new shopProductReviewsModel();
         $product['reviews'] = $product_reviews_model->getReviews($product->id, 0, $config->getOption('reviews_per_page_product'), 'datetime DESC', array('is_new' => true));
         $counters['reviews'] = $product_reviews_model->count($product->id);
         $sidebar_counters['reviews'] = array('new' => $product_reviews_model->countNew());
         $counters['images'] = count($product['images']);
         $product_pages_model = new shopProductPagesModel();
         $counters['pages'] = $product_pages_model->count($product->id);
         $product_services_model = new shopProductServicesModel();
         $counters['services'] = $product_services_model->countServices($product->id);
         $product_stocks_log_model = new shopProductStocksLogModel();
         $counters['stocks_log'] = $product_stocks_log_model->countByField('product_id', $product->id);
         $this->view->assign('edit_rights', $product->checkRights());
     } else {
         $counters += array_fill_keys(array('images', 'services', 'pages', 'reviews'), 0);
         $product['images'] = array();
         reset($product_types);
         $product->type_id = 0;
         if ($product_types_count) {
             if (!$product_types) {
                 throw new waRightsException(_w("Access denied"));
             } else {
                 reset($product_types);
                 $product->type_id = key($product_types);
             }
         } elseif (!$product->checkRights()) {
             throw new waRightsException(_w("Access denied"));
         }
         $this->view->assign('edit_rights', true);
         $product['skus'] = array('-1' => array('id' => -1, 'sku' => '', 'available' => 1, 'name' => '', 'price' => 0.0, 'purchase_price' => 0.0, 'count' => null, 'stock' => array(), 'virtual' => 0));
         $product->currency = $config->getCurrency();
     }
     $this->assignReportsData($product);
     $stock_model = new shopStockModel();
     $taxes_mode = new shopTaxModel();
     $this->view->assign('stocks', $stock_model->getAll('id'));
     $this->view->assign(array('use_product_currency' => wa()->getSetting('use_product_currency'), 'currencies' => $this->getCurrencies(), 'primary_currency' => $config->getCurrency(), 'taxes' => $taxes_mode->getAll()));
     $category_model = new shopCategoryModel();
     $categories = $category_model->getFullTree('id, name, depth, url, full_url, parent_id', true);
     $frontend_urls = array();
     if (intval($product->id)) {
         $routing = wa()->getRouting();
         $domain_routes = $routing->getByApp($this->getAppId());
         foreach ($domain_routes as $domain => $routes) {
             foreach ($routes as $r) {
                 if (!empty($r['private'])) {
                     continue;
                 }
                 if (empty($r['type_id']) || in_array($product->type_id, (array) $r['type_id'])) {
                     $routing->setRoute($r, $domain);
                     $params = array('product_url' => $product->url);
                     if ($product->category_id && isset($categories[$product->category_id])) {
                         if (!empty($r['url_type']) && $r['url_type'] == 1) {
                             $params['category_url'] = $categories[$product->category_id]['url'];
                         } else {
                             $params['category_url'] = $categories[$product->category_id]['full_url'];
                         }
                     }
                     $frontend_url = $routing->getUrl('/frontend/product', $params, true);
                     $frontend_urls[] = array('url' => $frontend_url);
                 }
             }
         }
     } else {
         $frontend_urls[] = array('url' => wa()->getRouteUrl('/frontend/product', array('product_url' => '%product_url%'), true));
     }
     $stuff = intval($product->id) ? $product->url : '%product_url%';
     foreach ($frontend_urls as &$frontend_url) {
         $pos = strrpos($frontend_url['url'], $stuff);
         $frontend_url['base'] = $pos !== false ? rtrim(substr($frontend_url['url'], 0, $pos), '/') . '/' : $frontend_url['url'];
     }
     unset($frontend_url);
     $product_model = new shopProductModel();
     $this->view->assign('storefront_map', $product_model->getStorefrontMap($product->id));
     /**
      * Backend product profile page
      * UI hook allow extends product profile page
      * @event backend_product
      * @param shopProduct $entry
      * @return array[string][string]string $return[%plugin_id%]['title_suffix'] html output
      * @return array[string][string]string $return[%plugin_id%]['action_button'] html output
      * @return array[string][string]string $return[%plugin_id%]['toolbar_section'] html output
      * @return array[string][string]string $return[%plugin_id%]['image_li'] html output
      */
     $this->view->assign('backend_product', wa()->event('backend_product', $product));
     /**
      * @event backend_product_edit
      */
     $this->view->assign('backend_product_edit', wa()->event('backend_product_edit', $product));
     $this->view->assign('categories', $categories);
     $this->view->assign('counters', $counters);
     $this->view->assign('product', $product);
     $this->view->assign('current_author', shopProductReviewsModel::getAuthorInfo(wa()->getUser()->getId()));
     $this->view->assign('reply_allowed', true);
     $this->view->assign('review_allowed', true);
     $this->view->assign('sidebar_counters', $sidebar_counters);
     $this->view->assign('lang', substr(wa()->getLocale(), 0, 2));
     $this->view->assign('frontend_urls', $frontend_urls);
     $tag_model = new shopTagModel();
     $this->view->assign('popular_tags', $tag_model->popularTags());
     $counts = array();
     // Selectable features
     $features_selectable = $product->features_selectable;
     if (is_array($features_selectable)) {
         foreach ($features_selectable as $f) {
             if ($f['selected']) {
                 $counts[] = $f['selected'];
             }
         }
     }
     $feature_model = new shopTypeFeaturesModel();
     $features_selectable_types = $feature_model->getSkuTypeSelectableTypes();
     foreach ($product_types as $type_id => &$type) {
         $type['sku_type'] = empty($features_selectable_types[$type_id]) ? shopProductModel::SKU_TYPE_FLAT : shopProductModel::SKU_TYPE_SELECTABLE;
     }
     $this->view->assign('features', $features_selectable);
     $this->view->assign('duble', '???');
     $this->view->assign('features_counts', $counts);
     #load product types
     $this->view->assign('product_types', $product_types);
     $this->view->assign('sidebar_width', $config->getSidebarWidth());
 }