Example #1
0
 public function execute()
 {
     $search = new shopIndexSearch();
     if (waRequest::param(0)) {
         $search->indexProduct(waRequest::param(0));
     } else {
         $product_model = new shopProductModel();
         $n = $product_model->countAll();
         $limit = 100;
         $i = 0;
         $product_model->exec("TRUNCATE TABLE shop_search_index");
         while ($i < $n) {
             echo $i . "/" . $n . "\n";
             $sql = "SELECT p.*, t.name type_name FROM " . $product_model->getTableName() . " p\n                LEFT JOIN shop_type t ON p.type_id = t.id\n                LIMIT " . $i . ", " . $limit;
             $products = $product_model->query($sql)->fetchAll('id');
             $product_ids = array_keys($products);
             // get skus
             $sql = "SELECT * FROM shop_product_skus WHERE product_id IN (i:id)";
             $data = $product_model->query($sql, array('id' => $product_ids));
             foreach ($data as $row) {
                 $products[$row['product_id']]['skus'][] = $row;
             }
             // get tags
             $sql = "SELECT pt.product_id, t.name FROM shop_product_tags pt\n                JOIN shop_tag t ON pt.tag_id = t.id WHERE pt.product_id IN (i:id)";
             $data = $product_model->query($sql, array('id' => $product_ids));
             foreach ($data as $row) {
                 $products[$row['product_id']]['tags'][] = $row['name'];
             }
             // get features
             $sql = "SELECT pf.product_id, fv.value FROM shop_product_features pf\n                JOIN shop_feature f ON pf.feature_id = f.id AND f.type = 'varchar'\n                JOIN shop_feature_values_varchar fv ON pf.feature_value_id = fv.id WHERE pf.product_id IN (i:id)";
             $data = $product_model->query($sql, array('id' => $product_ids));
             foreach ($data as $row) {
                 $products[$row['product_id']]['features'][] = $row['value'];
             }
             $sql = "SELECT pf.product_id, fv.value FROM shop_product_features pf\n                JOIN shop_feature f ON pf.feature_id = f.id AND f.type = 'double'\n                JOIN shop_feature_values_double fv ON pf.feature_value_id = fv.id WHERE pf.product_id IN (i:id)";
             $data = $product_model->query($sql, array('id' => $product_ids));
             foreach ($data as $row) {
                 $products[$row['product_id']]['features'][] = $row['value'];
             }
             $sql = "SELECT pf.product_id, fv.value FROM shop_product_features pf\n                JOIN shop_feature f ON pf.feature_id = f.id AND f.type = 'text'\n                JOIN shop_feature_values_text fv ON pf.feature_value_id = fv.id WHERE pf.product_id IN (i:id)";
             $data = $product_model->query($sql, array('id' => $product_ids));
             foreach ($data as $row) {
                 $products[$row['product_id']]['features'][] = $row['value'];
             }
             // get skus
             $sql = "SELECT * FROM shop_product_skus WHERE product_id IN (i:id)";
             $data = $product_model->query($sql, array('id' => $product_ids));
             foreach ($data as $row) {
                 $products[$row['product_id']]['skus'][] = $row;
             }
             foreach ($products as $p) {
                 $search->indexProduct($p, false);
             }
             $i += $limit;
         }
     }
 }
 public function execute()
 {
     if (!$this->getUser()->isAdmin('shop') && !wa()->getUser()->getRights('shop', 'type.%')) {
         throw new waRightsException('Access denied');
     }
     $this->setLayout(new shopBackendLayout());
     $this->getResponse()->setTitle(_w('Products'));
     $this->view->assign('categories', new shopCategories());
     $tag_model = new shopTagModel();
     $this->view->assign('cloud', $tag_model->getCloud());
     $set_model = new shopSetModel();
     $this->view->assign('sets', $set_model->getAll());
     $collapse_types = wa()->getUser()->getSettings('shop', 'collapse_types');
     if (empty($collapse_types)) {
         $type_model = new shopTypeModel();
         $this->view->assign('types', $type_model->getTypes());
     } else {
         $this->view->assign('types', false);
     }
     $product_model = new shopProductModel();
     $this->view->assign('count_all', $product_model->countAll());
     $review_model = new shopProductReviewsModel();
     $this->view->assign('count_reviews', array('all' => $review_model->count(null, false), 'new' => $review_model->countNew(true)));
     $product_services = new shopServiceModel();
     $this->view->assign('count_services', $product_services->countAll());
     $config = $this->getConfig();
     $this->view->assign('default_view', $config->getOption('products_default_view'));
     /*
      * @event backend_products
      * @return array[string]array $return[%plugin_id%] array of html output
      * @return array[string][string]string $return[%plugin_id%]['sidebar_top_li'] html output
      * @return array[string][string]string $return[%plugin_id%]['sidebar_section'] html output
      */
     $this->view->assign('backend_products', wa()->event('backend_products'));
     $this->view->assign('sidebar_width', $config->getSidebarWidth());
     $this->view->assign('lang', substr(wa()->getLocale(), 0, 2));
 }
 public function getLists()
 {
     $product_model = new shopProductModel();
     $category_model = $this->getModel('category');
     $set_model = $this->getModel('set');
     $type_model = $this->getModel('type');
     return array('category' => $category_model->getAll('id'), 'set' => $set_model->getAll('id'), 'type' => $type_model->getAll('id'), 'all' => array('count' => $product_model->countAll()));
 }