Import product to change status with SKU.

<?php
error_reporting(1);
require_once ‘app/Mage.php’;
umask(0);
Mage::init();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$update_connection = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’);
if(isset($_POST[‘submit’]))
{
$time = rand(0000,9999);
if($_FILES[‘file’][‘type’] == ‘application/csv’)
{
if(isset($_FILES[‘file’]))
{
move_uploaded_file($_FILES[“file”][“tmp_name”],’category_products/’.$time.$_FILES[“file”][“name”]);
}

define(‘MAGENTO’, realpath(dirname(__FILE__).”/..”));

$fileName = MAGENTO .’/store/category_products/’.$time.$_FILES[“file”][“name”];
$file = fopen($fileName,”r”);

while(! feof($file))
{
$status = ”;
$csv = fgetcsv($file);
//$csv1 = explode(“\t”,$csv[0]);
$sku = $csv[0];
$statusCode = $csv[1];

if($statusCode == “Enable” || $statusCode == “enable”)
$status = 1;
else if($statusCode == “Disabled” || $statusCode == “disabled”)
$status = 2;
else if($statusCode == “Ready” || $statusCode == “ready”)
$status = 3;
else if($statusCode == “Retired” || $statusCode == “retired”)
$status = 4;
else if($statusCode == “Copy” || $statusCode == “copy”)
$status = 5;
else if($statusCode == “Received” || $statusCode == “received”)
$status = 6;
else if($statusCode == “Shot” || $statusCode == “shot”)
$status = 7;
else if($statusCode == “Reshoot” || $statusCode == “reshoot”)
$status = 8;
else if($statusCode == “Paid” || $statusCode == “paid”)
$status = 9;
else if($statusCode == “Editorial” || $statusCode == “editorial”)
$status = 10;

if($status){

$productid = Mage::getModel(‘catalog/product’)->getIdBySku(trim($sku));
$product = Mage::getModel(‘catalog/product’)->load($productid);

if($productid != ”)
{
if($status)
{
$product->setStatus($status);
}
$product->save();
}
}
$status = ”;
}

fclose($file);
echo “CSV Imported Successfully.”;
exit;
}
else
{
die(“Sorry, This file type not allowed.”);
}
}
?>
<html>
<body>
<form action=”change_status.php” method=”post” id=”import-form” name=”import-form” enctype=”multipart/form-data”>
<fieldset id=”my-fieldset”>
<table cellspacing=”0″ class=”form-list”>
<tr>
<td class=”label”>
Import file path
</td>
</tr>
<tr>
<td class=”input-ele”>
<input type=”file” class=”input-text required-entry” name=”file” id=”file” value=”” />
</td>
<td class=”button”>
<button type=”submit” class=”button” name=”submit”>Submit</button>
</td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>

How to Override Magento Core Javascript Functionality

How to Override Magento Core Javascript Functionality

In case you’ve ever had to modify core Magento functionality in the realm of the javascripts, this may come in handy. Today, I needed to look into modifying some validation methods that are located in

js/prototype/validation.js

So what you’ll want to do, at a high level, is:
Figure out how many different places in Mage you’ll need to insert your custom javascript
Insert your javascript via layout xml of some sort
Extend the core javascript objects with your customizations
Profit
Where do I need to insert my javascriptation?
design/frontend/deafult/default/layout/local.xml

In local.xml
<default>
<action method=”addItem”>
<type>skin_js</type>
<name>js/prototype/validation.js</name>
</action>
</default>
________________________________________________________________________
In validation.js
Validation.addAllThese([
[‘validate-po’, ‘We don’t ship to PO boxes, suckafoo.’, function(v) {
var no_po = v.toLowerCase();
if((no_po.indexOf(‘po box’)) >= 0) {
return false;
}else {
return true;
}
}]
]);
OR
Validation.addAllThese([
[‘validate-western-data’, ‘Some text are invalid in this field.’, function (v) {
var regex = /[\u3000-\u303F]|[\u3040-\u309F]|[\u30A0-\u30FF]|[\uFF00-\uFFEF]|[\u4E00-\u9FAF]|[\u2605-\u2606]|[\u2190-\u2195]|\u203B/g;
if(regex.test(v)) {
return false;
}
else {
return true;
}
}],
]);

XML condition in magento

<cms_index_index>
<reference name=”head”>
<action method=”addItem” ifconfig=”categorysalesbanner/enablecategorybanner/categorybanner_enable” ifvalue=”1″>
<type>skin_css</type>
<name>css/cat-sale-banner.css</name>
<params />
</action>
<action method=”addItem” ifconfig=”categorysalesbanner/categorytimer_enable/timer_enable” >
<type>js</type>
<name>banner/CategoryBanner/category-timer.js</name>
</action>
</reference>

<reference name=”root”>
<block type=”categorybanner/salebanner” name=”category.salebanner” alias=”category.salebanner” template=”categorybanner/salebanner.phtml”/>
</reference>
</cms_index_index>