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

New method for Attributes trait, compability with new response for /orders #62

Merged
merged 2 commits into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/Lib/Traits/InteractsWithAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
9 changes: 6 additions & 3 deletions src/Resources/Shop/OrdersResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down