From 412aa438397a060359e25833dfa7a13e1d504495 Mon Sep 17 00:00:00 2001 From: Marcus Aschan Date: Fri, 18 Jan 2019 11:07:05 +0200 Subject: [PATCH] remove custom field handles from pmt_row_desc, add validation and filtering for pmt_userlanguage --- src/models/PaymentRequest.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/models/PaymentRequest.php b/src/models/PaymentRequest.php index 0d36f6d..5117c5e 100644 --- a/src/models/PaymentRequest.php +++ b/src/models/PaymentRequest.php @@ -58,6 +58,7 @@ public function rules() $rules = parent::rules(); $rules[] = [['pmt_buyeremail', 'pmt_buyername', 'pmt_buyeraddress', 'pmt_buyerpostalcode', 'pmt_buyercity'], 'required']; $rules[] = [['pmt_deliveryname', 'pmt_deliveryaddress', 'pmt_deliverypostalcode', 'pmt_deliverycity'], 'required']; + $rules[] = ['pmt_userlocale', 'filter', 'filter' => [$this, 'filterUserLocale']]; return $rules; } @@ -82,6 +83,24 @@ public function getAttributes($names = null, $except = []) return $values; } + /** + * Filter pmt_userlocale + * Return a default launguage string if value is not among allowed languages + * + * @param string $value + * @return string $value + */ + public function filterUserLocale($value) + { + $allowed = ['fi_FI', 'sv_FI', 'en_FI']; + + if (in_array($value, $allowed)) { + return $value; + } + + return 'en_FI'; + } + /** * Set attributes from PaymentForm * @@ -194,13 +213,11 @@ private function populatelineItems(array $lineItems) */ private function populatelineItem(LineItem $lineItem) { - $product = $lineItem->snapshot['product']; - $row = [ 'pmt_row_name' => $lineItem->description, - 'pmt_row_desc' => $product['description'] ? $product['description'] : ' ', + 'pmt_row_desc' => $lineItem->description, 'pmt_row_quantity' => $lineItem->qty, - 'pmt_row_deliverydate' => $product['days']->one()->startDate->format('d.m.Y'), + 'pmt_row_deliverydate' => date('d.m.Y'), 'pmt_row_price_net' => number_format($lineItem->price, 2, ',', ''), 'pmt_row_vat' => $this->getLineItemTax($lineItem), 'pmt_row_discountpercentage' => '0,00',