magento table “sales_flat_order” field “protect_code” explanation

前端 未结 1 1923
星月不相逢
星月不相逢 2021-02-15 13:01

We are working on magento database and tables. Magento seems to write a code in table sales_flat_order field protect_code to define if there is a invoi

1条回答
  •  生来不讨喜
    2021-02-15 13:34

    Where is it generated?

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

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

    This is where protect_code is generated for the order (using a combination of md5, uniqid, and random integer.

    What is it used for?

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

    It's also used in other areas, such as tracking information comparisons. You can see several instances of the getProtectCode() method being called in the Shipment models to compare the order to the tracking information. An example of a function that uses it is:

    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(), the tracking protect_code must match the Shipment protect_code.

    0 讨论(0)
提交回复
热议问题