-
Notifications
You must be signed in to change notification settings - Fork 16
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
Refactored product variant gateway and added handler to load stock of… #105
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,6 @@ public function getSecurityContext() | |
|
||
public function getLocale(Request $request) | ||
{ | ||
return $request->query->get('locale'); | ||
return $request->query->get('locale') ?? ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) MASSIVE ART WebServices GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\SyliusConsumerBundle\Model\Product\Handler\Query; | ||
|
||
use Sulu\Bundle\SyliusConsumerBundle\Gateway\ProductVariantGatewayInterface; | ||
use Sulu\Bundle\SyliusConsumerBundle\Model\Product\Query\LoadProductVariantStockQuery; | ||
|
||
class LoadProductVariantStockQueryHandler | ||
{ | ||
/** | ||
* @var ProductVariantGatewayInterface | ||
*/ | ||
private $gateway; | ||
|
||
public function __construct(ProductVariantGatewayInterface $productVariantGateway) | ||
{ | ||
$this->gateway = $productVariantGateway; | ||
} | ||
|
||
public function __invoke(LoadProductVariantStockQuery $query): void | ||
{ | ||
$variantData = $this->gateway->findByCodeAndVariantCode( | ||
$query->getCode(), | ||
$query->getVariantCode() | ||
); | ||
|
||
$query->setOnHand($variantData['onHand']); | ||
$query->setOnHold($variantData['onHold']); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of Sulu. | ||
* | ||
* (c) MASSIVE ART WebServices GmbH | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sulu\Bundle\SyliusConsumerBundle\Model\Product\Query; | ||
|
||
class LoadProductVariantStockQuery | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $code; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $variantCode; | ||
|
||
/** | ||
* @var int|null | ||
*/ | ||
private $onHold; | ||
|
||
/** | ||
* @var int|null | ||
*/ | ||
private $onHand; | ||
|
||
public function __construct(string $code, string $variantCode) | ||
{ | ||
$this->code = $code; | ||
$this->variantCode = $variantCode; | ||
} | ||
|
||
public function getCode(): string | ||
{ | ||
return $this->code; | ||
} | ||
|
||
public function getVariantCode(): string | ||
{ | ||
return $this->variantCode; | ||
} | ||
|
||
public function getOnHold(): ?int | ||
{ | ||
return $this->onHold; | ||
} | ||
|
||
public function setOnHold(?int $onHold): self | ||
{ | ||
$this->onHold = $onHold; | ||
|
||
return $this; | ||
} | ||
|
||
public function getOnHand(): ?int | ||
{ | ||
return $this->onHand; | ||
} | ||
|
||
public function setOnHand(?int $onHand): self | ||
{ | ||
$this->onHand = $onHand; | ||
|
||
return $this; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{% extends "SuluSyliusConsumerBundle:Email:master-email.html.twig" %} | ||
{% extends "@SuluSyliusConsumer/Email/master-email.html.twig" %} | ||
|
||
{% block content %} | ||
{% set confirmUrl = url('sulu_sylius.customer.verify', { token: token }) %} | ||
<a href="{{ confirmUrl }}">{{ confirmUrl }}</a> | ||
{% endblock %} | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,6 +17,7 @@ | |||||
use Sulu\Bundle\SyliusConsumerBundle\Model\Dimension\DimensionInterface; | ||||||
use Sulu\Bundle\SyliusConsumerBundle\Model\Product\Product; | ||||||
use Sulu\Bundle\SyliusConsumerBundle\Model\Product\ProductInformation; | ||||||
use Sulu\Bundle\SyliusConsumerBundle\Model\Product\ProductInterface; | ||||||
|
||||||
trait ProductInformationTrait | ||||||
{ | ||||||
|
@@ -29,8 +30,9 @@ protected function createProductInformation(string $productId, string $locale): | |||||
] | ||||||
); | ||||||
|
||||||
/** @var ProductInterface $product */ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whats the reason for this? also i dont think that type is right, cant this be null too? 🤔 |
||||||
$product = $this->getEntityManager()->find(Product::class, $productId); | ||||||
if (!$product) { | ||||||
if (!$product instanceof ProductInterface) { | ||||||
throw new \RuntimeException('Product not fount'); | ||||||
} | ||||||
|
||||||
|
@@ -52,8 +54,9 @@ protected function createProductInformationLive(string $productId, string $local | |||||
] | ||||||
); | ||||||
|
||||||
/** @var ProductInterface $product */ | ||||||
$product = $this->getEntityManager()->find(Product::class, $productId); | ||||||
if (!$product) { | ||||||
if (!$product instanceof ProductInterface) { | ||||||
throw new \RuntimeException('Product not fount'); | ||||||
} | ||||||
|
||||||
|
@@ -75,10 +78,13 @@ protected function findProductInformation(string $id, string $locale): ?ProductI | |||||
] | ||||||
); | ||||||
|
||||||
return $this->getEntityManager()->find( | ||||||
/** @var ProductInformation $productInformation */ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
$productInformation = $this->getEntityManager()->find( | ||||||
ProductInformation::class, | ||||||
['product' => $id, 'dimension' => $dimension] | ||||||
); | ||||||
|
||||||
return $productInformation; | ||||||
} | ||||||
|
||||||
protected function findProductInformationByCode(string $code, string $locale): ?ProductInformation | ||||||
|
@@ -95,13 +101,16 @@ protected function findProductInformationByCode(string $code, string $locale): ? | |||||
throw new \RuntimeException('Product not fount'); | ||||||
} | ||||||
|
||||||
return $this->getEntityManager()->find( | ||||||
/** @var ProductInformation $productInformation */ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
$productInformation = $this->getEntityManager()->find( | ||||||
ProductInformation::class, | ||||||
[ | ||||||
'product' => $product, | ||||||
'dimension' => $dimension, | ||||||
] | ||||||
); | ||||||
|
||||||
return $productInformation; | ||||||
} | ||||||
|
||||||
abstract protected function findDimension(array $attributes): DimensionInterface; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
''
is a strange fallback here. this could lead to confusing behaviour. i think i would expect an error here if no locale is givenThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.