Shipping costs remove in cart grand total in Magento 1.9 - cart

I have add product in cart after that I have checkout page, now in checkout page I will fill the all details also select shipping method but not proceed order.
After that I have going on cart then my grand total showing with shipping cost so I have to remove this shipping cost in my cart grand total because customer can confusion how that total will increase.
So I will only show product total with text in cart if I am select shipping method they can't be display in cart only show at checkout time.
Is this possible in Magento 1.9?

Try this Create an observer in checkout_cart_save_before
<frontend>
<events>
<checkout_cart_save_before>
<observers>
<your_module_shipping_observer>
<type>singleton</type>
<class>Your_Module/observer</class>
<method>setShipping</method>
</your_module_shipping_observer>
</observers>
</checkout_cart_save_before>
</events>
</frontend>
And in your observer try this
public function setShipping($observer) {
$event = $observer->getEvent();
$cart = $event->getCart();
$shippingaddress = $cart->getQuote()->getShippingAddress();
$shippingaddress->setShippingMethod('')->save();
return;
}

Related

Magento observer - after/before order place

In my website there is a product having qty as 500 (For Example), if a user ordered 600 qty the payment must process for available and remaining 100 qty must get paid after the stock avail. At present user can only pay for 500 qty.
Can anybody help to update the qty to 600 after placing an order programmatically? So that admin can manage invoice/shipment for first 500 qty and after user pay for the 100 again invoice/shipment.
Any other option to manage this?
Current observer code (not working):
public function myfucn($observer){
$data = $observer->getEvent()->getOrder();
$id = '40';
$qty = 600;
$_product = Mage::getModel('catalog/product')->load($id);
$cart = Mage::getModel('checkout/cart');
$cart->init();
$cart->addProduct($_product, array('qty' => $qty));
$cart->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);}
Config.xml
<modules>
<Ajt_PlaceOrder>
<version>0.0.1</version>
</Ajt_PlaceOrder>
</modules>
<global>
<models>
<placeprder>
<class>PlaceOrder_Model</class>
</placeprder>
</models>
<events>
<sales_quote_save_before>
<observers>
<ajt_placeorder_model_observer>
<class>Ajt_PlaceOrder_Model_Observer</class>
<method>mymethod</method>
</ajt_placeorder_model_observer>
</observers>
</sales_quote_save_before>
</events>
</global>
The above observer code im trying is to add product to cart. But if you have solution to update the qty of already existed item at cart before place an order please guide me.

Magento margin/profit rules to allow or prevent check out

Hi i have an attribute that calculates the margin of an product, in all attribute sets. Question is how can i set a rule to prevent customer check out if the margin(or profit) of a cart is less than required?
You can create an observer for the event controller_action_predispatch_checkout_onepage_index - this will fire when the customer starts the onepage checkout process.
This can be achieved like so in your modules config.xml:
<events>
<controller_action_predispatch_checkout_onepage_index>
<observers>
<YOUR_MODULE_checkout_onepage_index>
<type>singleton</type>
<class>YOUR_MODULE_Model_Observer</class>
<method>calculateProductMargin</method>
</YOUR_MODULE_checkout_onepage_index>
</observers>
</controller_action_predispatch_checkout_onepage_index>
</events>
If you are unaware about how to create a module then look here
So in your app/code/local/YOUR/MODULE/Model/Observer.php:
class YOUR_MODULE_Model_Observer extends Varien_Event_Observer {
public function setStore($observer) {
// Your logic here
}
}
In here you can $cart = Mage::getModel('checkout/cart')->getQuote(); and loop through the cart items, calculate your product margin and _goBack() potentially if it fails your requirements.
Enjoy! I hope this helps.

Price not updating in cart when the store is switched to another store

We have magento1.9 installed. In this site we have products with multiple options. We have added custom price for the options and it works fine. The product with the custom options and a total price can be added to the cart. The custom price is set using the code
$quote_item->setOriginalCustomPrice($new_price['price'])
My magento is multi language store with different currencies. The base price is in GBP. When we switch it to a different store the cart currency is updated but the price remains the same, it does not decrease or increase respectively with respect to the store currency.
Hi encountered the same issue on Magento ver. 1.9.3.3.
To solve I create an observer on controller_action_predispatch
<frontend>
<events>
<controller_action_predispatch>
<observers>
<updatecartonstorechange>
<type>singleton</type>
<class>megaobserver/Observer</class>
<method>updateCartOnStoreChange</method>
</updatecartonstorechange>
</observers>
</controller_action_predispatch>
</events>
</frontend>
inside the method I checked if a store change was called, and forced update the cart:
public function updateCartOnStoreChange(Varien_Event_Observer $observer)
{
$store = Mage::app()->getRequest()->getParam('___store', false);
if(!($store===false)){
$currentQuote = Mage::getSingleton('checkout/session')->getQuote();
$items = $currentQuote->getAllVisibleItems();
$cartData = Array();
foreach ($items as $key =>$value) {
$cartData[$value->getItemId()] = ['qty'=>$value->getQty()];
}
if(!empty($cartData)){
$this->_updateShoppingCart($cartData);
}
}
}
Prices in Magento are either per-website or global, not per-store (view). However, I don't think that is your problem, I believe your issue is just bad code used in templates to actually render the prices in front-end.
Could you provide the corresponding code from the templates (.phtml files) of the pages in which you see the wrong prices?
I am getting the same issue. Before adding custom price is set based on height and width and in cart it is showing correctly. But while changing the currency, the item price is not changing. I am using checkout_cart_product_add_after this event. and my code is like
public function updateProductCartPrice($observer, $new_price){
$quote_item = $observer->getQuoteItem();
$quote_item = ( $quote_item->getParentItem() ? $quote_item ->getParentItem() : $quote_item );
if($new_price):
$quote_item ->setCustomPrice($new_price);
$quote_item ->setOriginalCustomPrice($new_price);
$quote_item ->getProduct()->setIsSuperMode(true);
endif;
}

Disable 'General' group sales in Magento

I'm looking to disable sales on our Magento site for any customers in the 'General' customer group. We have a tiered customer group system setup, with different tax rules etc., but I can't figure out how to disable 'general' as a group that can purchase from the site. I don't want new customers signing up able to purchase without being assigned a group first.
Thanks.
Here is my idea: set up observer on controller_action_predispatch_checkout_onepage_index event, which will fire before checkout page is loaded. In observer we check if customer belongs to certain group and if so we redirect him to cart page and show error message.
Translated to Magento code, it would look like this:
Firs we hook on the event in our config.xml
<frontend>
<events>
<controller_action_predispatch_checkout_onepage_index>
<observers>
<your_module>
<class>your_module/observer</class>
<method>banCheckout</method>
</your_module>
</observers>
</controller_action_predispatch_checkout_onepage_index>
</events>
</frontend>
and in our observer:
public function banCheckout(Varien_Event_Observer $observer)
{
$customerSession = Mage::getSingleton('customer/session');
if (!$customerSession->isLoggedIn()) {
return $this;
}
$groupId = $customerSession->getCustomer()->getGroupId();
if ($groupId == 1) {
Mage::getSingleton('checkout/session')->addError(
Mage::helper('checkout')->__('Your error message.')
);
$action = $observer->getEvent()->getControllerAction();
$action->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
$action->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
}
return $this;
}
Keep in mind this is just an example, and a pretty simple one.

How can I set the inbuilt payment method based on store id

I want to show the Magento existing inbuilt payment method based on store Id.I have two store and want to show Cash on delivery and pay pal on one store and do not want these payment method on another store.Please help
When deciding which payment methods to show Magento will issue an event. You can register observer for that event and filter payment list by store ID. Here is how to do it.
Create new module for the observer. Register observer in your config.xml:
<confg>
...
<frontend>
...
<events>
<payment_method_is_active>
<observers>
<company_module>
<type>singleton</type>
<class>Company_Module_Model_Observer</class>
<method>frontendPaymentMethods</method>
</company_module>
</observers>
</payment_method_is_active>
</events>
</frontend>
</config>
And then create model for the observer class Model/Observer.php with frontendPaymentMethods function:
<?php
class Company_Module_Model_Observer {
public function frontendPaymentMethods($observer) {
$quote = $observer->getData('quote');
$result = $observer->getData('result');
$method = $observer->getData('method_instance');
if($method->getCode() == 'banktransfer' && Mage::app()->getStore() == 5) {
$result->isAvailable = false;
}
}
}
This will disable banktransfer payment method for store with id 5.
You can do this in Magento configuration under System > Configuration. Choose one of the stores in the dropdown list at the top left corner of the configuration page. And disable Cash on delivery and paypal payment methods. This will be a store specific configuration, that means these payment methods will be disabled only in that store and available in other.
http://www.magentocommerce.com/knowledge-base/entry/overview-how-multiple-websites-stores-work/

Resources