1 | <?php |
||
13 | class ArticleService extends AbstractService |
||
14 | { |
||
15 | /** |
||
16 | * Get the articles. |
||
17 | * |
||
18 | * @param string $articleNumber Article number to filter on. |
||
19 | * @return Get\ApiResponse |
||
20 | */ |
||
21 | 3 | public function getArticles($articleNumber = null) |
|
22 | { |
||
23 | 3 | $requestData = new Get\RequestData(); |
|
24 | 3 | $requestData->setArticleNumber($articleNumber); |
|
25 | |||
26 | 3 | $request = new Get\Request($requestData); |
|
27 | |||
28 | 3 | return $this->sendRequest($request, Get\ApiResponse::class); |
|
29 | } |
||
30 | |||
31 | /** |
||
32 | * Get one article by article number. |
||
33 | * |
||
34 | * @param string $articleNumber Article number of the article to get. |
||
35 | * @return Article|null |
||
36 | */ |
||
37 | 12 | public function getArticle($articleNumber) |
|
38 | { |
||
39 | 12 | $requestData = new Get\RequestData(); |
|
40 | 12 | $requestData->setArticleNumber($articleNumber); |
|
41 | |||
42 | 12 | $request = new Get\Request($requestData); |
|
43 | 12 | $request->setLimit(1); |
|
44 | |||
45 | /** @var Get\ApiResponse $apiResponse */ |
||
46 | 12 | $apiResponse = $this->sendRequest($request, Get\ApiResponse::class); |
|
47 | 12 | $articles = $apiResponse->getResponse()->getArticles(); |
|
48 | |||
49 | 12 | return isset($articles[0]) ? $articles[0] : null; |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * Get the article checkout URL. |
||
54 | * |
||
55 | * @param Article $article The article. |
||
56 | * @param Customer|null $customer The customer. |
||
57 | * @return string |
||
58 | */ |
||
59 | 9 | public function getArticleCheckoutURL(Article $article, Customer $customer = null) |
|
60 | { |
||
61 | 9 | if ($customer === null) { |
|
62 | 3 | return $article->getCheckoutUrl(); |
|
63 | } |
||
64 | |||
65 | 6 | return $this->generateCheckoutURLForCustomer($customer->getCustomerId(), $article->getArticleNumber()); |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * Get the checkout URL for an article. |
||
70 | * |
||
71 | * @param string $articleNumber Article number of the article to get the checkout URL. |
||
72 | * @param Customer $customer The customer for which the checkout URL should be created. |
||
73 | * @return string |
||
74 | */ |
||
75 | 9 | public function getArticleNumberCheckoutURL($articleNumber, Customer $customer = null) |
|
76 | { |
||
77 | 9 | $article = $this->getArticle($articleNumber); |
|
78 | 9 | if ($article === null) { |
|
79 | 3 | throw new \OutOfBoundsException('Article not found.'); |
|
80 | } |
||
81 | |||
82 | 6 | return $this->getArticleCheckoutURL($article, $customer); |
|
83 | } |
||
84 | |||
85 | /** |
||
86 | * Get the checkout URL for an article. |
||
87 | * |
||
88 | * @deprecated Use getArticleNumberCheckoutURL |
||
89 | * |
||
90 | * @param string $articleNumber Article number of the article to get the checkout URL. |
||
91 | * @param Customer $customer The customer for which the checkout URL should be created. |
||
92 | * @return string |
||
93 | */ |
||
94 | public function getCheckoutURL($articleNumber, Customer $customer = null) |
||
98 | |||
99 | /** |
||
100 | * Get the checkout URL of an article for a customer. |
||
101 | * |
||
102 | * @param string $customerId The customer ID. |
||
103 | * @param string $articleNumber The article number. |
||
104 | * @return string |
||
105 | */ |
||
106 | 6 | protected function generateCheckoutURLForCustomer($customerId, $articleNumber) |
|
115 | |||
116 | /** |
||
117 | * Get the checkout URL to change a product for a subscription. |
||
118 | * |
||
119 | * @param Subscription $subscription The subscription. |
||
120 | * @param Article $article The new article. |
||
121 | * @return string |
||
122 | */ |
||
123 | 3 | public function getSubscriptionProductChangeURL(Subscription $subscription, Article $article) |
|
127 | |||
128 | /** |
||
129 | * Get the checkout URL to change a product for a subscription. |
||
130 | * |
||
131 | * @param string $subscriptionId The subscription ID. |
||
132 | * @param string $articleNumber The new article number. |
||
133 | * @return string |
||
134 | */ |
||
135 | 3 | protected function generateSubscriptionProductChangeURL($subscriptionId, $articleNumber) |
|
144 | } |
||
145 |