1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Terox\SubscriptionBundle\Strategy; |
4
|
|
|
|
5
|
|
|
use Terox\SubscriptionBundle\Exception\ProductDefaultNotFoundException; |
6
|
|
|
use Terox\SubscriptionBundle\Exception\ProductExpiredException; |
7
|
|
|
use Terox\SubscriptionBundle\Exception\ProductIntegrityException; |
8
|
|
|
use Terox\SubscriptionBundle\Exception\ProductQuoteExceededException; |
9
|
|
|
use Terox\SubscriptionBundle\Model\ProductInterface; |
10
|
|
|
|
11
|
|
|
class ProductDefaultStrategy extends AbstractProductStrategy |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* {@inheritdoc} |
15
|
|
|
*/ |
16
|
7 |
|
public function getFinalProduct(ProductInterface $product) |
17
|
|
|
{ |
18
|
|
|
try { |
19
|
|
|
|
20
|
7 |
|
$this->checkProductIntegrity($product); |
21
|
7 |
|
$this->checkExpiration($product); |
22
|
6 |
|
$this->checkQuote($product); |
23
|
|
|
|
24
|
5 |
|
return $product; |
25
|
|
|
|
26
|
2 |
|
} catch (ProductIntegrityException $exception) { |
27
|
|
|
|
28
|
|
|
$this->getLogger()->error('Product integrity: {message}', [ |
29
|
|
|
'message' => $exception->getMessage() |
30
|
|
|
]); |
31
|
|
|
|
32
|
2 |
|
} catch (ProductExpiredException $exception) { |
33
|
|
|
|
34
|
1 |
|
$this->getLogger()->error('Product is expired: {message}', [ |
35
|
1 |
|
'message' => $exception->getMessage() |
36
|
|
|
]); |
37
|
|
|
|
38
|
1 |
|
} catch (ProductQuoteExceededException $exception) { |
39
|
|
|
|
40
|
1 |
|
$this->getLogger()->error('Product quota is exceeded: {message}', [ |
41
|
1 |
|
'message' => $exception->getMessage() |
42
|
|
|
]); |
43
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
2 |
|
return $this->getDefaultProduct(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Get default product in case of that current product is not valid. |
51
|
|
|
* |
52
|
|
|
* @return ProductInterface |
53
|
|
|
* |
54
|
|
|
* @throws ProductDefaultNotFoundException |
55
|
|
|
*/ |
56
|
2 |
|
private function getDefaultProduct() |
57
|
|
|
{ |
58
|
2 |
|
$defaultProduct = $this->getProductRepository()->findDefault(); |
59
|
|
|
|
60
|
2 |
|
if (null !== $defaultProduct) { |
61
|
2 |
|
return $defaultProduct; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
throw new ProductDefaultNotFoundException('Default product was not found into the product repository'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|