Child pages
  • [in-commerce] Improve kCCDateFormatter [5.2.1-RC1]
Skip to end of metadata
Go to start of metadata

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:

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:

  1. the "month_field" and "year_field" are being submitted from the form
  2. formatter is attached only to "PaymentCCExpDate" field
  3. 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:

  1. set the formatter on month/year fields, but do nothing
  2. the kDBItem::UpdateFormattersMasterFields method is called already before validation happens and combines both fields into one

Related Tasks