Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:craftcms/commerce into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
lukeholder committed Jun 16, 2023
2 parents ef4d650 + 8d805dc commit c51f365
Show file tree
Hide file tree
Showing 19 changed files with 556 additions and 122 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
branches:
- develop
- v3
- '4.2'
pull_request:
permissions:
contents: read
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

## Unreleased

- Fixed a bug where `hasMatchingAddresses()` was incorrectly returning `false`. ([#3183](https://github.com/craftcms/commerce/issues/3183))
- Fixed a bug where changing a user’s email would cause extra user elements to be created. ([#3138](https://github.com/craftcms/commerce/issues/3138))
- Fixed a bug where related sales were showing when creating a new product.
- Fixed a bug where Commerce wasn’t invoking `craft\services\Elements::EVENT_AUTHORIZE_*` event handlers.
- Fixed a bug where discounts’ per user usage counters weren’t getting migrated properly when upgrading to Commerce 4.
- Fixed a bug where address changes weren’t being synced to carts using them as a source. ([#3178](https://github.com/craftcms/commerce/issues/3178))
- Added `craft\commerce\services\Orders::afterSaveAddressHandler()`.
- Added `craft\commerce\elements\Order::$orderCompletedEmail`. ([#3138](https://github.com/craftcms/commerce/issues/3138))

## 4.2.11 - 2023-06-05

Expand Down
11 changes: 7 additions & 4 deletions example-templates/dist/shop/_private/address/fieldset.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Outputs a fieldset for selecting one of a user’s available addresses or creati
@var title string
@var currentUser \craft\elements\User
#}
{% set sourceAttribute = 'source' ~ (name|slice(0, 1)|capitalize) ~ (name|slice(1) ~ 'Id') %}
<div class="js-address-fieldset {{ classes }}">
<h2 class="text-lg font-bold mb-4">
{{- title -}}
Expand All @@ -19,22 +20,24 @@ Outputs a fieldset for selecting one of a user’s available addresses or creati
selectable: true,
primaryBillingAddressId: cart and cart.customer ? cart.customer.primaryBillingAddressId : null,
primaryShippingAddressId: cart and cart.customer ? cart.customer.primaryShippingAddressId : null,
showAdd: true,
}) }}

<div class="js-address-select">
<div class="js-address-select" data-model-name="{{ name }}">
{% if attribute(cart, name ~ 'Id') %}
{% set addressHasErrors = attribute(cart, name) and attribute(cart, name).hasErrors() %}
{% else %}
{% set addressHasErrors = false %}
{% endif %}

{% if currentUser %}
{# Show the custom toggle if there is a custom address on the order #}
{% if currentUser and cart and attribute(cart, name ~ 'Id') and not attribute(cart, sourceAttribute) %}
<div class="js-radio">
<label>
{{ input('radio', name ~ 'Id', '', {
checked: not addresses|length or addressHasErrors
checked: true
}) }}
{{ 'New {title}'|t({ title: title }) }}
{{ 'Custom {title}'|t({ title: title }) }}
</label>
</div>
{% endif %}
Expand Down
112 changes: 62 additions & 50 deletions example-templates/dist/shop/_private/address/list.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,73 @@
{% set primaryShippingAddressId = primaryShippingAddressId ?? null %}
{% set cardWidth = cardWidth ?? 'md:w-1/2' %}
{% set showDelete = showDelete ?? false %}
{% set showAdd = showAdd ?? false %}
{% set addUrl = '/shop/customer/addresses/edit?redirect=' ~ craft.app.request.fullPath %}

{% if addresses and currentUser %}
<div class="md:flex md:flex-wrap md:-mx-2 pb-4">
{% for address in addresses %}
{% set editUrl = '/shop/customer/addresses/edit?addressId=' ~ address.id ~ '&redirect=' ~ craft.app.request.fullPath %}
<div class="pb-2 my-4 md:px-2 {{ cardWidth }} md:my-0">
{% tag selectable ? 'label' : 'div' with {
class: 'block relative address-select js-address-select border-blue-300 border-b-2 px-6 py-4 rounded-md shadow-md hover:shadow-lg',
data: {
'address-id': address.id,
},
} %}
<span class="js-radio flex py-2">
{% if selectable %}
{{ input('radio', name ~ 'Id', address.id, {
checked: (attribute(cart, sourceIdName) == address.id) or (not attribute(cart, sourceIdName) and address.id == attribute(_context, primaryIdName)),
}) }}
{% endif %}
<span class="-mt-2 ml-3 mb-2">
{{ address|address }}
</span>
</span>
<span class="block mb-1">
<a href="{{ url(editUrl) }}" class="cursor-pointer rounded px-2 py-1 text-sm inline-block bg-gray-500 hover:bg-gray-600 text-white hover:text-white">
{{- 'Edit'|t -}}
</a>
{% if showDelete and not selectable %}
<form method="post" action="" class="js-address-delete inline-block">
{{ csrfInput() }}
{{ actionInput('users/delete-address') }}
{{ redirectInput('shop/customer/addresses') }}
{{ hiddenInput('addressId', address.id) }}
{{ tag('button', {
type: 'submit',
class: 'cursor-pointer rounded px-2 py-1 text-sm inline-block bg-gray-500 hover:bg-gray-600 text-white hover:text-white',
text: 'Delete'|t
{% if currentUser %}
{% if addresses|length %}
<div class="md:flex md:flex-wrap md:-mx-2 pb-4">
{% for address in addresses %}
{% set editUrl = '/shop/customer/addresses/edit?addressId=' ~ address.id ~ '&redirect=' ~ craft.app.request.fullPath %}
<div class="pb-2 my-4 md:px-2 {{ cardWidth }} md:my-0">
{% tag selectable ? 'label' : 'div' with {
class: 'block relative address-select js-address-select border-blue-300 border-b-2 px-6 py-4 rounded-md shadow-md hover:shadow-lg',
data: {
'address-id': address.id,
},
} %}
<span class="js-radio flex py-2">
{% if selectable %}
{{ input('radio', name ~ 'Id', address.id, {
data: {
'model-name': name,
},
checked: (attribute(cart, sourceIdName) == address.id) or (not attribute(cart, sourceIdName) and address.id == attribute(_context, primaryIdName)),
}) }}
</form>
{% endif %}
</span>

{% if primaryBillingAddressId == address.id or primaryShippingAddressId == address.id %}
<span class="absolute top-4 right-4">
{% if primaryBillingAddressId == address.id %}
<span title="{{ 'Primary billing address'|t }}">💳</span>
{% endif %}
{% if primaryShippingAddressId == address.id %}
<span title="{{ 'Primary shipping address'|t }}">📦</span>
<span class="-mt-2 ml-3 mb-2">
{{ address|address }}
</span>
</span>
<span class="block mb-1">
<a href="{{ url(editUrl) }}" class="cursor-pointer rounded px-2 py-1 text-sm inline-block bg-gray-500 hover:bg-gray-600 text-white hover:text-white">
{{- 'Edit'|t -}}
</a>
{% if showDelete and not selectable %}
<form method="post" action="" class="js-address-delete inline-block">
{{ csrfInput() }}
{{ actionInput('users/delete-address') }}
{{ redirectInput('shop/customer/addresses') }}
{{ hiddenInput('addressId', address.id) }}
{{ tag('button', {
type: 'submit',
class: 'cursor-pointer rounded px-2 py-1 text-sm inline-block bg-gray-500 hover:bg-gray-600 text-white hover:text-white',
text: 'Delete'|t
}) }}
</form>
{% endif %}
</span>
{% endif %}
{% endtag %}
</div>
{% endfor %}
</div>

{% if primaryBillingAddressId == address.id or primaryShippingAddressId == address.id %}
<span class="absolute top-4 right-4">
{% if primaryBillingAddressId == address.id %}
<span title="{{ 'Primary billing address'|t }}">💳</span>
{% endif %}
{% if primaryShippingAddressId == address.id %}
<span title="{{ 'Primary shipping address'|t }}">📦</span>
{% endif %}
</span>
{% endif %}
{% endtag %}
</div>
{% endfor %}
</div>
{% endif %}
{% if showAdd %}
<div class="pt-2">
<a href="{{ url(addUrl) }}" class="cursor-pointer rounded px-2 py-1 text-sm inline-block bg-blue-500 hover:bg-blue-600 text-white hover:text-white">{{ 'Add address'|t }}</a>
</div>
{% endif %}
{% endif %}

{% js %}
Expand Down
4 changes: 3 additions & 1 deletion example-templates/dist/shop/checkout/addresses.twig
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ Outputs a form for collecting an order’s shipping and billing address.
if ($body) {
// Creating new address
$radio.addEventListener('change', function(ev) {
console.log('changing');
if (ev.target.checked) {
$body.classList.remove('hidden');
} else {
Expand All @@ -136,6 +137,7 @@ Outputs a form for collecting an order’s shipping and billing address.
} else {
// Selecting existing address
$radio.addEventListener('change', function(ev) {
console.log(ev.target.checked);
if (ev.target.checked) {
var $newBox = document.querySelector('.js-address-select[data-model-name="' + ev.target.dataset.modelName + '"]');
if ($newBox) {
Expand All @@ -156,7 +158,7 @@ Outputs a form for collecting an order’s shipping and billing address.
var $billingFieldSet = document.querySelector('.js-address-fieldset.BillingAddress');
$billingFieldSet.classList.toggle('hidden');

for (let input of document.querySelector('.js-address-box.BillingAddress').querySelectorAll('input')) {
for (let input of $billingFieldSet.querySelectorAll('.js-address-select input')) {
if ($billingSameAs.checked === true) {
input.setAttribute('disabled', '');
} else if (input.hasAttribute('disabled')) {
Expand Down
11 changes: 7 additions & 4 deletions example-templates/src/shop/_private/address/fieldset.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Outputs a fieldset for selecting one of a user’s available addresses or creati
@var title string
@var currentUser \craft\elements\User
#}
{% set sourceAttribute = 'source' ~ (name|slice(0, 1)|capitalize) ~ (name|slice(1) ~ 'Id') %}
<div class="js-address-fieldset {{ classes }}">
<h2 class="text-lg font-bold mb-4">
{{- title -}}
Expand All @@ -19,22 +20,24 @@ Outputs a fieldset for selecting one of a user’s available addresses or creati
selectable: true,
primaryBillingAddressId: cart and cart.customer ? cart.customer.primaryBillingAddressId : null,
primaryShippingAddressId: cart and cart.customer ? cart.customer.primaryShippingAddressId : null,
showAdd: true,
}) }}

<div class="js-address-select">
<div class="js-address-select" data-model-name="{{ name }}">
{% if attribute(cart, name ~ 'Id') %}
{% set addressHasErrors = attribute(cart, name) and attribute(cart, name).hasErrors() %}
{% else %}
{% set addressHasErrors = false %}
{% endif %}

{% if currentUser %}
{# Show the custom toggle if there is a custom address on the order #}
{% if currentUser and cart and attribute(cart, name ~ 'Id') and not attribute(cart, sourceAttribute) %}
<div class="js-radio">
<label>
{{ input('radio', name ~ 'Id', '', {
checked: not addresses|length or addressHasErrors
checked: true
}) }}
{{ 'New {title}'|t({ title: title }) }}
{{ 'Custom {title}'|t({ title: title }) }}
</label>
</div>
{% endif %}
Expand Down
112 changes: 62 additions & 50 deletions example-templates/src/shop/_private/address/list.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,73 @@
{% set primaryShippingAddressId = primaryShippingAddressId ?? null %}
{% set cardWidth = cardWidth ?? 'md:w-1/2' %}
{% set showDelete = showDelete ?? false %}
{% set showAdd = showAdd ?? false %}
{% set addUrl = '/[[folderName]]/customer/addresses/edit?redirect=' ~ craft.app.request.fullPath %}

{% if addresses and currentUser %}
<div class="md:flex md:flex-wrap md:-mx-2 pb-4">
{% for address in addresses %}
{% set editUrl = '/[[folderName]]/customer/addresses/edit?addressId=' ~ address.id ~ '&redirect=' ~ craft.app.request.fullPath %}
<div class="pb-2 my-4 md:px-2 {{ cardWidth }} md:my-0">
{% tag selectable ? 'label' : 'div' with {
class: 'block relative address-select js-address-select [[classes.box.selection]]',
data: {
'address-id': address.id,
},
} %}
<span class="js-radio flex py-2">
{% if selectable %}
{{ input('radio', name ~ 'Id', address.id, {
checked: (attribute(cart, sourceIdName) == address.id) or (not attribute(cart, sourceIdName) and address.id == attribute(_context, primaryIdName)),
}) }}
{% endif %}
<span class="-mt-2 ml-3 mb-2">
{{ address|address }}
</span>
</span>
<span class="block mb-1">
<a href="{{ url(editUrl) }}" class="[[classes.btn.small]] [[classes.btn.grayColor]]">
{{- 'Edit'|t -}}
</a>
{% if showDelete and not selectable %}
<form method="post" action="" class="js-address-delete inline-block">
{{ csrfInput() }}
{{ actionInput('users/delete-address') }}
{{ redirectInput('[[folderName]]/customer/addresses') }}
{{ hiddenInput('addressId', address.id) }}
{{ tag('button', {
type: 'submit',
class: '[[classes.btn.small]] [[classes.btn.grayColor]]',
text: 'Delete'|t
{% if currentUser %}
{% if addresses|length %}
<div class="md:flex md:flex-wrap md:-mx-2 pb-4">
{% for address in addresses %}
{% set editUrl = '/[[folderName]]/customer/addresses/edit?addressId=' ~ address.id ~ '&redirect=' ~ craft.app.request.fullPath %}
<div class="pb-2 my-4 md:px-2 {{ cardWidth }} md:my-0">
{% tag selectable ? 'label' : 'div' with {
class: 'block relative address-select js-address-select [[classes.box.selection]]',
data: {
'address-id': address.id,
},
} %}
<span class="js-radio flex py-2">
{% if selectable %}
{{ input('radio', name ~ 'Id', address.id, {
data: {
'model-name': name,
},
checked: (attribute(cart, sourceIdName) == address.id) or (not attribute(cart, sourceIdName) and address.id == attribute(_context, primaryIdName)),
}) }}
</form>
{% endif %}
</span>

{% if primaryBillingAddressId == address.id or primaryShippingAddressId == address.id %}
<span class="absolute top-4 right-4">
{% if primaryBillingAddressId == address.id %}
<span title="{{ 'Primary billing address'|t }}">💳</span>
{% endif %}
{% if primaryShippingAddressId == address.id %}
<span title="{{ 'Primary shipping address'|t }}">📦</span>
<span class="-mt-2 ml-3 mb-2">
{{ address|address }}
</span>
</span>
<span class="block mb-1">
<a href="{{ url(editUrl) }}" class="[[classes.btn.small]] [[classes.btn.grayColor]]">
{{- 'Edit'|t -}}
</a>
{% if showDelete and not selectable %}
<form method="post" action="" class="js-address-delete inline-block">
{{ csrfInput() }}
{{ actionInput('users/delete-address') }}
{{ redirectInput('[[folderName]]/customer/addresses') }}
{{ hiddenInput('addressId', address.id) }}
{{ tag('button', {
type: 'submit',
class: '[[classes.btn.small]] [[classes.btn.grayColor]]',
text: 'Delete'|t
}) }}
</form>
{% endif %}
</span>
{% endif %}
{% endtag %}
</div>
{% endfor %}
</div>

{% if primaryBillingAddressId == address.id or primaryShippingAddressId == address.id %}
<span class="absolute top-4 right-4">
{% if primaryBillingAddressId == address.id %}
<span title="{{ 'Primary billing address'|t }}">💳</span>
{% endif %}
{% if primaryShippingAddressId == address.id %}
<span title="{{ 'Primary shipping address'|t }}">📦</span>
{% endif %}
</span>
{% endif %}
{% endtag %}
</div>
{% endfor %}
</div>
{% endif %}
{% if showAdd %}
<div class="pt-2">
<a href="{{ url(addUrl) }}" class="[[classes.btn.small]] [[classes.btn.mainColor]]">{{ 'Add address'|t }}</a>
</div>
{% endif %}
{% endif %}

{% js %}
Expand Down
4 changes: 3 additions & 1 deletion example-templates/src/shop/checkout/addresses.twig
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ Outputs a form for collecting an order’s shipping and billing address.
if ($body) {
// Creating new address
$radio.addEventListener('change', function(ev) {
console.log('changing');
if (ev.target.checked) {
$body.classList.remove('hidden');
} else {
Expand All @@ -136,6 +137,7 @@ Outputs a form for collecting an order’s shipping and billing address.
} else {
// Selecting existing address
$radio.addEventListener('change', function(ev) {
console.log(ev.target.checked);
if (ev.target.checked) {
var $newBox = document.querySelector('.js-address-select[data-model-name="' + ev.target.dataset.modelName + '"]');
if ($newBox) {
Expand All @@ -156,7 +158,7 @@ Outputs a form for collecting an order’s shipping and billing address.
var $billingFieldSet = document.querySelector('.js-address-fieldset.BillingAddress');
$billingFieldSet.classList.toggle('hidden');

for (let input of document.querySelector('.js-address-box.BillingAddress').querySelectorAll('input')) {
for (let input of $billingFieldSet.querySelectorAll('.js-address-select input')) {
if ($billingSameAs.checked === true) {
input.setAttribute('disabled', '');
} else if (input.hasAttribute('disabled')) {
Expand Down
Loading

0 comments on commit c51f365

Please sign in to comment.