Skip to content

Commit 3fd9675

Browse files
authored
Some fixes for the pricing info
1 parent b85c101 commit 3fd9675

File tree

1 file changed

+14
-4
lines changed
  • en/01_Commerce/v1/75_Developer/03_Products

1 file changed

+14
-4
lines changed

en/01_Commerce/v1/75_Developer/03_Products/Pricing.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ Other notable methods on the `ProductPricing` object:
276276
- `getRegularPrice() : PriceInterface`
277277
- `addPriceType(PriceTypeInterface $priceType) : void`
278278

279-
## Updating product pricing programmatically
279+
## Adding price types programmatically
280280

281281
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:
282282

@@ -347,11 +347,11 @@ $pricing->addPriceType(
347347
```
348348

349349

350-
## Removing a PriceType from a Pricing instance
350+
## Updating or removing price types
351351

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.
353353

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.
355355

356356
```php
357357
$currency = $commerce->getCurrency('EUR');
@@ -370,6 +370,16 @@ foreach ($currentPricing->getPriceTypes() as $priceType) {
370370
$product->savePricing($newPricing);
371371
```
372372

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+
373383
## Loading Price Types in a custom product
374384

375385
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

Comments
 (0)