Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Template.php #9399

Closed
wants to merge 4 commits into from
Closed

Update Template.php #9399

wants to merge 4 commits into from

Conversation

thiagolima-bm
Copy link
Member

@thiagolima-bm thiagolima-bm commented Apr 25, 2017

This update enable the use of loop into template files. Allowing the user iterate through collections

Description

Fixed Issues (if relevant)

  1. magento/magento2#<issue_number>: Issue title
  2. ...

Manual testing scenarios

consider $template as Magento\Email\Model\Template
the email template as follows
$value = "
{{var order.increment_id}}

{{loop order.all_visible_items delimiter=,}}
{
'sku': '{{var item.sku}}',
'name': '{{var item.name}}',
'price': {{var item.price}},
'quantity': {{var item.ordered_qty}}
}
{{/loop}}

{{var order.customer_id}}

{{loop things.collection delimiter=,}}
{
'name': '{{var item.name}}',
'lastname': '{{var item.lastname}}',
'age': '{{var item.age}}',
}
{{/loop}}
";
$template->setTemplateText($value);
$template = new Magento\Email\Model\Template(new Magento\Framework\Model\Context)
$template->setTemplateText($value);
$thing_1 = new Varien_Object();
$thing_1->setName('Richard');
$thing_1->setAge(24);

$thing_2 = new Varien_Object();
$thing_2->setName('Jane');
$thing_2->setAge(12);

$thing_3 = new Varien_Object();
$thing_3->setName('Spot');
$thing_3->setLastName('The Dog');
$thing_3->setAge(7);

$collection_of_things = new Varien_Data_Collection();
$collection_of_things
    ->addItem($thing_1)
    ->addItem($thing_2)
    ->addItem($thing_3);

$things = new Varien_Object();
$things->setData('collection', $collection_of_things);

echo $template->getProcessedTemplate(array('order' => $order, 'things' => $things));

This update enable the use of loop into template files. Allowing the user iterate through collections

e.g.:

{{var order.increment_id}}

{{loop order.all_visible_items delimiter=,}}
    {
       'sku': '{{var item.sku}}',
       'name': '{{var item.name}}',
       'price': {{var item.price}},
       'quantity': {{var item.ordered_qty}}
    }
{{/loop}}

{{var order.customer_id}}
@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Apr 25, 2017

CLA assistant check
All committers have signed the CLA.

@orlangur
Copy link
Contributor

@thiagolima-bm how is this different from #9401?

@thiagolima-bm
Copy link
Member Author

@orlangur Is the same. I do not know how to remove this one.

@ishakhsuvarov
Copy link
Contributor

@thiagolima-bm Closing this per your comment.

@ishakhsuvarov ishakhsuvarov self-assigned this Apr 27, 2017
@thiagolima-bm
Copy link
Member Author

@ishakhsuvarov how about #9401? :)

@ishakhsuvarov
Copy link
Contributor

@thiagolima-bm Need some more time to look into it and provide feedback. I'll let you know asap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants