/**
  * 25 Create request_urls and export any photos (from pre 2.5 installs)
  */
 public function actionConvertProductSEO()
 {
     //First, run our request_url creation if needed
     Product::convertSEO(-1);
     Category::ConvertSEO();
     $matches = Yii::app()->db->createCommand('SELECT count(*) FROM ' . Product::model()->tableName() . ' WHERE request_url IS NULL AND title is not null')->queryScalar();
     if ($matches > 0) {
         return array('result' => "success", 'makeline' => 25, 'tag' => 'Creating SEO-friendly URLs ' . $matches . ' remaining', 'total' => 50);
     } else {
         //Getting ready for photo convert, drop any orphaned images with blobs
         _dbx("delete a from xlsws_images as a left join xlsws_product as b on a.id=b.image_id where image_path is null and a.id=a.parent and b.id is null;");
         return array('result' => "success", 'makeline' => 26, 'tag' => 'Installing Amazon categories (group 1 of 14)', 'total' => 50);
     }
 }
Example #2
0
 /**
  * Instead of calling UpdateChildCount iteratively on Active Record
  * objects, we use Data Access Objects instead because they use less
  * PHP memory and some users have A LOT of categories.
  * http://www.yiiframework.com/doc/guide/1.1/en/database.dao
  *
  * @return void
  */
 public static function updateAllChildCounts()
 {
     $arrRows = Yii::app()->db->createCommand('select `id` from `xlsws_category`')->queryAll();
     foreach ($arrRows as $row) {
         $id = $row['id'];
         $sql = 'SELECT COUNT(*) FROM `xlsws_product` as Product ';
         $sql .= 'LEFT JOIN `xlsws_product_category_assn` as ProductAssn ON ProductAssn.product_id = Product.id ';
         // product is current, marked to be sold on Web Store and in the category
         $sql .= "WHERE current = 1 AND web = 1 AND category_id = {$id} AND ";
         // Child products are not allowed to be displayed without their masters / parents.
         // So ignore any child products and only consider master products and regular non-matrix products
         $sql .= '(master_model = 1 OR (master_model = 0 AND parent IS NULL))';
         // When make product disappear for out of stock items is set to ON,
         // then inventoried items must have available inventory
         if (_xls_get_conf('INVENTORY_OUT_ALLOW_ADD', 0) == Product::InventoryMakeDisappear) {
             $sql .= ' AND ((inventoried = 1 AND inventory_avail > 0) OR inventoried = 0)';
         }
         $count = Yii::app()->db->createCommand($sql)->queryScalar();
         $updateSql = "UPDATE `xlsws_category` SET `child_count` = {$count} WHERE `id` = {$id}";
         _dbx($updateSql);
     }
 }
 /**
  * Product lookup and optional delete, shows inventory numbers
  */
 public function actionProducts()
 {
     if (isset($_POST['pk']) && isset($_POST['name']) && isset($_POST['value'])) {
         if ($_POST['name'] == 'code' && $_POST['value'] == "") {
             $items = CartItem::model()->findAll("product_id=" . $_POST['pk'] . " AND (cart_type=" . CartType::order . " OR cart_type=" . CartType::awaitpayment . ")");
             if ($items) {
                 echo "You cannot delete a product that has been used on an order";
             } else {
                 _dbx("set foreign_key_checks=0;");
                 Product::model()->updateAll(array('image_id' => null), 'id =' . $_POST['pk']);
                 Images::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductCategoryAssn::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductRelated::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductRelated::model()->deleteAllByAttributes(array('related_id' => $_POST['pk']));
                 ProductTags::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductQtyPricing::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductText::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 WishlistItem::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 TaskQueue::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 Product::model()->deleteByPk($_POST['pk']);
                 _dbx("set foreign_key_checks=1;");
                 echo "delete";
             }
         } else {
             echo Yii::t('admin', 'You cannot change a product code here. Delete the code to remove it manually from the Web Store database');
         }
     } else {
         $model = new Product();
         if (isset($_GET['q'])) {
             $model->code = $_GET['q'];
         }
         $this->render("products", array('model' => $model));
     }
 }