findologic / libflexport

FINDOLOGIC export toolkit for XML and CSV data export
MIT License
4 stars 5 forks source link

Allow getting price if no price is assigned yet #129

Closed TheKeymaster closed 4 years ago

TheKeymaster commented 4 years ago

Purpose

In case you have variants and each variant can have it's own price, you do not know if the final product has a price. Therefore you may want to call Item::getPrice, but you will be greeted with a nice exception, since the getter does not allow nullables.

Code Example:

$item = $this->exporter->createItem('123');

// . . . Some variant logic to get prices . . .

// Let's check if the price is set
if (!$item->getPrice()) {
    // OK, item has no price, lets not export it...
}

// . . .

Shows following error:

Return value of FINDOLOGIC\Export\Data\Item::getPrice() must be an instance of FINDOLOGIC\Export\Data\Price, null returned

Approach

Make that getter nullable, so you can check if a price is actually set or not

Open Questions and Pre-Merge TODOs

TheKeymaster commented 4 years ago

@howard closing this PR, as the user of the library should be responsible for knowing if a price was already set.