You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you're looking to import product prices, you'll need to interact with the classes mentioned in this document to make that work. The rough workflow would look like this:
282
282
@@ -347,11 +347,11 @@ $pricing->addPriceType(
347
347
```
348
348
349
349
350
-
## Removing a PriceType from a Pricing instance
350
+
## Updating or removing price types
351
351
352
-
It's not natively possible to remove a PriceType directly, as it does not have an ID or another unique key to target them by.
352
+
It's not natively possible to update, remove or replace a PriceType directly, as it does not have an ID or another unique key to target them by.
353
353
354
-
If you programmatically want to remove a PriceType, create a new ProductPricing input, add the PriceType's you want to keep, and save that to the product.
354
+
To programmatically update/remove/replace a PriceType, create a new (empty) ProductPricing instance, add the PriceType's you want to keep, and save that to the product.
355
355
356
356
```php
357
357
$currency = $commerce->getCurrency('EUR');
@@ -370,6 +370,16 @@ foreach ($currentPricing->getPriceTypes() as $priceType) {
370
370
$product->savePricing($newPricing);
371
371
```
372
372
373
+
If you want to find a specific price type, you can use instanceof to test the price type inside the `foreach` loop. For example to only keep a Sale price type:
374
+
375
+
```php
376
+
foreach ($currentPricing->getPriceTypes() as $priceType) {
377
+
if ($priceType instanceof \modmore\Commerce\Pricing\PriceType\Sale) {
378
+
$newPricing->addPriceType($priceType);
379
+
}
380
+
}
381
+
```
382
+
373
383
## Loading Price Types in a custom product
374
384
375
385
Prior to 1.0, you would override `getPrice` and return a simple price object. That has been deprecated and will be removed in 1.3.
0 commit comments