Skip to content

Commit

Permalink
Make phone number optional during address validation. (#25)
Browse files Browse the repository at this point in the history
Co-authored-by: MykolaMalovanets <[email protected]>
  • Loading branch information
2 people authored and p-bystritsky committed Nov 16, 2023
1 parent 04ab747 commit 4d3eb6d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Checkout/Api/Platform/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public static function getCart(
}
try {
self::prepareStore($quote);
$quote->getShippingAddress()->setCollectShippingRates(true);
if (!$quote->getIsVirtual()) {
$quote->getShippingAddress()->setCollectShippingRates(true);
}
$quote->collectTotals();
$quoteData = Bold_Checkout_Service_Extractor_Quote::extract($quote);
} catch (Mage_Core_Model_Store_Exception $e) {
Expand Down Expand Up @@ -300,6 +302,7 @@ private static function updateAddress(
$address->setLastname($lastname);
$address->setSameAsBilling($sameAsBilling);
$address->setSaveInAddressBook($saveInAddressBook);
$address->setShouldIgnoreValidation(true);
}

/**
Expand Down Expand Up @@ -344,6 +347,10 @@ private static function prepareStore(Mage_Sales_Model_Quote $quote)
/** @var Mage_Customer_Model_Session $customerSession */
$customerSession = Mage::getSingleton('customer/session');
$customerSession->setCustomerId($quote->getCustomerId());
$quote->getBillingAddress()->setShouldIgnoreValidation(true);
if (!$quote->isVirtual()) {
$quote->getShippingAddress()->setShouldIgnoreValidation(true);
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions Checkout/Api/Platform/Customer/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public static function validate(
$payload = json_decode($request->getRawBody());
$addressData = isset($payload->address) ? $payload->address : new stdClass();
$address = Bold_Checkout_Service_Customer_Address_Convertor::getAddress($addressData);
if (!$address->getTelephone()) {
$address->setTelephone('0000000000');// Set a default phone number placeholder if none is provided.
}
$validationResult = $address->validate();
if ($validationResult === true) {
return Bold_Checkout_Rest::buildResponse($response, json_encode(
Expand Down
4 changes: 3 additions & 1 deletion Checkout/Api/Platform/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ private static function getCustomer(stdClass $customerData)
$customer->setFirstname($firstname);
$customer->setLastname($lastname);
foreach ($addresses as $address) {
$customer->addAddress(Bold_Checkout_Service_Customer_Address_Convertor::getAddress($address));
$customerAddress = Bold_Checkout_Service_Customer_Address_Convertor::getAddress($address);
$customerAddress->setShouldIgnoreValidation(true);
$customer->addAddress($customerAddress);
}
return $customer;
}
Expand Down

0 comments on commit 4d3eb6d

Please sign in to comment.