davit_sargsyandavit_sargsyan MemberComments: 12 Received thanks: 0 Member since: June 2018

I try to call get() function from Shopware\Bundle\StoreFrontBundle\Struct\Attribute in order to access storage variables but it does not work, 

{$supplier.attributes.core->toArray()|var_dump}

{$supplier.attributes.core->get("external_link")|var_dump}

none of the above functions work, however they are public functions, what is the problem here?

1 Answer

  • Moritz NaczenskiMoritz Naczenski AdministratorsComments: 7882 Received thanks: 2305 Member since: September 2013

    The get() will cause an exception, when there is no entry for this specific supplier in the s_articles_supplier_attributes table. You should add an IF-Statement like this:

    {if $supplier.attributes.core}
    {$supplier.attributes.core->get('attribute')}
    {/if}

    There might be some old installations that are missing the entries, because this functionality was added with 5.2. You cann add an entry for every supplier via sql to fix this.

    Quote
    Accepted Answer
    Thanked by 1davit_sargsyan
  • Accepted Answer

Answers

  • Moritz NaczenskiMoritz Naczenski AdministratorsComments: 7882 Received thanks: 2305 Member since: September 2013

    The get() will cause an exception, when there is no entry for this specific supplier in the s_articles_supplier_attributes table. You should add an IF-Statement like this:

    {if $supplier.attributes.core}
    {$supplier.attributes.core->get('attribute')}
    {/if}

    There might be some old installations that are missing the entries, because this functionality was added with 5.2. You cann add an entry for every supplier via sql to fix this.

    Quote
    Accepted Answer
    Thanked by 1davit_sargsyan
  • davit_sargsyandavit_sargsyan MemberComments: 12 Received thanks: 0 Member since: June 2018

    @Moritz Naczenski‍ Thank you very much, I've added the if statement and it worked, so that means if you call a function on null it will throw an exception right? 

Sign In or Register to comment.