Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. <?php
  2.  
  3. include_once('C:/xampp/htdocs/magento/app/Mage.php');
  4.  
  5. Mage::app();
  6. $rootMagento = mage::getBaseDir();
  7. $files = scandir($rootMagento);
  8. $count = sizeof($files);
  9. for ($i =0; $i< $count; $i++) {
  10. if ($files[$i]=='productData.txt'){
  11. $fileAperto = fopen($files[$i], "r");
  12. $buffer = fread($fileAperto,filesize("productData.txt"));
  13. list($sku, $name, $description, $shortDescription, $price) = split("[n]", $buffer);
  14. if ($sku == '' || $name == '' || $description == ''
  15. || $shortDescription == '' || $price == '') {
  16. mage::log('esportazione non corretta: manca uno dei dati');
  17. }
  18. fclose($fileAperto);
  19. }
  20. }
  21.  
  22. //// prodotto ////
  23.  
  24. $product_model = mage::getModel('catalog/product');
  25.  
  26. $productId = $product_model->getIdBySku($sku);
  27. if (!$productId){
  28. //inserimento
  29. $productData = array ('sku' => $sku,
  30. 'name' => $name,
  31. 'description' => $description,
  32. 'short_description' => $shortDescription,
  33. 'status' => 0,
  34. 'visibility' => 0
  35. );
  36.  
  37. $product_model->setData($productData);
  38. try{
  39. $productId = $product_model->save()->getId();
  40. $product = $product_model->load($productId);
  41. $product->setQty($qty);
  42. $product->setIsInStock(1); //->isInStock(1)
  43. $product->save();
  44. }catch(Exception $e){
  45. mage::log($e->getMessage());
  46. }
  47.  
  48. }else{
  49. //aggiornamento
  50. $product = $product_model->load($productId);
  51. // $productData... ... ..
  52. $product->setData($productData); // + codice x stock
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement