Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once('C:/xampp/htdocs/magento/app/Mage.php');
- Mage::app();
- $rootMagento = mage::getBaseDir();
- $files = scandir($rootMagento);
- $count = sizeof($files);
- for ($i =0; $i< $count; $i++) {
- if ($files[$i]=='productData.txt'){
- $fileAperto = fopen($files[$i], "r");
- $buffer = fread($fileAperto,filesize("productData.txt"));
- list($sku, $name, $description, $shortDescription, $price) = split("[n]", $buffer);
- if ($sku == '' || $name == '' || $description == ''
- || $shortDescription == '' || $price == '') {
- mage::log('esportazione non corretta: manca uno dei dati');
- }
- fclose($fileAperto);
- }
- }
- //// prodotto ////
- $product_model = mage::getModel('catalog/product');
- $productId = $product_model->getIdBySku($sku);
- if (!$productId){
- //inserimento
- $productData = array ('sku' => $sku,
- 'name' => $name,
- 'description' => $description,
- 'short_description' => $shortDescription,
- 'status' => 0,
- 'visibility' => 0
- );
- $product_model->setData($productData);
- try{
- $productId = $product_model->save()->getId();
- $product = $product_model->load($productId);
- $product->setQty($qty);
- $product->setIsInStock(1); //->isInStock(1)
- $product->save();
- }catch(Exception $e){
- mage::log($e->getMessage());
- }
- }else{
- //aggiornamento
- $product = $product_model->load($productId);
- // $productData... ... ..
- $product->setData($productData); // + codice x stock
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement