Skip to content

Commit

Permalink
Merge pull request #292 from AcclaroInc/hotfix/tag-issue
Browse files Browse the repository at this point in the history
fix: tag labels missing after adding entry on create order
  • Loading branch information
sidedwards authored Jan 14, 2022
2 parents 385a9ff + 58a8df6 commit 818f27a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
8 changes: 0 additions & 8 deletions src/controllers/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,6 @@ public function actionOrderDetail(array $variables = array())
$order->targetSites = json_encode($orderTargetSites);
}

if (! empty(json_decode($order->tags, true))) {
$variables['tags'] = [];

foreach (json_decode($order->tags, true) as $tagId) {
$variables['tags'][] = Craft::$app->getTags()->getTagById($tagId);
}
}

if ($orderTags= Craft::$app->getRequest()->getQueryParam('tags') ?? Craft::$app->getRequest()->getParam('tags')) {
if (! is_array($orderTags)) {
$orderTags = explode(',', $orderTags);
Expand Down
5 changes: 5 additions & 0 deletions src/elements/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,11 @@ public function getOwner()
return $owner;
}

public function getTags()
{
return Translations::$plugin->tagRepository->getOrderTags($this);
}

public function getTargetSitesArray()
{
return $this->targetSites ? json_decode($this->targetSites, true) : array();
Expand Down
21 changes: 20 additions & 1 deletion src/services/repository/TagRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Craft;
use craft\elements\Tag;
use acclaro\translations\elements\Order;

class TagRepository
{
Expand All @@ -31,4 +32,22 @@ public function saveTag(Tag $tag)
Craft::error( '['. __METHOD__ .'] Couldn’t save the tag "'.$tag->title.'"', 'translations' );
}
}
}

/**
* Get Tags Object for an order
*
* @param Order $order
* @return array
*/
public function getOrderTags(Order $order)
{
$orderTags = [];
if ($order->tags) {
foreach (json_decode($order->tags, true) as $tagId) {
$orderTags[$tagId] = Craft::$app->getTags()->getTagById($tagId);
}
}

return $orderTags;
}
}
4 changes: 2 additions & 2 deletions src/templates/_components/orders/settings-tab.twig
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@
<div class="input ltr">
<div id="fields-tags" class="elementselect tagselect">
<div id="elementTags" class="elements">
{% if tags is defined %}
{% for tag in tags %}
{% if not order.getTags is empty %}
{% for tag in order.getTags %}
<div class="element small removable" data-editable="1" data-id="{{ tag.id }}" data-label="{{ tag.title }}">
<input type="hidden" name="tags[]" value="{{ tag.id }}"/>
<a class="delete icon custom-tag" data-label="{{ tag.title }}" data-id="{{ tag.id }}" title="Remove"></a>
Expand Down

0 comments on commit 818f27a

Please sign in to comment.