0

i wanna get products from shopsense.shopstyle.com using simplexml_load_file() method in that code:

class Shopsense_Shopstyle_ShopstyleController extends Mage_Adminhtml_Controller_Action{

    public function indexAction(){

        $this->loadLayout();//app/design/adminhtml

        $this->_setActiveMenu('shopsense');
        $this->_addLeft($this->getLayout()
             ->createBlock('core/text')
             ->setText('<h1>import products</h1>'));

               $block= $this->getLayout()
                ->createBlock('shopsense_shopstyle/adminhtml_adminblock')
                ->setTemplate('shopsense/adminblock.phtml');

 Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$results=simplexml_load_file("http://api.shopstyle.com/api/v2/products?pid=1761-25615319-5&offset=0&limit=1&format=xml");

foreach($results->products as $prod){
    foreach($prod as $pro){
            $product = Mage::getModel('catalog/product');
                    $product
                        ->setStoreId(1) 
                        ->setWebsiteIds(array(1)) 
                        ->setAttributeSetId(9) 
                        ->setTypeId('simple') 
                        ->setCreatedAt(strtotime('now')) 
                        ->setUpdatedAt(strtotime('now'))

                        ->setSku($pro->id)
                        ->setName($pro->name) 
                        ->setWeight(4.000)
                        ->setStatus(1)
                        ->setTaxClassId(4)
                        ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH) 
                        ->setManufacturer(28)
                        ->setColor(24)
                        ->setNewsFromDate('10/26/2014') 
                        ->setNewsToDate('12/30/2014') 
                        ->setCountryOfManufacture('EG') 
                        ->setPrice(11.22) 
                        ->setCost(22.33) 
                        ->setSpecialPrice(00.44) 
                        ->setSpecialFromDate('06/1/2014') 
                        ->setSpecialToDate('06/30/2014')
                        ->setMsrpEnabled(0) 
                        ->setMsrpDisplayActualPriceType(1)
                        ->setMsrp(99.99)                    
                        ->setMetaTitle('test meta title 2')
                        ->setMetaKeyword('test meta keyword 2')
                        ->setMetaDescription('test meta description 2')

                        ->setDescription('This is a long description')
                        ->setShortDescription('This is a short description')

                        ->setMediaGallery (array('images'=>array (), 'values'=>array ())) 
                        ->addImageToMediaGallery('media/catalog/product/1/0/10243-1.png', array('image','thumbnail','small_image'), false, false)                      
                        ->setStockData(array(
                                        'use_config_manage_stock' => 0, 
                                           'manage_stock'=>1,
                                           'min_sale_qty'=>1,
                                           'max_sale_qty'=>2, 
                                           'is_in_stock' => 1,
                                           'qty' => 10
                                       )
                        )

                        ->setCategoryIds(array(21)); //assign product to categories
                    $product->save();

       }
   }

                $this->_addContent($block);
                $this->renderLayout();

    }

but i find the new products here add products for new category page [with out the name !!!!!!!!!!!!!!!] why??

and not found that products in manage products page here manage products page

  • Try to log the value of $pro->name and see what you receive. – Marius Nov 18 '14 at 15:08
  • i did that and it return the product name put when use $product->setName() i doesn`t find the product name ?? – Mohamed Maree Nov 18 '14 at 15:17
  • Just found something else. ->setStoreId(1). That's not right. When creating a product you cannot set directly values for a store id. You have to fill in first the values for default values. So replace it with ->setStoreId(0). Maybe this is the issue. – Marius Nov 18 '14 at 15:21
  • the same problem :( – Mohamed Maree Nov 18 '14 at 15:46
0

thank you Marius that is the answer

    $product = Mage::getModel('catalog/product');
             //   if(!$product->getIdBySku('newnew')){



//   try{
        $product
           ->setStoreId(0) 
            ->setWebsiteIds(array(1)) 
            ->setAttributeSetId(4) 
            ->setTypeId('simple') 
            ->setCreatedAt(strtotime('now')) 
            ->setUpdatedAt(strtotime('now')) 

            ->setSku($pro->id) 
            ->setName($pro->name) 
            ->setWeight(4.000)
            ->setStatus(1) 
            ->setTaxClassId(4) 
            ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH) 
            ->setManufacturer(2)
           // ->setColor(24)
            ->setNewsFromDate('10/26/2014') 
            ->setNewsToDate('12/30/2014') 
            ->setCountryOfManufacture('EG') 

            ->setPrice($pro->price) 
            ->setCost($pro->price+10)
            ->setMsrpEnabled(1) 
            ->setMsrpDisplayActualPriceType(1) 

            ->setMetaTitle($pro->name)
            ->setMetaKeyword($pro->name)
            ->setMetaDescription($pro->description)

            ->setDescription($pro->description)
            ->setShortDescription($pro->description);

            $product->setStockData(array(
                               'use_config_manage_stock' => 1, 
                               'manage_stock'=>1,
                               'min_sale_qty'=>1, 
                               'max_sale_qty'=>2, 
                               'is_in_stock' => 1, 
                               'qty' => 10
                           )
            )            
            ->setCategoryIds(array(21));
            $product->save();

$this->_addContent($block);
             $this->renderLayout();
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.