AddressBookCheckoutComponent::validateData PHP Метод

validateData() публичный Метод

public validateData ( Order $order, array $data )
$order Order
$data array
    public function validateData(Order $order, array $data)
    {
        $result = ValidationResult::create();
        $existingID = !empty($data[$this->addresstype . "AddressID"]) ? (int) $data[$this->addresstype . "AddressID"] : 0;
        if ($existingID) {
            // If existing address selected, check that it exists in $member->AddressBook
            if (!Member::currentUserID() || !Member::currentUser()->AddressBook()->byID($existingID)) {
                $result->error("Invalid address supplied", $this->addresstype . "AddressID");
                throw new ValidationException($result);
            }
        } else {
            // Otherwise, require the normal address fields
            $required = parent::getRequiredFields($order);
            $addressLabels = singleton('Address')->fieldLabels(false);
            foreach ($required as $fieldName) {
                if (empty($data[$fieldName])) {
                    // attempt to get the translated field name
                    $fieldLabel = isset($addressLabels[$fieldName]) ? $addressLabels[$fieldName] : $fieldName;
                    $errorMessage = _t('Form.FIELDISREQUIRED', '{name} is required', array('name' => $fieldLabel));
                    $result->error($errorMessage, $fieldName);
                    throw new ValidationException($result);
                }
            }
        }
    }