コード例 #1
0
 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;
 }
コード例 #2
0
 public function execute()
 {
     if (waRequest::param('url_type') == 2) {
         $product_model = new shopProductModel();
         if (waRequest::param('category_url')) {
             $category_model = new shopCategoryModel();
             $c = $category_model->getByField('full_url', waRequest::param('category_url'));
             if ($c) {
                 $product = $product_model->getByUrl(waRequest::param('product_url'), $c['id']);
                 if ($product && $product['category_id'] != $c['id']) {
                     $c = $category_model->getById($product['category_id']);
                     if ($c) {
                         $this->redirect(wa()->getRouteUrl('shop/frontend/product', array('category_url' => $c['full_url'], 'product_url' => $product['url'])));
                     } else {
                         $product = null;
                     }
                 }
             } else {
                 $product = null;
             }
         } else {
             $product = $product_model->getByField('url', waRequest::param('product_url'));
         }
         if (!$product) {
             // try find page
             $url = waRequest::param('category_url');
             $url_parts = explode('/', $url);
             waRequest::setParam('page_url', waRequest::param('product_url'));
             waRequest::setParam('product_url', end($url_parts));
             $this->executeAction(new shopFrontendProductPageAction());
         } else {
             $this->executeAction(new shopFrontendProductAction($product));
         }
     } else {
         $this->executeAction(new shopFrontendProductAction());
     }
 }
コード例 #3
0
 /**
  * @usedby stepImport
  * @param $data
  * @return bool
  */
 private function stepImportCategory($data)
 {
     /**
      * @var shopCategoryModel $model
      */
     static $model;
     $empty = $this->reader->getEmpty();
     $data += $empty;
     if (!$model) {
         $model = new shopCategoryModel();
     }
     if (!isset($this->data['map'][self::STAGE_CATEGORY])) {
         $this->data['map'][self::STAGE_CATEGORY] = array();
     }
     $stack =& $this->data['map'][self::STAGE_CATEGORY];
     if (preg_match('/^(!{1,})(.+)$/', trim(ifset($data['name'])), $matches)) {
         $data['name'] = $matches[2];
         $depth = strlen($matches[1]);
         $stack = array_slice($stack, 0, $depth);
         $parent_id = end($stack);
         if (!$parent_id) {
             $parent_id = 0;
         }
     } else {
         $stack = array();
         $parent_id = 0;
     }
     $primary = $this->data['primary'];
     if (strpos($primary, 'skus:') === 0) {
         $primary = 'name';
     }
     $fields = array('parent_id' => $parent_id);
     if ($primary) {
         $fields[$primary] = ifset($data[$primary]);
     }
     try {
         self::filterEmptyRows($data, array('url'));
         $key = 'c:';
         if ($current_data = $model->getByField($fields)) {
             $key .= 'u:' . $current_data['id'];
             $stack[] = $current_data['id'];
             if (!$this->emulate($key)) {
                 $target = 'update';
                 if (!$model->update($current_data['id'], $data)) {
                     $target = 'error';
                 }
             } else {
                 $target = 'found';
             }
         } else {
             $key .= 'a:';
             if (!$this->emulate()) {
                 $id = $model->add($data, $parent_id);
                 $model->move($id, null, $parent_id);
                 $stack[] = $id;
                 $target = 'new';
             } else {
                 $stack[] = $this->getKey($fields);
                 $target = 'add';
                 $key .= implode($stack);
                 $this->emulate($key);
             }
         }
     } catch (waDbException $ex) {
         $target = 'error';
         $this->error($ex->getMessage());
     }
     $this->data['processed_count'][self::STAGE_CATEGORY][$target]++;
     return true;
 }