3

Hello I'm trying to add custom data to shipping method (image url, to be exact). Following this example I managed to add extension attribute to interface and show field named 'image' in extension attributes (in JSON view). So now I'm stuck on how to populate that extension attribute when creating method.

For example I would need to do something like this:

    $method = $this->_rateMethodFactory->create();
    $method->setCarrier($carrier);
    $method->setCarrierTitle($carrier_title);
    $method->setMethod($carrier_method);
    $method->setMethodTitle($carrier_method_title);
    $method->setPrice($price);
    $method->setCost($price);
    $method->setData('image','https://someurl.com.image.jpg');
    $result->append($method);

The problem is in this line:

$method->setData('image','https://someurl.com.image.jpg');
// I also tried using this
$method->setImage('https://someurl.com.image.jpg');

But either way I can't get that because it doesn't exist when I list all data from shipping method in front controller. I tried using:

$result->getData('image');
// I also tried
$result->getImage('image');

And when I try:

$result->getExtensionAttributes();

it returns null.

Could you please help me how set some data when creating method and pass it to extension attribute.

  • try using $method->addData() instead of $method->setData() – simple guy Oct 3 '17 at 8:56
  • This doesn't seem to work either. addData requires array and once array is passed it doesn't show it using getData(). – Filip Kunjadić - Ćulibrk Oct 3 '17 at 9:36
0

It's not that easy to pass data as extension attribute. Please refer to this question https://stackoverflow.com/q/34202497/2536631

  • Thank you for this link, but in the end I've solved it using Magento Registry since that data doesn't need to be stored anyway, just displayed at frontend. – Filip Kunjadić - Ćulibrk Jul 23 '18 at 14:55
  • how can you solve this? please let me know. – Akash Sep 17 '18 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.