Magento Remove an items from Quote Items, Order total not updated - magento

Trying to remove an item from the quote object, but cannot get order total updated.
For example, a customer adds product A ($2), and B ($3) to the cart, and then place the order.
After customer hits the place order button, I am trying to remove product B from the order.
Using the code below, I can successfully remove B from the order. But the total of the order is not updated.
$quote->getItemsCollection()->removeItemByKey($item->getId());
Say I have product B removed, then order should have a total of $2, but I checked from the order grid in backend, the total was $5.

//Try with the below code. not tested.
$quote->getItemsCollection()->removeItemByKey($item->getId());
$quote->save();
//I thing you need to remove items from order to reflect your changes in order.
foreach($order->getAllItems() as $item) {
$item->isDeleted(true);
}
Please note that this is not recommended to do things like this as per this link More details

Related

How to filter product collection with multiple price range on same time in magento?

I want to filter product listing page collection with multiple price range. Like i want to filter PLP page collection as mentioned below.
40-50
80-90
Above are filtered price ranges and i want plp page collection with this 2 ranges on same time.
I have try to add multiple filter in addFieldtofilter as well as addattributetofilter but it's showing always last range result. Let me know any solution for same.

How to update a field when another is modified

I have three fields
1. Price (:P7_PRIJS)
2. Quantity (:P7_HOEVEELHEID)
3. Total (:P7_TOTAAL).
I want the total to be updated (price * quantity) the moment the quantity is changed. All items are on the same region, from the same table.
I have already created a trigger to update the total, this works, but is not visible in the screen.
I have tried with a Dynamic action, but get errors when doing so.
I just want to see in the form, before saving the updated total. How can this be done?
Dynamic action is a way to do that. Actually, you need two of them (which will look exactly the same), each of them created on P7_PRIJS and P7_HOEVEELHEID items (so that total gets calculated regardless of which item value you've changed).
Dynamic action's action is Set value:
set type: PL/SQL expression
PL/SQL expression: :P7_PRIJS * :P7_HOEVEELHEID
items to submit: P7_PRIJS,P7_HOEVEELHEID
affected elements: item, P7_TOTAAL

Change Order Date when changing an order

I'm hoping someone will be able to solve an issue that takes us a lot of manual labour, the solution seems simple :-)
Summary:
Is it possible to change the code that, when you Edit an order (invoiced or not yet invoiced) that is does not take the Order Date and Time of when you edited the order, but it uses the Order Date and Time of the original order?
Example:
Order 1000 was placed on 15/05/2015 at 12:00
Order 1000 was edited on 25/05/2015 at 14:00, the new order ID is 1000-1
We will credit or cancel order 1000, depending on the invoice state
Standard Magento will give order 1000-1 the Order date of 25/05/2015 14:00
But we would like order 1000-1 to receive the order date of 15/05/2015 12:00, the same as original order 1000.
Explanation:
We use a Magento Extension (Embedded ERP) which uses product reservations. If a customer orders a product, it does not remove the item from stock, but reserves stock. If the item is on backorder, the customer is placed in queue.
The system uses a first in, first out system. It uses the order date to check which customer is higher in queue than the other customers.
Because we use backorders, customer sometimes like to add or remove items to order, because they have to wait for items anyway. But when changing an order to add or remove items, the new order gets a new Order Date and Time. We want the customer to have the same product reservations as their original order. So now we manually change the product reservation of each item so it's the same as their original order.
I expect we can have the correct product reservations on the new order done automatically when the new order has the same order date and time of the original order.
Copy the file app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php into app/code/local/Mage/Adminhtml/Model/Sales/Order/. Keep the folder structure unchanged!
Find the option createOrder() and change this
if ($this->getSession()->getOrder()->getId()) {
$oldOrder = $this->getSession()->getOrder();
$this->getSession()->getOrder()->setRelationChildId($order->getId());
$this->getSession()->getOrder()->setRelationChildRealId($order->getIncrementId());
$this->getSession()->getOrder()->cancel()
->save();
$order->save();
}
with this:
if ($this->getSession()->getOrder()->getId()) {
$oldOrder = $this->getSession()->getOrder();
$this->getSession()->getOrder()->setRelationChildId($order->getId());
$this->getSession()->getOrder()->setRelationChildRealId($order->getIncrementId());
$this->getSession()->getOrder()->cancel()
->save();
$order->setCreatedAt($oldOrder->getCreatedAt());
$order->save();
}

Why does magento generates random order id's

One of my magento site shows zig-zag order numbers from admin panel sales->orders. I guess, it should be auto incremented. There is possiblity to skip few numbers due to uncompleted orders. But i get unusual number for an order. Last order id was 100001922 and i get order id for latest order 100001300. can anybody help me as i need to figure out the reason.

How to set minimum purchase order amount

When customer places an order, how to set minimum order amount?
i.e) Total amount of order not below than $500.
I know how to get total order amount. But I don't know where to place that code and where to check
sOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$oOrder = Mage::getModel('sales/order')->load($sOrderId);
if($oOrder >=$500)
{
.....
}
If customer has purchased total less than $500, they won't allow to checkout at the cart.
Login as admin, then go to System->configuration, then select ‘Sales‘ from left Nav and click on ‘Minimum order amount‘.
Then select Yes from Enable dropdown, enter Minimum order amount, enter message and also enter error message that will be shown whenever the order will be less than specified amount at the shopping cart.
Thanks.
You need to change the scope of the minimum amount setting. For that you need a new module with a system.xml file that contains the same path to the minimum amount field and just changes the <show_in_store> value. Read more about this here.

Resources