magento how to change cart account in checkout page - magento

in product detail page, the product price is 50 dollar, I use JavaScript change the price to 80 dollar, but when add to cart, it is still 50 dollar in checkout page. how to let it still 80 dollar in checkout page?

You need use "sales_quote_add_item" magento event to update the product price in cart session.
You have to make a custom module for that purpose.
Create a file in app/etc/modules/Company_All.xml
<?xml version="1.0"?> <config> <modules>
<Company_Product>
<codePool>local</codePool>
<active>true</active>
</Company_Product> </modules> </config>
Create configuration file for our module file in app/code/local/Company/Product/etc/config.xml
<?xml version="1.0"?> <config> <global>
<models>
<product>
<class>Company_Product_Model</class>
</product>
</models>
<events>
<sales_quote_add_item><!--Event to override price after adding product to cart-->
<observers>
<company_product_price_observer><!--Any unique identifier name -->
<type>singleton</type>
<class>Company_Product_Model_Price_Observer</class><!--Our observer class name-->
<method>update_book_price</method><!--Method to be called from our observer class-->
</company_product_price_observer>
</observers>
</sales_quote_add_item>
</events> </global> </config>
Create our observer file in app/code/local/Company/Product/Model/Price/Observer.php
class Company_Product_Model_Price_Observer{
public function update_book_price(Varien_Event_Observer $observer) {
$quote_item = $observer->getQuoteItem();
//if(){ //your logic goes here
$customprice = 50;
//}
$quote_item->setOriginalCustomPrice($customprice);
$quote_item->save();
return $this;
}
}

Related

Magento 1.9 disable plugin for specific ip

I've got a Magento store (1.9) with a very simple plugin. It changes the customer group when someone places an order in a website. But we also work with a POS.
In the POS the plugin is also trying to change the customer group but it gives an error.
So what I want to do is disable the plugin for our local IP (or User).
The code is the following or check Github:
observer.php
<?php
class RvdH_GroupChange_Model_Observer
{
public function changeGroup(Varien_Event_Observer $observer)
{
$order = $observer->getEvent()->getOrder();
$customer = Mage::getModel('customer/customer')->load($order->getCustomerId());
/*$event = $observer->getEvent(); //Fetches the current event"
$customer = $event->getCustomer();
$dbcustomer = Mage::getModel('customer/customer')->load($customer[entity_id]);*/
// ensure it's not guest checkout
if ($customer->getId()) {
$customer->setGroupId(5);
$customer->save();
}
}
}
config.xml
<?xml version="1.0"?>
<config>
<modules>
<RvdH_GroupChange>
<version>0.1.0</version>
</RvdH_GroupChange>
</modules>
<global>
<models>
<RvdH_GroupChange>
<class>RvdH_GroupChange_Model</class>
<resourceModel>module_mysql4</resourceModel>
</RvdH_GroupChange>
</models>
<events>
<sales_order_place_after>
<observers>
<RvdH_GroupChange>
<class>RvdH_GroupChange_Model_Observer</class>
<method>changeGroup</method>
</RvdH_GroupChange>
</observers>
</sales_order_place_after>
</events>
</global>
</config>
Solved.
I just had to change the <global> tag to <frontend> in the config.xml.
Now it only works in frontend and not global.

Set Payment Method "Cash On Delivery" on Particular State Only

I want to set "Cash On Delivery" for the site owner's State only
I know how to set For "Specified Country"
I am using Magento 1.8
How can I achieve this ?
LuFFy,you doing this using magento event observer:
Create an extension and here the step:
create config.xml under :app/code/community/Devamitbera/Statewisecod/etc/config.xml
<?xml version="1.0" encoding="utf-8"?>
<!--
#Author Amit Bera
#Email dev.amitbera#gmail.com
# Website: www.amitbera.com
*/-->
<config>
<modules>
<Devamitbera_Statewisecod>
<version>1.0.0</version>
</Devamitbera_Statewisecod>
</modules>
<global>
<models>
<statewisecod>
<class>Devamitbera_Statewisecod_Model</class>
</statewisecod>
</models>
</global>
<frontend> <!-- run observer event for frontend -->
<events>
<payment_method_is_active>
<observers>
<enable_cod_for_some_state>
<class>statewisecod/observer</class>
<method>EnableCod</method>
</enable_cod_for_some_state>
</observers>
</payment_method_is_active>
</events>
</frontend>
</config>
Create observer file
under Observer.php under app/code/community/Devamitbera/Statewisecod/Model
Code of this file:
<?php
class Devamitbera_Statewisecod_Model_Observer
{
public function EnableCod($observer){
$result=$observer->getEvent()->getResult();
$MethodInstance=$observer->getEvent()->getMethodInstance();
$quote=$observer->getEvent()->getQuote();
if($quote && $quote->getId()):
/* If Payment method is cashondelivery then conitnue */
if($MethodInstance->getCode()=='cashondelivery'){
#Mage::log('Payment is Cod',null,'Cod.log',true);
$ShippingAddress=$quote->getShippingAddress();
/* region_id is working when country have
* drop state/regions.
*/
/* Here i have put USA coutry new work & Washinton redion */
#Mage::log('redion'.$ShippingAddress->getRegionId(),null,'redion.log',true);
$CodEnableRegionIds=array(62,43);
if(in_array($ShippingAddress->getRegionId(),$CodEnableRegionIds)):
$result->isAvailable=true;
elseif(is_null($ShippingAddress->getRegionId()) && !is_null($ShippingAddress->getRegion())):
/* This section working when State/region is not dropdown
and state is dropdown
*/
$textListRegionName=array('West bengal','Delhi');
if(in_array($ShippingAddress->getRegion(),$textListRegionName)){
$result->isAvailable=true;
}else{
$result->isAvailable=false;
}
else:
$result->isAvailable=false;
endif;
return $result->isAvailable;
}
endif;
}
}
create module file Devamitbera_Statewisecod.xml under app/etc/modules
<?xml version="1.0" encoding="utf-8"?>
<!--
#Author Amit Bera
#Email dev.amitbera#gmail.com
# Website: www.amitbera.com
-->
<config>
<modules>
<Devamitbera_Statewisecod>
<codePool>community</codePool>
<active>true</active>
<depends><Mage_Payment/></depends>
</Devamitbera_Statewisecod>
</modules>
</config>
Here cashondelivery is payment method code of cash on delivery.... which is saved in database.
- Edited:
region_id is working when country have drop state/regions list.
if(in_array($ShippingAddress->getRegionId(),$CodEnableRegionIds)):
$result->isAvailable=true;
If State/region is not dropdown then Below logic is work
elseif(is_null($ShippingAddress->getRegionId()) && !is_null($ShippingAddress->getRegion())):
$textListRegionName=array('West bengal','Delhi');
if(in_array($ShippingAddress->getRegion(),$textListRegionName)){
$result->isAvailable=true;
}else{
$result->isAvailable=false;
}

magento: save categories with custom attribute to custom database table

I added custom attribute to a Category "custom_attribute". If selected I need to save this category name and url to new table in a database that I created "store_custom_categories".
This table has columns: id, name, url
How I do that?
Iva,You can used the magento Event function for that case.....
I am creating an extension that case....
app/code/local/Amit/Autoupdatecat/etc/ config.xml
<?xml version="1.0" ?>
<config>
<modules>
<Amit_Autoupdatecat>
<version>1.0.0</version>
</Amit_Autoupdatecat>
</modules>
<global>
<models>
<autoupdatecat>
<class>Amit_Autoupdatecat_Model</class>
</autoupdatecat>
</models>
</global>
<global>
<events>
<catalog_category_save_commit_after>
<observers>
<autoupdatecatgories>
<type>singleton</type>
<class>autoupdatecat/observer</class>
<method>saveCategorytabs</method>
</autoupdatecatgories>
</observers>
</catalog_category_save_commit_after>
</events>
</global>
</config>
app/code/local/Amit/Autoupdatecat/Model/ Observer.php
<?php
class Amit_Autoupdatecat_Model_Observer
{
public function saveCategorytabs($observer)
{
/*get category value */
$data= $observer->getEvent()->getData();
$name=$data['name'];
/*more fields and write code in below for custom table*/
}
}

Change Magento default status for duplicated products

I have a Magento store installed, and when a product is duplicated in the backend, Magento sets its status to Disabled by default. I don't want that to happen, the duplicated product should have its status copied from the original product as well.
In this post a partial solution was given. I see where I can find the config.xml and make the necessarry changes. However, where do I put such an observer class? Which file should I use/create and would that require any changes to the config.xml input?
Or does somebody have an overall solution for this issue? Thanks in advance!
Try this:
Create: app/code/local/MagePal/EnableDuplicateProductStatus/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<MagePal_EnableDuplicateProductStatus>
<version>1.0.1</version>
</MagePal_EnableDuplicateProductStatus>
</modules>
<global>
<models>
<enableduplicateproductstatus>
<class>MagePal_EnableDuplicateProductStatus_Model</class>
</enableduplicateproductstatus>
</models>
<events>
<catalog_model_product_duplicate>
<observers>
<enableduplicateproductstatus>
<type>singleton</type>
<class>enableduplicateproductstatus/observer</class>
<method>productDuplicate</method>
</enableduplicateproductstatus>
</observers>
</catalog_model_product_duplicate>
</events>
</global>
</config>
Create: app/code/local/MagePal/EnableDuplicateProductStatus/Model/Observer.php
class MagePal_EnableDuplicateProductStatus_Model_Observer
{
/**
* Prepare product for duplicate action.
*
* #param Varien_Event_Observer $observer
* #return object
*/
public function productDuplicate(Varien_Event_Observer $observer)
{
$newProduct = $observer->getEvent()->getNewProduct();
$newProduct->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
return $this;
}
}
Create: app/etc/modules/MagePal_EnableDuplicateProductStatus.xml
<?xml version="1.0"?>
<config>
<modules>
<MagePal_EnableDuplicateProductStatus>
<active>true</active>
<codePool>local</codePool>
</MagePal_EnableDuplicateProductStatus>
</modules>
</config>
Then clear cache and try duplicating a product.
read more # :
http://magento4u.wordpress.com/2009/06/08/create-new-module-helloworld-in-magento/
http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method
make a new product active by default in magento
I found error on this code and find out the solution below:
On app/code/local/MagePal/EnableDuplicateProductStatus/etc/config.xml change
<method> duplicateProduct </method>
TO
<method>productDuplicate</method>

Observer for Magent product after save

I am trying to add Observer to the Product status update event on backend. But it does not triggering the event.
<?xml version="1.0"?>
<config>
<modules>
<Mage4u_Customredirect>
<version>0.1.0</version>
</Mage4u_Customredirect>
</modules>
<global>
<events>
<catalog_product_status_update>
<observers>
<Mage4u_Customredirect_Catalog_product>
<type>singleton</type>
<class>mage4u_customredirect/observer</class> <method>on_catalog_product_status_update</method> </Mage4u_Customredirect_Catalog_product>
</observers>
</catalog_product_status_update>
</events>
</global>
</config>
And the observer function is to receive the status of the product that was updated and based on that i need to update it in another server.
<?php
class Mage4u_Customredirect_Model_Observer
{
public function on_catalog_product_status_update(Varien_Event_Observer $observer)
{
Mage::log("test " ,null,"test");
var_dump($observer);die();
}
}
?>
But it does not triggering this event. Please can someone tel me why its not working.
You should use the same notation here for class name as you use in Mage::getModel() factory method, e.g.: <class>mage4u_customredirect/observer</class>. Do not forget delete cache after this change to make it work.

Resources