2014-08-28 23 views
0

您好產物,Magento的上傳前端不同存儲在一個時間

我面臨的一個問題在在Magento前端產品upload.Values一個循環存儲的值,在時間保持爲相同所有商店。不知道如何可以恢復。請幫助。

謝謝

$xlsx = new SimpleXLSX($path . DS.$fileName); 
      list($cols,) = $xlsx->dimension(); 
      foreach($xlsx->rows() as $k => $r) { 
       if ($k == 0) continue;//Ingnoring first column of excel file 
       try{ 
        //grabbing categories for en 
        $key=array_search($r[55],$cat_arr); 
        $key2=array_search($r[56],$cat_arr); 
        $key3=array_search($r[57],$cat_arr); 

        //grabbing categories for de 
        $keyde=array_search($r[52],$cat_arr); 
        $key2de=array_search($r[53],$cat_arr); 
        $key3de=array_search($r[54],$cat_arr); 

        //grabbing categories for nl 
        $keynl=array_search($r[49],$cat_arr); 
        $key2nl=array_search($r[50],$cat_arr); 
        $key3nl=array_search($r[51],$cat_arr); 

        //Set the path of image folder 
        $imgpath_total="D:\wamp\www\liquor\media\proimg/adidas.jpg";//.$r[59] 


        $newProduct = new Mage_Catalog_Model_Product(); 
        $newProduct->setAttributeSetId(4) 
        ->setTypeId('simple') 
        ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH) 
        ->setTaxClassId(2) 
        ->setCreatedAt(strtotime('now')) 
        ->setSku($r[39]) 
        ->setWeight($r[40]) 
        ->setBrand($r[5]) 
        ->setTags($r[58]) 
        ->setAlc_percentage($r[42]) 
        ->setWeight('10') 
        ->setEan($r[37]) 
        ->setStatus(1) 
        ->setPrice($r[22]) 
        ->setWebsiteIds(array(1)) 
        ->setStockData(array('is_in_stock' => 1, 'qty' => 99999)) 
        ->setSetupFee(522) 
        ->addImageToMediaGallery($imgpath_total,array('image','small_image','thumbnail'),false,false) 
        ->setsetupCost(100) 

        ########En DATA########## 
        ->setName($r[17]) 
        ->setTitle_long($r[18]) 
        ->setGoogle($r[64]) 
        ->setDescription($r[20]) 
        ->setShort_description($r[19]) 
        ->setCategoryIds(array(2,$key,$key2,$key3)) 
        ->setStoreId(1) 
        ########En DATA########## 

        ########de DATA########## 
        ->setName($r[12]) 
        ->setTitle_long($r[13]) 
        ->setGoogle($r[63]) 
        ->setDescription($r[15]) 
        ->setShort_description($r[14]) 
        ->setCategoryIds(array(2,$keyde,$key2de,$key3de)) 
        ->setStoreId(7) 
        ########de DATA########## 


        ########nl DATA########## 
        ->setName($r[7]) 
        ->setTitle_long($r[8]) 
        ->setGoogle($r[62]) 
        ->setDescription($r[10]) 
        ->setShort_description($r[9]) 
        ->setCategoryIds(array(2,$keynl,$key2nl,$key3nl)) 
        ->setStoreId(8); 
        ########nl DATA########## 

        $newProduct->save();  
        #####save your product################### 

       }catch(Exception $e){ 
        $result['status'] = 3; 
        $result['message'] = 'There is an ERROR happened! NOT ALL products are created! Error:'.$e->getMessage(); 
        echo json_encode($result); 
        return; 
       } 



    } 

代碼是在這裏

+0

如果沒有查看您的代碼,很難說出任何內容。 SO提供你的代碼來更好地分析 – 2014-08-28 10:43:50

+0

**代碼被添加** – 2014-08-28 11:09:35

回答

0

找到了解決辦法,首先,我插在默認的存儲值,則通過獲得最後插入的產品ID,我添加靜態數據對於所有其他可用的商店。

Sample code: 
    $insertId=Mage::getSingleton('core/resource')->getConnection('core_read')->fetchOne('SELECT last_insert_id()'); // last inserted product id stored here. 
    $product = Mage::getModel('catalog/product')->load($insertId); 
    $product->setStoreId(STORE_ID)->setName('new_name')->save();//storing data by this way 

    Full code: 
    foreach($xlsx->rows() as $k => $r) { 
      if ($k == 0) continue;//Ingnoring first column of excel file 
      try{ 
       //grabbing categories for en 
       $key=array_search($r[55],$cat_arr); 
       $key2=array_search($r[56],$cat_arr); 
       $key3=array_search($r[57],$cat_arr); 

       //grabbing categories for de 
       $keyde=array_search($r[52],$cat_arr); 
       $key2de=array_search($r[53],$cat_arr); 
       $key3de=array_search($r[54],$cat_arr); 

       //grabbing categories for nl 
       $keynl=array_search($r[49],$cat_arr); 
       $key2nl=array_search($r[50],$cat_arr); 
       $key3nl=array_search($r[51],$cat_arr); 

       //Set the path of image folder 
       $imgpath_total=Mage::getBaseDir()."\media\proimg/12001.jpg";//.$r[59] 


       $newProduct = new Mage_Catalog_Model_Product(); 
       $newProduct->setAttributeSetId(4) 
       ->setTypeId('simple') 
       ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH) 
       ->setTaxClassId(2) 
       ->setCreatedAt(strtotime('now')) 
       ->setSku($r[39]) 
       ->setWeight($r[40]) 
       ->setBrand($r[5]) 
       ->setTags($r[58]) 
       ->setAlc_percentage($r[42]) 
       ->setWeight('10') 
       ->setEan($r[37]) 
       ->setStatus(1) 
       ->setPrice($r[22]) 
       ->setWebsiteIds(array(1)) 
       ->setStockData(array('is_in_stock' => 1, 'qty' => 99999)) 
       ->setSetupFee(522) 
       //->addImageToMediaGallery($imgpath_total,array('image','small_image','thumbnail'),false,false) 
       ->setsetupCost(100) 
       ->setName($r[17]) 
       ->setTitle_long($r[18]) 
       ->setGoogle($r[64]) 
       ->setDescription($r[20]) 
       ->setShort_description($r[19]) 
       ->setCategoryIds(array(2,$key,$key2,$key3)); 

       $newProduct->save(); 
       $insertId= Mage::getSingleton('core/resource')->getConnection('core_read')->fetchOne('SELECT last_insert_id()');   

       $product = Mage::getModel('catalog/product')->load($insertId); 

       #################Dutch############### 
        $product->setStoreId(7) 
        ->setName($r[12]) 
        ->setTitle_long($r[13]) 
        ->setGoogle($r[63]) 
        ->setDescription($r[15]) 
        ->setShort_description($r[14]) 

        ->save(); 

       ################End Dutch############# 

       #############Netherland ################ 
        $product->setStoreId(8) 
        ->setName($r[7]) 
        ->setTitle_long($r[8]) 
        ->setGoogle($r[62]) 
        ->setDescription($r[10]) 
        ->setShort_description($r[9]) 
        ->save(); 
       #############End Netherland########## 


       #####save your product################### 

      }catch(Exception $e){ 
       $result['status'] = 3; 
       $result['message'] = 'There is an ERROR happened! NOT ALL products are created! Error:'.$e->getMessage(); 
       echo json_encode($result); 
       return; 
      } 
      exit; 
       } 
相關問題