Skip to content

Commit

Permalink
Merge branch 'develop' into bugfix/3298-4x-sale-discount-set-dateupda…
Browse files Browse the repository at this point in the history
…ted-+-datecreated-after-save
  • Loading branch information
lukeholder authored Oct 17, 2023
2 parents 02ed12a + 451de16 commit 92e90d1
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 46 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
- Added the `commerce/gateways/webhook-url` command.
- Fixed a bug where the delete button would be shown for users that do not have permission to delete on the Product edit page. ([#3285](https://github.com/craftcms/commerce/issues/3285))
- Fixed a bug where deleted shipping categories were still available for selection. ([#3272](https://github.com/craftcms/commerce/issues/3272))
- Fixed a bug where the customer condition rule wasn’t loading correctly. ([#3291](https://github.com/craftcms/commerce/issues/3291))
- Fixed an error that could occur when rendering a PDF. ([#2633](https://github.com/craftcms/commerce/issues/2633))
- Fixed a bug where Sale’s and Discount’s date audit columns weren’t populated after saving. ([#3298](https://github.com/craftcms/commerce/issues/3298))
- Fixed a bug where duplicate inactive users could be created when using the `commerce/upgrade` command. ([#3286](https://github.com/craftcms/commerce/issues/3286))

## 4.3.0 - 2023-09-13

Expand Down
21 changes: 4 additions & 17 deletions example-templates/dist/shop/_private/address/fields.twig
Original file line number Diff line number Diff line change
Expand Up @@ -198,30 +198,17 @@ Outputs address form fields for editing an address.
{% if showPrimaryCheckboxes %}
<hr class="my-2">
<div class="my-2">
{{ input('hidden', '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>
{{ hiddenInput('isPrimaryBilling', 0) }}
<label>{{ input('checkbox', 'isPrimaryBilling', 1, { checked: address.isPrimaryBilling }) }} {{ 'Use as the primary billing address'|t('commerce') }}</label>
</div>
<div class="my-2">
{{ input('hidden', '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>
{{ hiddenInput('isPrimaryShipping', 0) }}
<label>{{ input('checkbox', 'isPrimaryShipping', 1, { checked: address.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
20 changes: 16 additions & 4 deletions example-templates/dist/shop/_private/address/list.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="my-6 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-2 xl:grid-cols-3 gap-4">
{% for address in addresses %}
{% set editUrl = '/shop/customer/addresses/edit?addressId=' ~ address.id ~ '&redirect=' ~ craft.app.request.fullPath %}
<div class="block border border-gray-200 bg-white rounded-lg shadow-sm hover:shadow-md p-4 w-full">
<div class="block border border-gray-200 bg-white rounded-lg shadow-sm hover:shadow-md p-4 w-full relative">
{% tag selectable ? 'label' : 'div' with {
class: 'block relative address-select js-address-select',
data: {
Expand Down Expand Up @@ -49,12 +49,24 @@
{% endif %}
</span>
{% endtag %}
{% if primaryBillingAddressId == address.id or primaryShippingAddressId == address.id %}
<div class="absolute top-0 right-0 pr-4 pt-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 %}
</div>
{% endif %}
</div>
{% endfor %}
{% if showAdd %}
<a href="{{ addUrl }}" class="block rounded-lg hover:shadow-md w-full">
<div class="flex items-center justify-center h-full border border-gray-200 bg-white rounded-lg shadow-sm p-4 w-full group hover:shadow-md">
<span class="group-hover:underline">Add Address</span>
<a href="{{ addUrl }}" class="block rounded-lg border border-gray-200 bg-white hover:shadow-md w-full relative">
<div class="absolute top-0 left-0 right-0 bottom-0 flex items-center">
<div class="flex items-center justify-center h-full p-4 w-full group">
<span class="group-hover:underline">Add Address</span>
</div>
</div>
</a>
{% endif %}
Expand Down
21 changes: 4 additions & 17 deletions example-templates/src/shop/_private/address/fields.twig
Original file line number Diff line number Diff line change
Expand Up @@ -198,30 +198,17 @@ Outputs address form fields for editing an address.
{% if showPrimaryCheckboxes %}
<hr class="my-2">
<div class="my-2">
{{ input('hidden', '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>
{{ hiddenInput('isPrimaryBilling', 0) }}
<label>{{ input('checkbox', 'isPrimaryBilling', 1, { checked: address.isPrimaryBilling }) }} {{ 'Use as the primary billing address'|t('commerce') }}</label>
</div>
<div class="my-2">
{{ input('hidden', '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>
{{ hiddenInput('isPrimaryShipping', 0) }}
<label>{{ input('checkbox', 'isPrimaryShipping', 1, { checked: address.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
20 changes: 16 additions & 4 deletions example-templates/src/shop/_private/address/list.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="my-6 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-2 xl:grid-cols-3 gap-4">
{% for address in addresses %}
{% set editUrl = '/[[folderName]]/customer/addresses/edit?addressId=' ~ address.id ~ '&redirect=' ~ craft.app.request.fullPath %}
<div class="block border border-gray-200 bg-white rounded-lg shadow-sm hover:shadow-md p-4 w-full">
<div class="block border border-gray-200 bg-white rounded-lg shadow-sm hover:shadow-md p-4 w-full relative">
{% tag selectable ? 'label' : 'div' with {
class: 'block relative address-select js-address-select',
data: {
Expand Down Expand Up @@ -49,12 +49,24 @@
{% endif %}
</span>
{% endtag %}
{% if primaryBillingAddressId == address.id or primaryShippingAddressId == address.id %}
<div class="absolute top-0 right-0 pr-4 pt-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 %}
</div>
{% endif %}
</div>
{% endfor %}
{% if showAdd %}
<a href="{{ addUrl }}" class="block rounded-lg hover:shadow-md w-full">
<div class="flex items-center justify-center h-full border border-gray-200 bg-white rounded-lg shadow-sm p-4 w-full group hover:shadow-md">
<span class="group-hover:underline">Add Address</span>
<a href="{{ addUrl }}" class="block rounded-lg border border-gray-200 bg-white hover:shadow-md w-full relative">
<div class="absolute top-0 left-0 right-0 bottom-0 flex items-center">
<div class="flex items-center justify-center h-full p-4 w-full group">
<span class="group-hover:underline">Add Address</span>
</div>
</div>
</a>
{% endif %}
Expand Down
7 changes: 6 additions & 1 deletion src/base/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ public function getWebhookUrl(array $params = []): string

$url = UrlHelper::actionUrl('commerce/webhooks/process-webhook', $params);

return StringHelper::replace($url, Craft::$app->getConfig()->getGeneral()->cpTrigger . '/', '');
// Remove the cpTrigger from the url if it's there.
if (Craft::$app->getConfig()->getGeneral()->cpTrigger) {
$url = StringHelper::replace($url, Craft::$app->getConfig()->getGeneral()->cpTrigger . '/', '');
}

return $url;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/console/controllers/UpgradeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,8 @@ public function _migrateCustomers(): void
->leftJoin(['u' => $usersTable], 'o.email = u.email')
->where(['u.email' => null])
->andWhere(['not', ['o.email' => null]])
->andWhere(['not', ['o.email' => '']])
->groupBy(['[[o.email]]'])
->column();
$this->stdoutlast(' Done. Found ' . count($guestEmails) . ' guest emails.', Console::FG_GREEN);

Expand Down
30 changes: 27 additions & 3 deletions src/elements/conditions/orders/CustomerConditionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
use craft\elements\conditions\ElementConditionRuleInterface;
use craft\elements\db\ElementQueryInterface;
use craft\elements\User;
use craft\helpers\Cp;
use craft\helpers\Db;
use yii\base\InvalidConfigException;
use yii\db\Expression;

/**
* Customer Condition Rule
*
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 4.2.0
* @TODO change the class that the `CustomerConditionRule` extends
*/
class CustomerConditionRule extends BaseMultiSelectConditionRule implements ElementConditionRuleInterface
{
Expand All @@ -35,6 +39,7 @@ public function getLabel(): string

/**
* @return array
* @deprecated in 4.3.1.
*/
protected function options(): array
{
Expand All @@ -47,6 +52,24 @@ protected function options(): array
->all();
}

/**
* @inheritDoc
*/
protected function inputHtml(): string
{
$users = User::find()->status(null)->limit(null)->id($this->values)->all();

return Cp::elementSelectHtml([
'name' => 'values',
'elements' => $users,
'elementType' => User::class,
'sources' => null,
'criteria' => null,
'condition' => null,
'single' => false,
]);
}

/**
* @inheritdoc
*/
Expand All @@ -63,10 +86,11 @@ public function modifyQuery(ElementQueryInterface $query): void
/** @var OrderQuery $query */
$paramValue = $this->paramValue();
if ($this->operator === self::OPERATOR_NOT_IN) {
$paramValue = ['or', $paramValue, null];
// Account for the fact the querying using a combination of `not` and `in` doesn't match `null` in the column
$query->andWhere(Db::parseParam(new Expression('coalesce([[commerce_orders.customerId]], -1)'), $paramValue));
} else {
$query->customerId($paramValue);
}

$query->customerId($paramValue);
}

/**
Expand Down

0 comments on commit 92e90d1

Please sign in to comment.