Пример #1
0
 /**
  * Save chosen third-party category
  */
 public function actionIntCatSave()
 {
     $service = Yii::app()->getRequest()->getQuery('service');
     $strSelected = Yii::app()->getRequest()->getQuery('selected');
     $arrSelected = explode("|", $strSelected);
     if (count($arrSelected) > 1) {
         $objCategory = Category::model()->findByPk($arrSelected[0]);
         if ($objCategory instanceof Category) {
             $strTable = "Category" . ucfirst($service);
             $objIntCategory = $strTable::model()->findByPk($arrSelected[1]);
             if ($objIntCategory instanceof $strTable) {
                 if (!$objIntCategory->isUsable) {
                     echo json_encode(ucfirst($service) . " does not allow you to pick this category without choosing a further subcategory.");
                     return;
                 }
                 CategoryIntegration::model()->deleteAllByAttributes(array('category_id' => $objCategory->id, 'module' => $service));
                 $objCI = new CategoryIntegration();
                 $objCI->category_id = $objCategory->id;
                 $objCI->module = $service;
                 $objCI->foreign_id = $objIntCategory->id;
                 switch (count($arrSelected)) {
                     case 4:
                         $objCI->extra = $arrSelected[2] . "," . $arrSelected[3];
                         break;
                     case 3:
                         $objCI->extra = $arrSelected[2];
                         break;
                     case 2:
                         $objCI->extra = null;
                         break;
                 }
                 if (!$objCI->save()) {
                     echo json_encode(_xls_convert_errors($objCI->getErrors()));
                 } else {
                     echo json_encode("success|" . $objIntCategory->name0);
                 }
             } else {
                 echo json_encode(ucfirst($service) . " category not found");
             }
         } else {
             echo json_encode("Web Store category not found");
         }
     } else {
         echo json_encode("Array error");
     }
 }
Пример #2
0
 /**
  * 9-13 load amazon, Convert our web keywords into new tags table
  */
 protected function actionConvertGoogle()
 {
     $ct = 0;
     //Load google categories
     _dbx('SET FOREIGN_KEY_CHECKS=0');
     if ($this->online == 9) {
         Yii::app()->db->createCommand()->truncateTable(CategoryGoogle::model()->tableName());
     }
     $file = fopen(YiiBase::getPathOfAlias('ext.wsgoogle.assets') . "/googlecategories.txt", "r");
     if ($file) {
         while (!feof($file)) {
             $strLine = fgets($file);
             $ct++;
             if ($ct >= 1 && $ct <= 1000 && $this->online == 9 || $ct >= 1001 && $ct <= 2000 && $this->online == 10 || $ct >= 2001 && $ct <= 3000 && $this->online == 11 || $ct >= 3001 && $ct <= 4000 && $this->online == 12 || $ct >= 4001 && $ct <= 5000 && $this->online == 13) {
                 $objGC = new CategoryGoogle();
                 $objGC->name0 = trim($strLine);
                 $arrItems = array_filter(explode(" > ", $strLine));
                 if (isset($arrItems[0])) {
                     $objGC->name1 = trim($arrItems[0]);
                 }
                 if (isset($arrItems[1])) {
                     $objGC->name2 = trim($arrItems[1]);
                 }
                 if (isset($arrItems[2])) {
                     $objGC->name3 = trim($arrItems[2]);
                 }
                 if (isset($arrItems[3])) {
                     $objGC->name4 = trim($arrItems[3]);
                 }
                 if (isset($arrItems[4])) {
                     $objGC->name5 = trim($arrItems[4]);
                 }
                 if (isset($arrItems[5])) {
                     $objGC->name6 = trim($arrItems[5]);
                 }
                 if (isset($arrItems[6])) {
                     $objGC->name7 = trim($arrItems[6]);
                 }
                 if (isset($arrItems[7])) {
                     $objGC->name8 = trim($arrItems[7]);
                 }
                 if (isset($arrItems[8])) {
                     $objGC->name9 = trim($arrItems[8]);
                 }
                 $objGC->save();
             }
         }
     }
     fclose($file);
     if ($this->online == 13) {
         for ($x = 1; $x <= 9; $x++) {
             _dbx("update xlsws_category_google set `name" . $x . "`=null where `name" . $x . "`=''");
         }
         CategoryGoogle::model()->deleteAllByAttributes(array('name1' => null));
         //Import old google categories to new
         try {
             $dbC = Yii::app()->db->createCommand();
             $dbC->setFetchMode(PDO::FETCH_OBJ);
             //fetch each row as Object
             $dbC->select()->from('xlsws_category')->where('google_id IS NOT NULL')->order('id');
             foreach ($dbC->queryAll() as $row) {
                 _dbx("delete from xlsws_category_integration where module='google' AND foreign_id=" . $row->google_id . " and category_id=" . $row->id);
                 $obj = new CategoryIntegration();
                 $obj->category_id = $row->id;
                 $obj->module = "google";
                 $obj->foreign_id = $row->google_id;
                 $obj->extra = $row->google_extra;
                 $obj->save();
             }
             _dbx("alter table xlsws_category drop google_id");
             _dbx("alter table xlsws_category drop google_extra");
         } catch (Exception $e) {
         }
     }
     _dbx('SET FOREIGN_KEY_CHECKS=1');
     return array('result' => "success", 'makeline' => $this->online + 1, 'tag' => 'Installing Google categories (group ' . ($this->online - 7) . " of 6)", 'total' => 50);
 }
Пример #3
0
 public function getIntegration()
 {
     $objCategoryInte = CategoryIntegration::model()->findByAttributes(array('category_id' => $this->id, 'module' => 'amazon'));
     if ($objCategoryInte instanceof CategoryIntegration) {
         $this->integrated['amazon']['original'] = CategoryAmazon::model()->findByPk($objCategoryInte->foreign_id);
         $this->integrated['amazon']['int'] = $objCategoryInte;
     }
     $objCategoryInte = CategoryIntegration::model()->findByAttributes(array('category_id' => $this->id, 'module' => 'google'));
     if ($objCategoryInte instanceof CategoryIntegration) {
         $this->integrated['google']['original'] = CategoryGoogle::model()->findByPk($objCategoryInte->foreign_id);
         $this->integrated['google']['int'] = $objCategoryInte;
     }
     return $this;
 }
Пример #4
0
function _xls_get_googlecategory($intProductRowid)
{
    $objGoogle = Yii::app()->db->createCommand("SELECT d.name0, extra\n\t\tFROM " . ProductCategoryAssn::model()->tableName() . " AS a\n\t\tLEFT JOIN " . Category::model()->tableName() . " AS b ON a.category_id=b.id\n\t\tLEFT JOIN " . CategoryIntegration::model()->tableName() . " AS c ON a.category_id=c.category_id\n\t\tLEFT JOIN " . CategoryGoogle::model()->tableName() . " as d ON c.foreign_id=d.id\n\t\tWHERE c.module='google' AND a.product_id=" . $intProductRowid)->queryRow();
    $strLine = $objGoogle['name0'];
    $strLine = str_replace("&", "&amp;", $strLine);
    $strLine = str_replace(">", "&gt;", $strLine);
    $arrGoogle = array();
    $arrGoogle['Category'] = trim($strLine);
    if (!empty($objGoogle['extra'])) {
        $arrX = explode(",", $objGoogle['extra']);
        $arrGoogle['Gender'] = $arrX[0];
        $arrGoogle['Age'] = $arrX[1];
    }
    return $arrGoogle;
}