|
23 | 23 | use Commercetools\Core\Model\Common\Money; |
24 | 24 | use Commercetools\Core\Model\Common\MoneyCollection; |
25 | 25 | use Commercetools\Core\Model\Common\PriceDraft; |
| 26 | +use Commercetools\Core\Model\Common\PriceTier; |
| 27 | +use Commercetools\Core\Model\Common\PriceTierCollection; |
26 | 28 | use Commercetools\Core\Model\CustomField\CustomFieldObject; |
27 | 29 | use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft; |
28 | 30 | use Commercetools\Core\Model\CustomField\FieldContainer; |
@@ -1161,6 +1163,98 @@ public function testAutomaticDelete() |
1161 | 1163 | $this->assertSame(2, $cart->getDeleteDaysAfterLastModification()); |
1162 | 1164 | } |
1163 | 1165 |
|
| 1166 | + public function testPriceTiersOnAddLineItem() |
| 1167 | + { |
| 1168 | + $productDraft = $this->getProductDraft(); |
| 1169 | + $productDraft->getMasterVariant()->getPrices()->current()->setTiers(PriceTierCollection::of() |
| 1170 | + ->add( |
| 1171 | + PriceTier::of()->setValue(Money::ofCurrencyAndAmount('EUR', 10))->setMinimumQuantity(2) |
| 1172 | + ) |
| 1173 | + ->add( |
| 1174 | + PriceTier::of()->setValue(Money::ofCurrencyAndAmount('EUR', 1))->setMinimumQuantity(3) |
| 1175 | + ) |
| 1176 | + ); |
| 1177 | + $product = $this->getProduct($productDraft); |
| 1178 | + $variant = $product->getMasterData()->getCurrent()->getMasterVariant(); |
| 1179 | + |
| 1180 | + $draft = $this->getDraft(); |
| 1181 | + $draft->setLineItems( |
| 1182 | + LineItemDraftCollection::of() |
| 1183 | + ->add(LineItemDraft::of()->setProductId($product->getId())->setVariantId($variant->getId())->setQuantity(1)) |
| 1184 | + ); |
| 1185 | + $cart = $this->createCart($draft); |
| 1186 | + |
| 1187 | + $this->deleteRequest->setVersion($cart->getVersion()); |
| 1188 | + |
| 1189 | + $this->assertSame($product->getId(), $cart->getLineItems()->current()->getProductId()); |
| 1190 | + $this->assertSame( |
| 1191 | + $product->getProductType()->getId(), |
| 1192 | + $cart->getLineItems()->current()->getProductType()->getId() |
| 1193 | + ); |
| 1194 | + $this->assertSame( |
| 1195 | + 100, |
| 1196 | + $cart->getLineItems()->current()->getPrice()->getValue()->getCentAmount() |
| 1197 | + ); |
| 1198 | + |
| 1199 | + $request = CartUpdateRequest::ofIdAndVersion($cart->getId(), $cart->getVersion()) |
| 1200 | + ->addAction( |
| 1201 | + CartAddLineItemAction::ofProductIdVariantIdAndQuantity($product->getId(), $variant->getId(), 1) |
| 1202 | + ); |
| 1203 | + |
| 1204 | + $response = $request->executeWithClient($this->getClient()); |
| 1205 | + $cart = $request->mapResponse($response); |
| 1206 | + $this->deleteRequest->setVersion($cart->getVersion()); |
| 1207 | + |
| 1208 | + $this->assertSame($product->getId(), $cart->getLineItems()->current()->getProductId()); |
| 1209 | + $this->assertSame( |
| 1210 | + $product->getProductType()->getId(), |
| 1211 | + $cart->getLineItems()->current()->getProductType()->getId() |
| 1212 | + ); |
| 1213 | + $this->assertSame( |
| 1214 | + 10, |
| 1215 | + $cart->getLineItems()->current()->getPrice()->getValue()->getCentAmount() |
| 1216 | + ); |
| 1217 | + |
| 1218 | + $request = CartUpdateRequest::ofIdAndVersion($cart->getId(), $cart->getVersion()) |
| 1219 | + ->addAction( |
| 1220 | + CartChangeLineItemQuantityAction::ofLineItemIdAndQuantity($cart->getLineItems()->current()->getId(), 3) |
| 1221 | + ) |
| 1222 | + ; |
| 1223 | + $response = $request->executeWithClient($this->getClient()); |
| 1224 | + $cart = $request->mapResponse($response); |
| 1225 | + $this->deleteRequest->setVersion($cart->getVersion()); |
| 1226 | + $this->assertSame(3, $cart->getLineItems()->current()->getQuantity()); |
| 1227 | + $this->assertSame( |
| 1228 | + 1, |
| 1229 | + $cart->getLineItems()->current()->getPrice()->getValue()->getCentAmount() |
| 1230 | + ); |
| 1231 | + |
| 1232 | + $request = CartUpdateRequest::ofIdAndVersion($cart->getId(), $cart->getVersion()) |
| 1233 | + ->addAction( |
| 1234 | + CartRemoveLineItemAction::ofLineItemId($cart->getLineItems()->current()->getId())->setQuantity(1) |
| 1235 | + ) |
| 1236 | + ; |
| 1237 | + $response = $request->executeWithClient($this->getClient()); |
| 1238 | + $cart = $request->mapResponse($response); |
| 1239 | + $this->deleteRequest->setVersion($cart->getVersion()); |
| 1240 | + |
| 1241 | + $this->assertSame(2, $cart->getLineItems()->current()->getQuantity()); |
| 1242 | + $this->assertSame( |
| 1243 | + 10, |
| 1244 | + $cart->getLineItems()->current()->getPrice()->getValue()->getCentAmount() |
| 1245 | + ); |
| 1246 | + |
| 1247 | + $request = CartUpdateRequest::ofIdAndVersion($cart->getId(), $cart->getVersion()) |
| 1248 | + ->addAction( |
| 1249 | + CartRemoveLineItemAction::ofLineItemId($cart->getLineItems()->current()->getId()) |
| 1250 | + ) |
| 1251 | + ; |
| 1252 | + $response = $request->executeWithClient($this->getClient()); |
| 1253 | + $cart = $request->mapResponse($response); |
| 1254 | + $this->deleteRequest->setVersion($cart->getVersion()); |
| 1255 | + $this->assertCount(0, $cart->getLineItems()); |
| 1256 | + } |
| 1257 | + |
1164 | 1258 | /** |
1165 | 1259 | * @return CartDraft |
1166 | 1260 | */ |
|
0 commit comments