Social Network for Web Professionals

Webmaster Blog

Members blog at WebmaisterPro. Covering topics related to online marketing, SEO, web development as well as software reviews.

Magento Issue: Repairing a Rebill Module

One of our clients owns a website that provides instructionals, tutorials, and online classes for a monthly fee. One of the issues that Magento has is that sometimes, when the rebill function is called in a module, it accesses the database, memcache, and zencache to recall the previous order.

However, sometimes, for reasons our developers couldn't find out, that memcache, or zencache, which is supposed to be cleared after each unique session, somehow calls the wrong customer or customerID for the rebill module. Essentially what this means is that the wrong person is being billed for someone else's usage. Imagine the call you'll get from that first valued customer and you'll see why Customer Paradigm put not one but two of our developers on the issue.

Here's a quick summary of the issue:

  1. The Rebill function takes the previous order information and uses that to bill the client on a monthly basis.
  2. Instead, our Rebill function is calling the database, and both caches, and returning incorrect customer information and the CustomerID assigned to the user via Authorize.net
  3. After an hour of searching from two developers, disabling memcache, the problem either lies in how the module is calling the database, or it is getting some information from zencache, which in turn is not flushing after each session.
  4. The issue then can be the database, the module, zencache, or the flush command.

The Solution:

Instead of attempting to target each issue individually, our developers decided to hard code the functions right into the module. Here is the final code:

 

public function rebill($chargeProduct,$customerId) {
Mage::unregister('rule_data');
$chargeProductItem =
Mage::getModel('sales/order_item');
$chargeProductItem->setProductId($chargeProduct->getEntityId())->setIsVirtual(true)->setQtyOrdered(1);
Mage::getSingleton("adminhtml/session_quote")->getCustomer(true,true);
Mage::getSingleton("adminhtml/session_quote")->setCustomerId($customerId);
Mage::getSingleton("adminhtml/session_quote")->setCustomer(Mage::getModel("customer/customer")->load($customerId));
$this->newOrderSingleton->getQuote()->assignCustomer(Mage::getModel("customer/customer")->load($customerId));
$this->newOrderSingleton->saveQuote();
$this->oldOrder->setReordered(false);
$this->newOrderSingleton->initFromOrder($this->oldOrder);

$newQuote =
$this->removeAllProductsFromNewOrder();
$newQuote =
$this->addProductToQuote($chargeProduct,$newQuote);

$paymentObj = $newQuote->getPayment();

$newQuote->save();
$paymentObj->setQuote($newQuote);

$paymentData =
$this->createPaymentData($customerId);
$paymentObj->importData($paymentData);

$service =
Mage::getModel('sales/service_quote', $newQuote);
$service->submitAll();

 

Here, you can see that we hard-coded 3 new functions into the Rebill module. First, the code gets the Customer name from the database; second, we then call the servers at Authorize.net to get the unique customer ID, which references information stored on their database, and set it. Finally, we then set the customer to the customerID as long as the data matches up.

Afterward, the module works as designed, essentially forcing the module to review the information before completing its task. Is this a perfect solution? Probably not; however, for very little time, and for sites that have set products and their business relies on the Rebill module for Magento, this modification to the code will make sure that all of your information is correct before billing. At the very least, it will save you headaches and angry phone calls.

About Author

Pete Wise is a Content Creation Factory and a White-Hat SEO Jedi. This article was written at Customer Paradigm, right after two of our expert Magento Developers fixed the issue. If you need help with a Magento Upgrade, visit our website and speak to a live representitive! Follow Pete on Twitter: @MySEOHeadache

Rate this blog entry:
2
Lasso - Make Life Easy with Business Card Reader
5 Reasons Why You Should Use WordPress For Your We...

Related Posts

Comments

 
No comments yet
Already Registered? Login Here
Guest
Friday, 23 October 2020
If you'd like to register, please fill in the username and name fields.

Captcha Image