I have a model that contains a bunch of storage arrays where I collect results from various services I have written.
class Shipper_ResultsModel extends BaseModel
{
shipping categories for debugging
protected function defineAttributes()
{
return array(
'service' => array('type'=>AttributeType::Enum, 'values'=>['post','courier','free','cantShip','needsQuote']),
'options' => array('type'=>AttributeType::Mixed,'default'=>[]),
'boxes' => array('type'=>AttributeType::Mixed,'default'=>[]),
'postShippingItems' => array('type'=>AttributeType::Mixed,'default'=>[]),
'courierShippingItems' => array('type'=>AttributeType::Mixed,'default'=>[]),
'freeShippingItems' => array('type'=>AttributeType::Mixed,'default'=>[]),
'cantShippingItems' => array('type'=>AttributeType::Mixed,'default'=>[]),
'quoteShippingItems' => array('type'=>AttributeType::Mixed,'default'=>[]),
);
}
Each of this ShippingItems
arrays is intended to hold an array of Shipper_ShippingItem models.
My issue is in building these arrays, I create new items and add them like this:
$shippingItem = Shipper_ShippingItemModel::populateModel($data);
//build our arrays of items
if($shippingClass=="Courier Only"){
$results->courierShippingItems[] = $shippingItem;
}
But this results in the following error:
PHP Notice: Indirect modification of overloaded property Craft\Shipper_ResultsModel::$courierShippingItems has no effect
I think this is because I am not using array objects as such but I have to say I've got a little confused here and various syntax experiments have resulted in ignoble failures.
Some guidance as to the right way would be much appreciated (and am I right in using AttributeType::Mixed
for these?)
(This is all for a mega shipping calculator for Craft Commerce, should that matter)