Guest User

Untitled

a guest
Apr 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. <?php
  2. /* Hna ketn3ayto 3la magento */
  3. $mageFilename = 'app/Mage.php';
  4. require_once $mageFilename;
  5. Mage::setIsDeveloperMode(true);
  6. ini_set('display_errors', 1);
  7. umask(0);
  8. Mage::app('admin');
  9. Mage::register('isSecureArea', 1);
  10. Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
  11. set_time_limit(0);
  12. ini_set('memory_limit','1024M');
  13. /* -------------------------------- */
  14. /* Hna ken3ayto 3la csv */
  15. $csv = new Varien_File_Csv();
  16. $data = $csv->getData('potsgrilled.csv'); //csv
  17. array_shift($data); /* Hadi kethayd line lewla li fiha les attribute "Nom,sku,......." */
  18.  
  19. $message = '';
  20. $count = 1;
  21. foreach($data as $_data){
  22. Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
  23. $product = Mage::getModel('catalog/product');
  24. if(!$product->getIdBySku($_data[1].$count)){
  25. if( $_data[3] == "0%" ){
  26. $taxid = 2;
  27. $prix = $_data[2];
  28. } elseif ($_data[3] == "10%") {
  29. $taxid = 5;
  30. $prix = $_data[2] - ($_data[2] * (10/100)) ;
  31. }
  32. elseif ($_data[3] == "20%") {
  33. $taxid = 6;
  34. $prix = $_data[2] - ($_data[2] * (20/100));
  35. }
  36. else{
  37. $taxid = 2;
  38. $prix = $_data[2];
  39. }
  40. try{
  41. $product
  42. ->setStoreId(1) // Hna dir store id ghatl9ah f url diya System -> gestion de magasin -> Main Store
  43. ->setWebsiteIds(array(1)) //Hna dir Website id ghatl9ah f url diya System -> gestion de magasin -> Main Website khliha Array()
  44. ->setAttributeSetId(4) //Hna dir id diyal attrubite set ghatl9aha f url diyal Catalog -> Attribute -> 2 -> default
  45. ->setTypeId('simple') //product type
  46. ->setCreatedAt(strtotime('now')) //product creation time
  47.  
  48. ->setSku($_data[1].$count) //SKU
  49. ->setName($_data[0]) //product name
  50. ->setWeight($_data[5]) // Hna Grammage
  51. ->setColisage($_data[4]) // Hna Colisage
  52. ->setStatus(1) //product status (1 - enabled, 2 - disabled) khliha 1 y3ni active
  53. ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH) //catalog and search visibility khliha fhal haka
  54. ->setNewsFromDate('04/05/2018') //product set as new from
  55. ->setNewsToDate('12/30/2018') //product set as new to
  56. ->setPrice($prix) //Hna l prix
  57. ->setMetaTitle($_data[0]) // Hna meta title li kikon f head
  58. ->setMetaKeyword($_data[0]) // Hna meta keyword li kikon f head
  59. ->setMetaDescription($_data[0]) // Hna meta description li kikon f head
  60. ->setTaxClassId($taxid) // Classe diyal TAX diyal produit
  61. ->setDescription($_data[0]) // Hna Description diyal produit
  62. ->setShortDescription($_data[0]) // Hna Short description
  63. ->setMediaGallery (array('images'=>array (), 'values'=>array ())) //Hna Image diyal produit li htiti f media/import
  64. ->addImageToMediaGallery(Mage::getBaseDir('media') . DS . 'import' . DS . $_data[1] . '.png', array('image','thumbnail','small_image'), false, false) //Hna ghadi twli hadik l'image hiya li f thumbnail o small*/
  65. /*addImageToMediaGallery(Mage::getBaseDir('media') . DS . 'import' . DS . $_data[1] . '.png', array('image','thumbnail','small_image'), false, false)*/
  66.  
  67. ->setStockData(array(
  68. 'is_in_stock' => 1, //Hna disponibility
  69. 'qty' => 999 //Hna Quentity
  70. )
  71. )
  72.  
  73. ->setCategoryIds(array(2,21)); //Hna les id diyal les category li ghadi ikon fihom lproduit
  74. $product->save();
  75. $count++;
  76. echo "goood";
  77.  
  78. }catch(Exception $e){
  79. echo Mage::log($e->getMessage()) . " Message mabanch";
  80. }
  81. }
  82. else{
  83. echo "sorry";
  84. }
  85. }
  86. ?>
Add Comment
Please, Sign In to add comment