PHP Classes

File: website_assign.php

Recommend this page to a friend!
  Classes of Victor Andeloci   Useful Magento Scripts   website_assign.php   Download  
File: website_assign.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Useful Magento Scripts
Run product operations in Magento e-commerce sites
Author: By
Last change:
Date: 9 days ago
Size: 1,019 bytes
 

Contents

Class file image Download
<?php
   
include_once './app/Mage.php';
   
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

   
$updates_file = "./var/export/website_assign.csv";
   
$websites = array(1, 2);
   
   
$sku_entry = array();
   
$updates_handle = fopen($updates_file, 'r');
    if(
$updates_handle) {
        while(
$sku_entry = fgetcsv($updates_handle, 1000, ",")) {
           
$sku = $sku_entry[0];
            echo
"<br>Updating website of " . $sku . " - ";
            try {
               
$get_item = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
                if (
$get_item) {
                   
$get_item->setWebsiteIds($websites);
                   
$get_item->save();
                    echo
"successful";
                } else {
                    echo
"item not found";
                }
            } catch (
Exception $e) {
                echo
"Cannot retrieve products from Magento: ".$e->getMessage()."<br>";
                return;
            }
        }
    }
   
fclose($updates_handle);