You can achieve this using an observer on the product before save or after save. I recommend doing it on the before save event.
Create a module, or you can use one that you already have. Let's call it Easylife_Leftbanner
. You will need these files:
app/etc/modules/Easylife_Leftbanner.xml
- the declaration file
<?xml version="1.0"?>
<config>
<modules>
<Easylife_Leftbanner>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Catalog />
</depends>
</Easylife_Leftbanner>
</modules>
</config>
app/code/local/Easylife/Leftbanner/etc/config.xml
- the configuration file
<?xml version="1.0"?>
<config>
<modules>
<Easylife_Leftbanner>
<version>0.0.1</version>
</Easylife_Leftbanner>
</modules>
<global>
<models>
<leftbanner><!-- declare the models alias -->
<class>Easylife_Leftbanner_Model</class>
</leftbanner>
</models>
<events>
<catalog_product_save_before><!-- observe the product before save event -->
<observers>
<leftbanner>
<class>leftbanner/observer</class>
<method>changeLeftbanner</method>
</leftbanner>
</observers>
</catalog_product_save_before>
</events>
</global>
</config>
app/code/local/Easylfe/Leftbanner/Model/Observer.php
- the observer
<?php
class Easylife_Leftbanner_Model_Observer{
public function changeLeftbanner($observer){
$attribute = 'leftbanner';
$product = $observer->getEvent()->getProduct();
//if the product attribute value has changed
if ($product->getData($attribute) != $product->getOrigData($attribute)){
//if the value is set to 1
if ($product->getData($attribute) == 1){
//get all the products that already have the value 1 for the attribute.
//normally there should be only 1, but it's safer this way
$collection = Mage::getModel('catalog/product')->setStoreId($product->getStoreId())->getCollection()
->addAttributeToFilter($attribute, 1);
$ids = $collection->getAllIds();
//if there are such products
if (count($ids)){
//change the value of the attribute for them
Mage::getModel('catalog/product_action')->updateAttributes($ids, array($attribute=>'0'), $product->getStoreId());
}
}
}
return $this;
}
}
Clear the cache and give it a go.