Question

when i submit an edited order in which the reward points awarded is negative (because the new processed order is less than the original), in the reward history one of the entries is pushed forward 12 hours ahead of the most recent entry

this isn't causing any bad effects to the total reward points as the value is being calculated correctly

there's really nothing my edit order module could be doing that does this, to edit the order the module just does the exact same thing as what Reorder does but it also creates a new session which stores the previous order's item's, their qty, the date the order was made and it's increment id, how the points are calculated is that when they are normally calculated, there's a check for this session, if it's exists it gets the Base Grand Total, puts that though $this->getReward()->getRateToPoints()->calculateToPoints() and subtracts that from the points delta

when we process the order in the checkout, it just creates a new order but the transaction id is the same as the previous order, since internet sales looks at this transaction id they'll know which order to edit, the old order will be canceled during the next run of the synchronization scripts

given all of that, at no time do i ever do anything with the reward history and it's not always the order your editing who's reward history entry i pushed up, i went and edited order 100000040 but 100000042 was pushed up

NOTE: i should also point out that the orders are not storing the same transaction id at this time as i am waiting on sample xml to compare to the request/response xml from the payment gateway, so there is no way that an order once process is tied to another order in any way


The following code is taken from Enterprise_Reward_Model_Action_OrderExtra::getPoints, it is places between $pointsDelta = $this->getReward()->getRateToPoints()->calculateToPoints((float)$monetaryAmount); and return $pointsDelta;

$editOrder = Mage::getModel('core/session')->getData('editorder');

    if(!is_null($editOrder))
    {
        $readConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
        $result = $readConnection->fetchAll("
                SELECT sfo.entity_id FROM sales_flat_order AS sfo
                    WHERE sfo.increment_id = ?
                LIMIT 1
            ",$editOrder['original_order']);
        $order = Mage::getModel('sales/order')->load($result[0]['entity_id']);
        $orderData = $order->getData();
        $previousOrderMonetaryAmount = (($orderData['base_grand_total'] - $orderData['base_shipping_amount']) - $orderData['base_tax_amount']);

        $pointsDelta = $pointsDelta - $this->getReward()->getRateToPoints()->calculateToPoints((float)$previousOrderMonetaryAmount);
    }

enter image description here

above is a snapshot of what's happening, the top shows what the reward history was before en order was edited and processed, the bottom is what happens after (for #100000049 nothing happened so i had to do it again yo get the glitch showing up)

the items in #100000044 are completely different to order #100000048, order #100000046 is missing cause when the points delta is 0 (meaning no points will be added/subtracted) it doesn't show (which is good)

all the order with a negative values are processed edited orders of those which had positive values but had some items removed during the edit reducing the cart total (in the gateway, this would then refund the customer so it makes sense that they should not be allowed to have the points that they was refunded for)

Was it helpful?

Solution

The problem is to do with Magento itself, by forcing a clean build of Magento to always have a negative amount in the order using $pointsDelta = $pointsDelta - 100000 results in the exact same problem, no idea if Magento will consider it a bug though since the only way to have discovered it is via customization of Magento but I'll report it nonetheless.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top