/
[in-commerce] Improve kCCDateFormatter [5.2.1-RC1]
[in-commerce] Improve kCCDateFormatter [5.2.1-RC1]
Right now the field, used to store credit card expiration date is using kCCDateFormatter
. It appears that there is a bug in the formatter class and following code was added to OrdersItem
class to overcome this:
orders_item.php
public function SetFieldsFromHash($hash, $skip_fields = Array (), $set_fields = Array ()) { parent::SetFieldsFromHash($hash, $skip_fields, $set_fields); $options = $this->GetFieldOptions('PaymentCCExpDate'); if ( $this->GetDirtyField($options['month_field']) || $this->GetDirtyField($options['year_field']) ) { $this->SetDirtyField('PaymentCCExpDate', 0); $this->SetField('PaymentCCExpDate', 0); } }
Here is what happens:
- the "month_field" and "year_field" are being submitted from the form
- formatter is attached only to "PaymentCCExpDate" field
- to trigger a formatter we're actually looking for these 2 fields and triggering fake value change for a "PaymentCCExpDate" field to notify formatter
To solve it we need use idea from kDateFormatter
class:
- set the formatter on month/year fields, but do nothing
- the
kDBItem::UpdateFormattersMasterFields
method is called already before validation happens and combines both fields into one