Magento table "sales_flat_order" field "protect_code" explanation

We are working on a database and tables magento. Magento seems to have written code in the sales_flat_order protect_code field to determine if there is an invoice or a shipment has already been made. It would look like

01b335 or
a0a243

But there is no key to understand what this security code means. Is there any explanation for the meaning of these codes and their generation?

+7
design database mysql magento
source share
1 answer

Where is it generated?

If you look in app/code/core/Mage/Sales/Model/Order.php on line 2052 , you will find the following:

 $this->setData('protect_code', substr(md5(uniqid(mt_rand(), true) . ':' . microtime(true)), 5, 6)); 

Here protect_code generated for order (using a combination of md5, uniqid and random integer.

What is it used for?

If you look at app/code/core/Mage/Sales/Helper/Guest.php and find the loadValidOrder function. You will see that protect_code used in some areas to ensure that the loaded order is correct for the guest cookie value.

It is also used in other areas, such as matching tracking information. You can see several instances of the getProtectCode() method called in submit models to compare order with tracking information. Example function used:

 public function getTrackingInfoByTrackId() { $track = Mage::getModel('sales/order_shipment_track')->load($this->getTrackId()); if ($track->getId() && $this->getProtectCode() == $track->getProtectCode()) { $this->_trackingInfo = array(array($track->getNumberDetail())); } return $this->_trackingInfo; } 

As you can see with $this->getProtectCode() == $track->getProtectCode() , protect_code tracking should match Shipping protect_code .

+21
source share

All Articles