Php Magento一次将产品从前端上传到不同的商店

Php Magento一次将产品从前端上传到不同的商店,php,magento,Php,Magento,嗨 我在magento前端产品上载的循环中一次存储值时遇到问题。所有存储的值都保持不变。无法确定如何恢复。请帮助 谢谢 代码在这里找到了解决方案,首先我在默认存储中插入了值,然后通过获取最后插入的产品id,我为所有其他可用存储添加了rest数据 Sample code: $insertId=Mage::getSingleton('core/resource')->getConnection('core_read')->fetchOne('SELECT last_ins

我在magento前端产品上载的循环中一次存储值时遇到问题。所有存储的值都保持不变。无法确定如何恢复。请帮助

谢谢


代码在这里

找到了解决方案,首先我在默认存储中插入了值,然后通过获取最后插入的产品id,我为所有其他可用存储添加了rest数据

    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;
                }

如果不查看代码,很难说出任何内容。因此,请提供您的代码以便更好地进行分析
    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;
                }