PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk All 48 releases
← All changes | api/Resource/ProductVariationResource.php +43 -22 1.3.20 → 1.6.5 View file →
@@ -64,12 +64,14 @@
64 64 * $data = [
65 65 * 'id' => (int) Required. The variant ID.
66 66 * 'post_id' => (int) Required. The product ID.
67 67 * 'variant_title' => (string) Required. The variant title.
68 - * 'item_price' => (float) Required. The item price.
69 - * 'compare_price' => (float) Required. The compare price.
68 + * 'item_price' => (int) Required. The item price in CENTS — e.g. 129900 means
69 + * $1,299.00. Same unit the API returns on read, and the same
70 + * unit stored. See dev-docs/PRICING-AND-TAX.md §6.
71 + * 'compare_price' => (int) Required. The compare price, in cents (see item_price).
70 72 * 'manage_cost' => (string) Optional. Whether to manage costs.
71 - * 'item_cost' => (float) Required if manage cost is yes. The item cost.
73 + * 'item_cost' => (int) Required if manage cost is yes. The item cost, in cents.
72 74 * 'manage_stock' => (string) Required. Whether to manage stock.
73 75 * 'stock_status' => (string) Required. The stock status.
74 76 * 'stock' => (int) Required. The stock quantity.
75 77 * 'media' => (array) Optional. Info of media files for each variant.
@@ -79,9 +81,9 @@
79 81 * 'other_info' => (array) Optional. Other information for the variant.
80 82 * 'payment_type' => (string) Required. The payment type.
81 83 * 'times' => (string) Required. The number of times.
82 84 * 'repeat_interval' => (string) Required. The repeat interval unit.
83 - * 'signup_fee' => (string) Required. The signup fee.
85 + * 'signup_fee' => (int) Required. The signup fee, in cents (see item_price).
84 86 * 'downloadable_files' => (array) Required if downloadable is true.
85 87 * 'download_limit' => (string) Required. The download limit.
86 88 * 'download_expiry' => (string) Required. The download expiry.
87 89 * 'downloadable' => (bool) Optional. Whether the product is downloadable.
@@ -95,13 +97,19 @@
95 97 * ];
96 98 */
97 99 public static function create($variant, $params = [])
98 100 {
99 - $otherInfo = Arr::get($variant, 'other_info');
101 + $otherInfo = Arr::wrap(Arr::get($variant, 'other_info'));
102 + $otherInfo['tax_exempt'] = Arr::get($otherInfo, 'tax_exempt', 'no');
103 + $otherInfo['tax_class'] = Arr::get($otherInfo, 'tax_class', 'standard');
104 +
100 105 if (Arr::get($otherInfo, 'payment_type') == 'onetime') {
101 106 $otherInfo = Arr::only($otherInfo, [
102 107 'payment_type',
103 108 'description',
109 + 'tax_class',
110 + 'tax_exempt',
111 + 'tax_inclusion',
104 112 'package_slug',
105 113 'weight',
106 114 'weight_unit',
107 115 'length',
@@ -115,9 +123,10 @@
115 123 unset($otherInfo['signup_fee']);
116 124 unset($otherInfo['setup_fee_per_item']);
117 125 }
118 126 if (Arr::get($otherInfo, 'manage_setup_fee') == 'yes') {
119 - $signupFee = Helper::toCent(floatval(Arr::get($otherInfo, 'signup_fee', 0)));
127 + // Already in cents — normalize only, do not scale.
128 + $signupFee = Helper::roundCent(Arr::get($otherInfo, 'signup_fee', 0));
120 129 Arr::set($otherInfo, 'signup_fee', $signupFee);
121 130 }
122 131 }
123 132
@@ -147,22 +156,28 @@
147 156 'available' => Arr::get($variant, 'available'),
148 157 'committed' => Arr::get($variant, 'committed'),
149 158 'on_hold' => Arr::get($variant, 'on_hold'),
150 159 'stock_status' => $stockStatus,
151 - 'item_price' => Helper::toCent($itemPrice),
152 - //'compare_price' => ($comparePrice !== '' && $comparePrice >= $itemPrice) ? Helper::toCent($comparePrice) : Helper::toCent($itemPrice),
153 - 'compare_price' => ($comparePrice !== '' && $comparePrice >= $itemPrice) ? Helper::toCent($comparePrice) : 0,
154 - 'item_cost' => Helper::toCent(Arr::get($variant, 'item_cost', 0)),
160 + // Amounts arrive already in CENTS. roundCent() only normalizes float
161 + // artifacts (a client-computed 19.99 * 100 arriving as
162 + // 1998.9999999999998) to a whole-cent int — it does not scale.
163 + 'item_price' => Helper::roundCent($itemPrice),
164 + 'compare_price' => ($comparePrice !== '' && $comparePrice >= $itemPrice) ? Helper::roundCent($comparePrice) : 0,
165 + 'item_cost' => Helper::roundCent(Arr::get($variant, 'item_cost', 0)),
155 166 'manage_cost' => Arr::get($variant, 'manage_cost', 'false'),
156 167 'fulfillment_type' => Arr::get($variant, 'fulfillment_type', 'physical'),
157 168 'shipping_class' => Arr::get($variant, 'shipping_class') ?: null,
158 169 'variation_title' => Arr::get($variant, 'variation_title', ''),
159 - 'sku' => Arr::get($variant, 'sku') ?: null,
160 170 'other_info' => $otherInfo,
161 171 'downloadable' => $isDownloadable,
162 172 'payment_type' => $hasSubscription ? 'subscription' : 'onetime',
163 173 ];
164 174
175 + $sku = Arr::get($variant, 'sku');
176 + if (!empty($sku)) {
177 + $variantData['sku'] = $sku;
178 + }
179 +
165 180 $isCreated = static::getQuery()->create($variantData);
166 181 if ($isCreated) {
167 182 ProductDetailResource::update(
168 183 [],
@@ -191,12 +206,14 @@
191 206 * $variant = [
192 207 * 'id' => (int) Required. The variant ID.
193 208 * 'post_id' => (int) Required. The product ID.
194 209 * 'variant_title' => (string) Required. The variant title.
195 - * 'item_price' => (float) Required. The item price.
196 - * 'compare_price' => (float) Required. The compare price.
210 + * 'item_price' => (int) Required. The item price in CENTS — e.g. 129900 means
211 + * $1,299.00. Same unit the API returns on read, and the same
212 + * unit stored. See dev-docs/PRICING-AND-TAX.md §6.
213 + * 'compare_price' => (int) Required. The compare price, in cents (see item_price).
197 214 * 'manage_cost' => (string) Optional. Whether to manage costs.
198 - * 'item_cost' => (float) Required if manage cost is yes. The item cost.
215 + * 'item_cost' => (int) Required if manage cost is yes. The item cost, in cents.
199 216 * 'manage_stock' => (string) Required. Whether to manage stock.
200 217 * 'stock_status' => (string) Required. The stock status.
201 218 * 'stock' => (int) Required. The stock quantity.
202 219 * 'media' => (array) Optional. Info of media files for each variant.
@@ -206,9 +223,9 @@
206 223 * 'other_info' => (array) Optional. Other information for the variant.
207 224 * 'payment_type' => (string) Required. The payment type.
208 225 * 'times' => (string) Required. The number of times.
209 226 * 'repeat_interval' => (string) Required. The repeat interval unit.
210 - * 'signup_fee' => (string) Required. The signup fee.
227 + * 'signup_fee' => (int) Required. The signup fee, in cents (see item_price).
211 228 * 'downloadable_files' => (array) Required if downloadable is true.
212 229 * 'download_limit' => (string) Required. The download limit.
213 230 * 'download_expiry' => (string) Required. The download expiry.
214 231 * 'downloadable' => (bool) Optional. Whether the product is downloadable.
@@ -221,10 +238,8 @@
221 238 * 'serial' => (string) Required if files. The file serial
222 239 * 'product_terms' => (array) Optional. Terms of the product.
223 240 * 'product-categories' => (array) Required if categories. Product categories.
224 241 * [0] => (int) Optional. The category ID.
225 - * 'product-tags' => (array) Required if tags. Product tags.
226 - * [0] => (int) Optional. The tag ID.
227 242 * 'product-types' => (array) Required if types. Product types.
228 243 * [0] => (int) Optional. The type ID.
229 244 * ];
230 245 */
@@ -242,8 +257,11 @@
242 257 if (Arr::get($otherInfo, 'payment_type') == 'onetime') {
243 258 $otherInfo = Arr::only($otherInfo, [
244 259 'payment_type',
245 260 'description',
261 + 'tax_class',
262 + 'tax_exempt',
263 + 'tax_inclusion',
246 264 'bundle_child_ids',
247 265 'package_slug',
248 266 'weight',
249 267 'weight_unit',
@@ -258,9 +276,10 @@
258 276 unset($otherInfo['signup_fee']);
259 277 unset($otherInfo['setup_fee_per_item']);
260 278 }
261 279 if (Arr::get($otherInfo, 'manage_setup_fee') == 'yes') {
262 - $signupFee = Helper::toCent(floatval(Arr::get($otherInfo, 'signup_fee', 0)));
280 + // Already in cents — normalize only, do not scale.
281 + $signupFee = Helper::roundCent(Arr::get($otherInfo, 'signup_fee', 0));
263 282 Arr::set($otherInfo, 'signup_fee', $signupFee);
264 283 }
265 284 }
266 285
@@ -297,12 +316,14 @@
297 316 'committed' => Arr::get($variant, 'committed'),
298 317 'on_hold' => Arr::get($variant, 'on_hold'),
299 318 'shipping_class' => Arr::get($variant, 'shipping_class') ?: null,
300 319 'stock_status' => $stockStatus,
301 - 'item_price' => Helper::toCent($itemPrice),
302 - //'compare_price' => ($comparePrice !== '' && $comparePrice >= $itemPrice) ? Helper::toCent($comparePrice) : Helper::toCent($itemPrice),
303 - 'compare_price' => ($comparePrice !== '' && $comparePrice >= $itemPrice) ? Helper::toCent($comparePrice) : 0,
304 - 'item_cost' => Helper::toCent(Arr::get($variant, 'item_cost', 0)),
320 + // Amounts arrive already in CENTS. roundCent() only normalizes float
321 + // artifacts (a client-computed 19.99 * 100 arriving as
322 + // 1998.9999999999998) to a whole-cent int — it does not scale.
323 + 'item_price' => Helper::roundCent($itemPrice),
324 + 'compare_price' => ($comparePrice !== '' && $comparePrice >= $itemPrice) ? Helper::roundCent($comparePrice) : 0,
325 + 'item_cost' => Helper::roundCent(Arr::get($variant, 'item_cost', 0)),
305 326 'manage_cost' => Arr::get($variant, 'manage_cost', 'false'),
306 327 'fulfillment_type' => Arr::get($variant, 'fulfillment_type', 'physical'),
307 328 'variation_title' => Arr::get($variant, 'variation_title', ''),
308 329 'sku' => Arr::get($variant, 'sku') ?: null,