|
13 | 13 | use Commercetools\Core\Model\CartDiscount\CartDiscountValue; |
14 | 14 | use Commercetools\Core\Model\Common\Money; |
15 | 15 | use Commercetools\Core\Model\Common\MoneyCollection; |
| 16 | +use Commercetools\Core\Model\CustomField\CustomFieldObjectDraft; |
16 | 17 | use Commercetools\Core\Model\DiscountCode\DiscountCode; |
17 | 18 | use Commercetools\Core\Model\DiscountCode\DiscountCodeDraft; |
18 | 19 | use Commercetools\Core\Model\Common\LocalizedString; |
| 20 | +use Commercetools\Core\Model\Type\Type; |
19 | 21 | use Commercetools\Core\Request\CartDiscounts\CartDiscountCreateRequest; |
20 | 22 | use Commercetools\Core\Request\CartDiscounts\CartDiscountDeleteRequest; |
| 23 | +use Commercetools\Core\Request\CustomField\Command\SetCustomFieldAction; |
| 24 | +use Commercetools\Core\Request\CustomField\Command\SetCustomTypeAction; |
21 | 25 | use Commercetools\Core\Request\DiscountCodes\Command\DiscountCodeChangeCartDiscountsAction; |
22 | 26 | use Commercetools\Core\Request\DiscountCodes\Command\DiscountCodeChangeIsActiveAction; |
23 | 27 | use Commercetools\Core\Request\DiscountCodes\Command\DiscountCodeSetCartPredicateAction; |
@@ -62,7 +66,7 @@ protected function createCartDiscount($draft) |
62 | 66 | $response = $request->executeWithClient($this->getClient()); |
63 | 67 | $cartDiscount = $request->mapResponse($response); |
64 | 68 |
|
65 | | - $this->discountDeleteRequests[] = CartDiscountDeleteRequest::ofIdAndVersion( |
| 69 | + $this->discountDeleteRequests[] = $this->deleteRequest = CartDiscountDeleteRequest::ofIdAndVersion( |
66 | 70 | $cartDiscount->getId(), |
67 | 71 | $cartDiscount->getVersion() |
68 | 72 | ); |
@@ -120,6 +124,51 @@ protected function createDiscountCode(DiscountCodeDraft $draft) |
120 | 124 | return $discountCode; |
121 | 125 | } |
122 | 126 |
|
| 127 | + public function testCustomTypeCreate() |
| 128 | + { |
| 129 | + $type = $this->getType($this->getTestRun() . '-discount-type', 'discount-code'); |
| 130 | + $draft = $this->getDraft('discount-type'); |
| 131 | + $draft->setCustom(CustomFieldObjectDraft::ofTypeKey($type->getKey())); |
| 132 | + $discountCode = $this->createDiscountCode($draft); |
| 133 | + |
| 134 | + $this->assertSame($type->getId(), $discountCode->getCustom()->getType()->getId()); |
| 135 | + } |
| 136 | + |
| 137 | + public function testCustomTypeUpdate() |
| 138 | + { |
| 139 | + $type = $this->getType($this->getTestRun() . '-discount-type', 'discount-code'); |
| 140 | + $draft = $this->getDraft('discount-type'); |
| 141 | + $discountCode = $this->createDiscountCode($draft); |
| 142 | + |
| 143 | + $request = DiscountCodeUpdateRequest::ofIdAndVersion($discountCode->getId(), $discountCode->getVersion()) |
| 144 | + ->addAction(SetCustomTypeAction::ofTypeKey($type->getKey())) |
| 145 | + ; |
| 146 | + $response = $request->executeWithClient($this->getClient()); |
| 147 | + $result = $request->mapResponse($response); |
| 148 | + $this->deleteRequest->setVersion($result->getVersion()); |
| 149 | + |
| 150 | + $this->assertSame($type->getId(), $result->getCustom()->getType()->getId()); |
| 151 | + } |
| 152 | + |
| 153 | + public function testCustomFieldUpdate() |
| 154 | + { |
| 155 | + $type = $this->getType($this->getTestRun() . '-discount-type', 'discount-code'); |
| 156 | + $draft = $this->getDraft('discount-type'); |
| 157 | + $draft->setCustom(CustomFieldObjectDraft::ofTypeKey($type->getKey())); |
| 158 | + $discountCode = $this->createDiscountCode($draft); |
| 159 | + |
| 160 | + $newValue = $this->getTestRun() . '-value'; |
| 161 | + $request = DiscountCodeUpdateRequest::ofIdAndVersion($discountCode->getId(), $discountCode->getVersion()) |
| 162 | + ->addAction(SetCustomFieldAction::ofName('testField')->setValue($newValue)) |
| 163 | + ; |
| 164 | + $response = $request->executeWithClient($this->getClient()); |
| 165 | + $result = $request->mapResponse($response); |
| 166 | + $this->deleteRequest->setVersion($result->getVersion()); |
| 167 | + |
| 168 | + $this->assertSame($newValue, $result->getCustom()->getFields()->getTestField()); |
| 169 | + } |
| 170 | + |
| 171 | + |
123 | 172 | public function testChangeCartDiscountAction() |
124 | 173 | { |
125 | 174 | $draft = $this->getDraft('change-cart-discount'); |
|
0 commit comments