Skip to content

Commit

Permalink
Merge branch 'develop' into 4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
nfourtythree committed Jul 5, 2023
2 parents 415f206 + 082cc2f commit a2e4754
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 45 deletions.
26 changes: 26 additions & 0 deletions example-templates/dist/shop/_private/address/fields.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{#
Outputs address form fields for editing an address.
#}
{% set showPrimaryCheckboxes = showPrimaryCheckboxes is defined ? showPrimaryCheckboxes : false %}
{% set addressFieldLayout = craft.app.getAddresses().getLayout() %}
{% set addressCustomFields = addressFieldLayout.getCustomFields()|filter(f => className(f) == 'craft\\fields\\PlainText') %}
{# @var address \craft\elements\Address #}
Expand Down Expand Up @@ -193,9 +194,34 @@ Outputs address form fields for editing an address.
{% endfor %}
</div>
{% endif %}

{% if showPrimaryCheckboxes %}
<hr class="my-2">
<div class="my-2">
{{ input('text', 'isPrimaryBilling', address.isPrimarybilling ? 1 : 0) }}
<label>{{ input('checkbox', 'isPrimaryBillingBox', 1, { checked: address.isPrimaryBilling, 'data-primary-input': 'isPrimaryBilling' }) }} {{ 'Use as the primary billing address'|t('commerce') }}</label>
</div>
<div class="my-2">
{{ input('text', 'isPrimaryShipping', address.isPrimaryShipping ? 1 : 0) }}
<label>{{ input('checkbox', 'isPrimaryShippingBox', 1, { checked: address.isPrimaryShipping, 'data-primary-input': 'isPrimaryShipping' }) }} {{ 'Use as the primary shipping address'|t('commerce') }}</label>
</div>
{% endif %}
</div>

{% js %}
{% if showPrimaryCheckboxes %}
document.querySelectorAll('input[type=checkbox][data-primary-input]').forEach(el => {
el.addEventListener('change', ev => {
let primaryInput = document.querySelector(`input[name="${ev.target.dataset.primaryInput}"]`);
if (ev.target.checked) {
primaryInput.value = 1;
} else {
primaryInput.value = 0;
}
});
});
{% endif %}

document.querySelector('select#{{ 'countryCode'|namespaceInputId(addressName) }}').addEventListener('change', ev => {
const countryCode = ev.target.value;
const stateSelect = document.querySelector('select#{{ 'administrativeArea'|namespaceInputId(addressName) }}');
Expand Down
44 changes: 22 additions & 22 deletions example-templates/dist/shop/checkout/addresses.twig
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ Outputs a form for collecting an order’s shipping and billing address.
sourceIdName: 'sourceShippingAddressId',
}) }}

{% if currentUser and addresses|length %}
<div class="mt-3">
<label>
{{ input('checkbox', 'makePrimaryShippingAddress', 1, {
id: 'makePrimaryShippingAddress',
}) }}
{{ 'Make this my default shipping address'|t }}
</label>
</div>
{% endif %}

<hr class="my-5">

{{ hiddenInput('billingAddressSameAsShipping', 0) }}
Expand All @@ -57,17 +68,6 @@ Outputs a form for collecting an order’s shipping and billing address.
</label>
</div>

{% if currentUser %}
<div class="mt-3">
<label>
{{ input('checkbox', 'makePrimaryShippingAddress', 1, {
id: 'makePrimaryShippingAddress',
}) }}
{{ 'Make this my default shipping address'|t }}
</label>
</div>
{% endif %}

<div class="mt-8">
{{ include('shop/_private/address/fieldset', {
title: 'Billing Address'|t,
Expand All @@ -78,19 +78,19 @@ Outputs a form for collecting an order’s shipping and billing address.
}) }}
</div>

<hr class="my-5">

{% if currentUser %}
<div class="mt-3">
<label>
{{ input('checkbox', 'makePrimaryBillingAddress', 1, {
id: 'makePrimaryBillingAddress',
}) }}
{{ 'Make this my default billing address'|t }}
</label>
</div>
{% if currentUser and addresses|length %}
<div class="mt-3">
<label>
{{ input('checkbox', 'makePrimaryBillingAddress', 1, {
id: 'makePrimaryBillingAddress',
}) }}
{{ 'Make this my default billing address'|t }}
</label>
</div>
{% endif %}

<hr class="my-5">

<div class="mt-3 flex justify-end">
{{ tag('button', {
type: 'submit',
Expand Down
1 change: 1 addition & 0 deletions example-templates/dist/shop/customer/addresses/edit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
{{ include('shop/_private/address/fields', {
address: address,
showLabelField: true,
showPrimaryCheckboxes: true,
}) }}
{{ hiddenInput('ownerId', currentUser.id) }}

Expand Down
26 changes: 26 additions & 0 deletions example-templates/src/shop/_private/address/fields.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{#
Outputs address form fields for editing an address.
#}
{% set showPrimaryCheckboxes = showPrimaryCheckboxes is defined ? showPrimaryCheckboxes : false %}
{% set addressFieldLayout = craft.app.getAddresses().getLayout() %}
{% set addressCustomFields = addressFieldLayout.getCustomFields()|filter(f => className(f) == 'craft\\fields\\PlainText') %}
{# @var address \craft\elements\Address #}
Expand Down Expand Up @@ -193,9 +194,34 @@ Outputs address form fields for editing an address.
{% endfor %}
</div>
{% endif %}

{% if showPrimaryCheckboxes %}
<hr class="my-2">
<div class="my-2">
{{ input('text', 'isPrimaryBilling', address.isPrimarybilling ? 1 : 0) }}
<label>{{ input('checkbox', 'isPrimaryBillingBox', 1, { checked: address.isPrimaryBilling, 'data-primary-input': 'isPrimaryBilling' }) }} {{ 'Use as the primary billing address'|t('commerce') }}</label>
</div>
<div class="my-2">
{{ input('text', 'isPrimaryShipping', address.isPrimaryShipping ? 1 : 0) }}
<label>{{ input('checkbox', 'isPrimaryShippingBox', 1, { checked: address.isPrimaryShipping, 'data-primary-input': 'isPrimaryShipping' }) }} {{ 'Use as the primary shipping address'|t('commerce') }}</label>
</div>
{% endif %}
</div>

{% js %}
{% if showPrimaryCheckboxes %}
document.querySelectorAll('input[type=checkbox][data-primary-input]').forEach(el => {
el.addEventListener('change', ev => {
let primaryInput = document.querySelector(`input[name="${ev.target.dataset.primaryInput}"]`);
if (ev.target.checked) {
primaryInput.value = 1;
} else {
primaryInput.value = 0;
}
});
});
{% endif %}

document.querySelector('select#{{ 'countryCode'|namespaceInputId(addressName) }}').addEventListener('change', ev => {
const countryCode = ev.target.value;
const stateSelect = document.querySelector('select#{{ 'administrativeArea'|namespaceInputId(addressName) }}');
Expand Down
44 changes: 22 additions & 22 deletions example-templates/src/shop/checkout/addresses.twig
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ Outputs a form for collecting an order’s shipping and billing address.
sourceIdName: 'sourceShippingAddressId',
}) }}

{% if currentUser and addresses|length %}
<div class="mt-3">
<label>
{{ input('checkbox', 'makePrimaryShippingAddress', 1, {
id: 'makePrimaryShippingAddress',
}) }}
{{ 'Make this my default shipping address'|t }}
</label>
</div>
{% endif %}

<hr class="my-5">

{{ hiddenInput('billingAddressSameAsShipping', 0) }}
Expand All @@ -57,17 +68,6 @@ Outputs a form for collecting an order’s shipping and billing address.
</label>
</div>

{% if currentUser %}
<div class="mt-3">
<label>
{{ input('checkbox', 'makePrimaryShippingAddress', 1, {
id: 'makePrimaryShippingAddress',
}) }}
{{ 'Make this my default shipping address'|t }}
</label>
</div>
{% endif %}

<div class="mt-8">
{{ include('[[folderName]]/_private/address/fieldset', {
title: 'Billing Address'|t,
Expand All @@ -78,19 +78,19 @@ Outputs a form for collecting an order’s shipping and billing address.
}) }}
</div>

<hr class="my-5">

{% if currentUser %}
<div class="mt-3">
<label>
{{ input('checkbox', 'makePrimaryBillingAddress', 1, {
id: 'makePrimaryBillingAddress',
}) }}
{{ 'Make this my default billing address'|t }}
</label>
</div>
{% if currentUser and addresses|length %}
<div class="mt-3">
<label>
{{ input('checkbox', 'makePrimaryBillingAddress', 1, {
id: 'makePrimaryBillingAddress',
}) }}
{{ 'Make this my default billing address'|t }}
</label>
</div>
{% endif %}

<hr class="my-5">

<div class="mt-3 flex justify-end">
{{ tag('button', {
type: 'submit',
Expand Down
1 change: 1 addition & 0 deletions example-templates/src/shop/customer/addresses/edit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
{{ include('[[folderName]]/_private/address/fields', {
address: address,
showLabelField: true,
showPrimaryCheckboxes: true,
}) }}
{{ hiddenInput('ownerId', currentUser.id) }}

Expand Down
2 changes: 1 addition & 1 deletion src/services/PaymentSources.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function createPaymentSource(int $customerId, GatewayInterface $gateway,
throw new PaymentSourceException(Craft::t('commerce', 'Could not create the payment source.'));
}

if($makePrimarySource) {
if ($makePrimarySource) {
Plugin::getInstance()->getCustomers()->savePrimaryPaymentSourceId($source->getCustomer(), $source->id);
}

Expand Down

0 comments on commit a2e4754

Please sign in to comment.