3

I need to make a rule for only one payment method, this rule will changes the price of the products. actually i have a method where i can do that, but i don't know how to save the new price.

   class Mipc_Payment_Block_Info_Monthlypayment extends Mage_Payment_Block_Info
{

protected function _prepareSpecificInformation($transport = null)
{
    if (null !== $this->_paymentSpecificInformation) {
        return $this->_paymentSpecificInformation;
    }
    $info = $this->getInfo();
    $transport = new Varien_Object();
    $transport = parent::_prepareSpecificInformation($transport);

        $transport->addData(array(
            $this->__('Plan de pago') => $info->getPaymentPlanTitle(),
            $this->__('Incremento por plan de pago') => round($info->getPaymentPlanIncrement(), 2).'%',
        ));

        $cart = Mage::getModel('checkout/session')->getQuote();
        foreach ($cart->getAllItems() as $item) {
            $this->log($item->getProduct()->getName());
            $oldPrice = $item->getProduct()->getPrice();
            $newPrice = $oldPrice * ((round($info->getPaymentPlanIncrement(),2) / 100) + 1); //display something like 1.1326
            $item->getProduct()->setPrice$newPrice();
            $item->save();
            $this->log($item->getProduct()->getPrice()); // this shows the new price, but on the step number 5 of OnePage Checkout is showig the oldPrice.
            $this->log("==  == ==");
       }

        return $transport;
    }
  • Do you want to change the product's price permantly or only for that order ? – Mrunmay Deswandikar Dec 28 '16 at 4:22
  • Only for the orders that had selected an specific payment method – Waskalle Dec 28 '16 at 22:54
  • i want to change the product price if "x" payment method is selected. – Waskalle Dec 28 '16 at 23:07
  • Ok referer my answer. – Mrunmay Deswandikar Dec 29 '16 at 3:52
0

Follow above steps,

  1. Add a order placed before event.

  2. In that event that is observer.php file add following code

    class Custom_Module_Modulename_Model_Observer

    { public function _construct() { }

    public function getNewPrice()
    {
    
        $login  = Mage::getSingleton('customer/session')->isLoggedIn();
        $roleId = Mage::getSingleton('customer/session')->getCustomerGroupId();
        $userrole   = Mage::getSingleton('customer/group')->load($roleId)->getData('customer_group_code');
        $userrole   = strtolower($userrole);
        $quote = Mage::getSingleton('checkout/session')->getQuote();
        $cartItems = $quote->getAllVisibleItems();
        foreach ($cartItems as $item) {
            $productId = $item->getProductId();
            $product = Mage::getModel('catalog/product')->load($productId);
        }
        $batch_qty = $product->getBatchQty();
        $actualPrice = $product->getPrice();
        $specialPrice = $product->getFinalPrice();
        if (isset($batch_qty) && $userrole=="retailer") {
            if (isset($specialPrice)) {
                $newprice = $specialPrice*$batch_qty;
            } else {
    
                $newprice = $actualPrice*$batch_qty;
            }
    
        } else {
            $newprice= $actualPrice;
        }
    
        return $newprice;
    }
    
    public function updatePrice($observer)
    {
        $event = $observer->getEvent();
        $product = $event->getProduct();
        $quote_item = $event->getQuoteItem();
        $new_price = $this->getNewPrice();
        $quote_item->setOriginalCustomPrice($new_price);
        //$clasquote_item->save();
        $quote_item->getQuote()->save();
        //Mage::getSingleton('checkout/cart')->save();
    }
    

    }

| improve this answer | |
  • Try with that event that you tell me but it is not possible to execute I have this "sales_quote_payment_import_data_before", which is executed after selecting a payment method. I may not be very clear and I apologize for that. In the 5 step of the checkout I need to alter the prices of the products if the customer chooses the payment method 1, I have a model that is executed when the customer accepts the payment method that he chose, right there is where I need to change the prices. I need to know how to alter the quote at the checkout. Thanks so much for your time. – Waskalle Dec 29 '16 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.