Inheritance: extends CheckoutComponent
 public function getConstraints(Order $order, $form = null)
 {
     $required = parent::getRequiredFields($order);
     $constraints = [];
     $namespace = $this->name();
     foreach ($required as $requirement) {
         $constraints[$namespace . '_' . $requirement] = new RequiredIf($namespace . '_' . $this->addresstype . 'ToSameAddress', 'not(:checked)');
     }
     return $constraints;
 }
 public function getConstraints(Order $order, $form = null)
 {
     $member = Member::currentUser() ?: $order->Member();
     if (!$member || !$member->exists() || !$member->AddressBook()->exists()) {
         return [];
     }
     $required = parent::getRequiredFields($order);
     $constraints = [];
     $namespace = $this->name();
     foreach ($member->AddressBook() as $address) {
         foreach ($required as $requirement) {
             $constraints[$namespace . '_address-' . $address->ID . '[' . $requirement . ']'] = (new RequiredIfStrict($namespace . '_Use', '[value=address-' . $address->ID . ']:checked'))->setMessage(_t('AlternateAddressBookCheckoutComponent.' . $this->addresstype . '-REQUIRED_IF', 'This value is required when ' . strtolower($this->addresstype) . ' to: {address}', ['address' => $address->toString()]));
         }
     }
     if ($this->allowNew) {
         foreach ($required as $requirement) {
             $constraints[$namespace . '_new[' . $requirement . ']'] = (new RequiredIfStrict($namespace . '_Use', '[value=new]:checked'))->setMessage(_t('AlternateAddressBookCheckoutComponent.' . $this->addresstype . '-REQUIRED_IF_NEW', 'This value is required when ' . strtolower($this->addresstype) . ' to a new address'));
         }
     }
     return $constraints;
 }
コード例 #3
0
 /**
  * Create a new address if the existing address has changed, or is not yet
  * created.
  *
  * @param Order $order order to get addresses from
  * @param array $data  data to set
  */
 public function setData(Order $order, array $data)
 {
     $existingID = !empty($data[$this->addresstype . "AddressID"]) ? (int) $data[$this->addresstype . "AddressID"] : 0;
     if ($existingID > 0) {
         $order->{$this->addresstype . "AddressID"} = $existingID;
         $order->write();
         $order->extend('onSet' . $this->addresstype . 'Address', $address);
     } else {
         parent::setData($order, $data);
     }
 }