-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from FosterCommerce/address-fields
Shipping address fields and forms
- Loading branch information
Showing
15 changed files
with
1,340 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ includes: | |
- vendor/craftcms/phpstan/phpstan.neon | ||
|
||
parameters: | ||
scanFiles: | ||
- phpstan_stubs.php | ||
paths: | ||
- src | ||
level: 5 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
$class = glob('storage/runtime/compiled_classes/CustomFieldBehavior*.php')[0]??null; | ||
if ($class !== null) { | ||
copy($class, 'phpstan_stubs.php'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace fostercommerce\craftfostercheckout\formatters; | ||
|
||
use CommerceGuys\Addressing\AddressInterface; | ||
use Craft; | ||
use craft\elements\Address; | ||
|
||
class CheckoutAddressFormatter extends \CommerceGuys\Addressing\Formatter\DefaultFormatter | ||
{ | ||
public function format(AddressInterface $address, array $options = []): string | ||
{ | ||
/** @var Address $address */ | ||
if (property_exists($address, 'firstName')) { | ||
$address->firstName = null; | ||
} | ||
if (property_exists($address, 'lastName')) { | ||
$address->lastName = null; | ||
} | ||
|
||
// if the address is in the US then get the State name, otherwise use the inputted value | ||
//$state = $address->countryCode == 'US' ? Craft::$app->getAddresses()->subdivisionRepository->get($address->administrativeArea, [$address->countryCode])->getName() : $address->administrativeArea; | ||
|
||
$addressLines[] = $address->addressLine1; | ||
$addressLines[] = $address->addressLine2; | ||
$addressLines[] = $address->addressLine3; | ||
$addressLines[] = $address->locality; | ||
$addressLines[] = $address->dependentLocality; | ||
$addressLines[] = $address->administrativeArea; | ||
$addressLines[] = $address->postalCode; | ||
$addressLines[] = $address->getCountry()->getName(); | ||
|
||
return ($address->fullName ? $address->fullName . '<br />' : '') . implode(' / ', array_filter($addressLines)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% set address = address ?? null %} | ||
{% if address %} | ||
{% set addressService = craft.app.getAddresses() %} | ||
{% set customFormatter = create( | ||
'fostercommerce\\craftfostercheckout\\formatters\\CheckoutAddressFormatter', | ||
[ | ||
addressService.getAddressFormatRepository(), | ||
addressService.getCountryRepository(), | ||
addressService.getSubdivisionRepository(), | ||
] | ||
) %} | ||
{{ address|address({ }, customFormatter) }} | ||
{% else %} | ||
No address to display | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.