Skip to content

Commit

Permalink
Adding missing postal_fee_id to payment_items, edge case handling
Browse files Browse the repository at this point in the history
* Postal fee ID was not added in the products initial migration
as product ID was. This migration is adding it in case it's still
missing.
* Because not all columns could be available by default in payments
form, product-related columns were conditioned and accessed only
if they're present. This is a temporary solution as the whole
form is planned to be rewritten to comply with dataproviders and
flow where external modules can extend it.

remp/crm#1118
  • Loading branch information
rootpd committed Mar 16, 2020
1 parent 6b6e629 commit bb83682
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/forms/PaymentFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,21 @@ public function create($paymentId, IRow $user = null)
$defaults = $payment->toArray();
$items = [];
foreach ($payment->related('payment_items')->fetchAll() as $item) {
$items[] = [
$item = [
'amount' => $item->amount,
'count' => $item->count,
'name' => $item->name,
'vat' => $item->vat,
'type' => $item->type,
'postal_fee_id' => $item->postal_fee_id,
'product_id' => $item->product_id,
];
// TODO: temporary solution until whole form is refactored and fields handled by dataproviders
if (array_key_exists('postal_fee_idx', $item)) {
$item['postal_fee_idx'] = $item->postal_fee_id;
}
if (array_key_exists('product_idx', $item)) {
$item['product_idx'] = $item->product_id;
}
$items[] = $item;
}
$defaults['payment_items'] = Json::encode($items);

Expand Down

0 comments on commit bb83682

Please sign in to comment.