diff --git a/src/Lib/Traits/InteractsWithAttributes.php b/src/Lib/Traits/InteractsWithAttributes.php index df17254d..2655f0ac 100644 --- a/src/Lib/Traits/InteractsWithAttributes.php +++ b/src/Lib/Traits/InteractsWithAttributes.php @@ -79,6 +79,27 @@ public function getFirstValueByAttributeCode(string $code) return $value; } + /** + * The method should get rid of addition conditions in templates + * + * @param string $code + * @param bool $asTitle By default we should display always Title field, + * but it should be also possible to use value + * @return string|null + */ + public function getFirstValueByAttributeCodeAsString(string $code, $asTitle = true) + { + $attributeValue = $this->getFirstValueByAttributeCode($code); + + if (!$attributeValue) { + return ""; + } + + $field = $asTitle ? 'title' : 'value'; + + return $attributeValue->$field; + } + /** * @param Attribute[] $attributes */ diff --git a/src/Resources/Shop/OrdersResource.php b/src/Resources/Shop/OrdersResource.php index 84cdc9de..6058a636 100644 --- a/src/Resources/Shop/OrdersResource.php +++ b/src/Resources/Shop/OrdersResource.php @@ -10,6 +10,7 @@ namespace SphereMall\MS\Resources\Shop; use SphereMall\MS\Entities\Order; +use SphereMall\MS\Lib\Makers\ObjectMaker; use SphereMall\MS\Lib\Makers\OrdersMaker; use SphereMall\MS\Lib\Shop\OrderFinalized; use SphereMall\MS\Resources\Resource; @@ -91,10 +92,12 @@ private function getOrderByParam($uriAppend) $params = $this->getQueryParams(); $response = $this->handler->handle('GET', false, $uriAppend, $params); - $orderCollection = $this->make($response); - if ($orderCollection) { + if ($response->getData()) { + $maker = empty($response->getData()[0]['relationships']) ? new ObjectMaker() : new OrdersMaker(); + /** @var $order Order */ + $order = $this->make($response, false, $maker); $orderFinalized = new OrderFinalized($this->client); - $orderFinalized->setOrderData($orderCollection[0]); + $orderFinalized->setOrderData($order); return $orderFinalized; }