您好,的
的我在magento前端产品上传的循环中遇到了存储值的问题。所有商店的价值保持不变。无法弄清楚它是怎么做的被收回。请帮忙。
由于的
$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 :(得分: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;
}