I’m interested in modifying some protected values in this object. More specifically, I’d like to modify the price depending on the method if possible.. This object is a response from an XML shipping rate request to UPS. The problem I’m having is that the rates returned for different methods are not what I need. I don’t supply specific dimensions (exact numbers unavailable for an arbitrary request), so any methods other than UPS Ground yield an unsuitable rate. Note that one solution is to give it some estimated dimensions in the XML request in the first place (I’m working on testing this way), but I’d like to know how to work with this object as well.
I was trying to simply access some values within this object, but it seems like being protected, they don’t print to the browser? I tried $object->_rates[0] and $object->{_rates[0]} but they don’t print anything. Can someone point me in the right direction in modifying the price values in this object?
$object =
Mage_Shipping_Model_Rate_Result Object
(
[_rates:protected] => Array
(
[0] => Mage_Shipping_Model_Rate_Result_Method Object
(
[_data:protected] => Array
(
[carrier] => ups
[carrier_title] => UPS
[method] => 03
[method_title] => UPS Ground
[cost] => 8.9
[price] => 8.9
)
[_hasDataChanges:protected] => 1
[_origData:protected] =>
[_idFieldName:protected] =>
[_isDeleted:protected] =>
[_oldFieldsMap:protected] => Array
(
)
[_syncFieldsMap:protected] => Array
(
)
)
....
)
Usually protected properties are protected for a reason. There is a method
getAllRates()which allow you to edit what you want.That means you probably get something like this:
The method to change the price is documented in the Magento Documentation.
However changing the visibility of a property/method in general is possible with Reflection.
For instance you may use this:
But still, this is usually not the way you want to do that! This is not the OOP way.