postnl/postnl-magento1-End-of-life

Recoverable Error: Argument 1 passed to TIG_PostNL_Helper_ProductCode::getDefault() must be an instance of TIG_PostNL_Model_Core_Order, boolean given

Closed this issue · 2 comments

  • [x ] I've verified and I assure that I'm running the latest version of the TIG PostNL Magento
  • [ x] Bug report (encountered problems with the TIG PostNL Magento extension)

Description of your issue, suggested solution and other information

Hello We have encountered an issue with the latest (1.15.1) version of the extention
The issue is that our client cannot ship an old order, and with old I mean an order that was created when the previous version of the extention was installed (in our case this was in the 1.12.x range)

workflow: Go to magento backend get an older order and create a new shipment, fill the relevant fields and save the shipment. Result: blank page.

Here is the relevant part of the corresponding stack trace (I starred out sentitive data):
*****.app/code/community/TIG/PostNL/Helper/ProductCode.php(47):mageCoreErrorHandler(4096, 'Argument 1 pass..., 47, Array)

#1 *******************public_html/vendor/tig/postnl-magento1/app/code/community/TIG/PostNL/Model/Core/Shipment.php(1249): TIG_PostNL_Helper_ProductCode->getDefault(false, 'STORE_ID', 'domestic')

The issue is TIG_PostNL_Helper_ProductCode->getDefault(false, 'STORE_ID', 'domestic') getDefault is called with false in the first parameter.

Here is the corresponding function declaration in TIG_PostNL_Helper_ProductCode:
public function getDefault(
TIG_PostNL_Model_Core_Order $postnlOrder,
$storeId,
$shipmentType,
TIG_PostNL_Model_Core_Shipment $shipment = null
)

This is called from: Model_Core_Shipment line 1249: also see:

if ($this->hasDefaultProductCode()) {
return $this->_getData('default_product_code');
}
$storeId = $this->getStoreId();
$shipmentType = $this->getShipmentType();

    $postnlOrder = $this->getPostnlOrder();
    $productCode = $this->getHelper('productCode')->getDefault($postnlOrder, $storeId, $shipmentType);

The method getPostnlOrder() can return false which seems to happen in our case. However the method definition of getDefault( .. ) does not take that into account. When checking the code of getDefault I found various checks to check if $postnlOrder is indeed an object if ($postnlOrder) { ... } etc

Suggested fix: declare getDefault as
public function getDefault(
$postnlOrder,
$storeId,
$shipmentType,
TIG_PostNL_Model_Core_Shipment $shipment = null
)

Or change the order of params and let $postnlOrder have a default value, which seems to have more impact.

I am not sure if the case getPostnlOrder returns false is even an intended use case But I cannot be the judge of that. It could be that this is an edge case and that you will not be able to reproduce this however the incompatibility in code is quite clear.

With kind regards, Edwin Jacobs

Good afternoon Edwin,

Thank you for submitting this. Just tested this situation on our test environment, but i am unable to reproduce this problem. No blank page appears and i am able to create a shipment from an old order (placed with extension version 1.12.1) after i upgrade to 1.15.1.

Nonetheless i will ask my colleague to take a look at the code you provided. Me or my colleague will get back to you on this.

Kind regards,

Jasper
TIG

It seems that this particular case has been accounted for in release 1.15.4.

Therefor I will close this issue. With kind regards, Edwin Jacobs