Skip to content

Commit

Permalink
Merge branch '4.7' into feature/pt-1998-add-requires-coupon-code-ligh…
Browse files Browse the repository at this point in the history
…tswitch-to-discounts

# Conflicts:
#	CHANGELOG-WIP.md
  • Loading branch information
nfourtythree committed Sep 24, 2024
2 parents 46178fe + cf23533 commit 69b8b21
Show file tree
Hide file tree
Showing 18 changed files with 207 additions and 30 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Release Notes for Craft Commerce 4.7 (WIP)

## Unreleased

### Store Management
- It’s now possible to specifically make discounts require a coupon code. ([#3132](https://github.com/craftcms/commerce/issues/3132))
- Country code defaults to the store’s country when creating a new address on the Order Edit page. ([#3306](https://github.com/craftcms/commerce/issues/3306))
- Product conditions can now have a “Variant Search” rule. ([#3689](https://github.com/craftcms/commerce/issues/3689))

### Administration

### Development

### Extensibility
- Added `craft\commerce\elements\conditions\products\ProductVariantSearchConditionRule`.
- Added `craft\commerce\models\Discount::$requireCouponCode`.

### System
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Release Notes for Craft Commerce

## Unreleased

- Fixed a bug where some text wasn’t getting translated on the Edit Order page.
- Fixed a JavaScript error that could occur when editing an order.

## 4.6.11 - 2024-09-10

- Fixed XSS vulnerabilities.

## 4.6.10 - 2024-08-28

- Fixed a PHP error that could occur when default addresses were set on a cart. ([#3641](https://github.com/craftcms/commerce/issues/3641))
Expand Down
3 changes: 3 additions & 0 deletions src/controllers/OrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,9 @@ private function _registerJavascript(array $variables): void
$forceEdit = ($variables['order']->hasErrors() || !$variables['order']->isCompleted);

Craft::$app->getView()->registerJs('window.orderEdit.forceEdit = ' . Json::encode($forceEdit) . ';', View::POS_BEGIN);

$store = Plugin::getInstance()->getStore()->getStore();
Craft::$app->getView()->registerJs('window.orderEdit.store = ' . Json::encode($store->toArray([], ['locationAddress'])) . ';', View::POS_BEGIN);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/elements/conditions/products/ProductCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function conditionRuleTypes(): array
{
return array_merge(parent::conditionRuleTypes(), [
ProductTypeConditionRule::class,
ProductVariantSearchConditionRule::class,
ProductVariantSkuConditionRule::class,
ProductVariantStockConditionRule::class,
ProductVariantHasUnlimitedStockConditionRule::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craft\commerce\elements\conditions\products;

use Craft;
use craft\base\conditions\BaseTextConditionRule;
use craft\base\ElementInterface;
use craft\commerce\elements\db\ProductQuery;
use craft\commerce\elements\Product;
use craft\commerce\elements\Variant;
use craft\elements\conditions\ElementConditionRuleInterface;
use craft\elements\db\ElementQueryInterface;
use craft\helpers\ArrayHelper;
use yii\base\InvalidConfigException;

/**
* Product Variant Search Condition Rule
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 4.7.0
*/
class ProductVariantSearchConditionRule extends BaseTextConditionRule implements ElementConditionRuleInterface
{
/**
* @inheritdoc
*/
public function getLabel(): string
{
return Craft::t('commerce', 'Variant Search');
}

/**
* @inheritdoc
*/
public function getExclusiveQueryParams(): array
{
return [];
}

/**
* @inheritdoc
*/
protected function operators(): array
{
return [];
}

/**
* @inheritdoc
*/
protected function paramValue(): ?string
{
return trim(parent::paramValue()); // TODO: Change the autogenerated stub
}

/**
* @param ElementQueryInterface $query
*/
public function modifyQuery(ElementQueryInterface $query): void
{
$variantQuery = Variant::find();
$variantQuery->select(['commerce_variants.productId as id']);
$variantQuery->search($this->paramValue());

/** @var ProductQuery $query */
$query->andWhere(['elements.id' => $variantQuery]);
}

/**
* @param Product $element
* @return bool
* @throws InvalidConfigException
*/
public function matchElement(ElementInterface $element): bool
{
$variantIds = ArrayHelper::getColumn($element->getVariants(), 'id');
if (empty($variantIds)) {
return false;
}

// Perform a variant query search to ensure it is the same process as `modifyQuery`
$variantQuery = Variant::find();
$variantQuery->search($this->paramValue());
$variantQuery->id($variantIds);

return $variantQuery->count() > 0;
}
}
17 changes: 9 additions & 8 deletions src/elements/traits/OrderElementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use craft\elements\db\ElementQueryInterface;
use craft\elements\exporters\Expanded as CraftExpanded;
use craft\helpers\ArrayHelper;
use craft\helpers\Html;
use craft\models\FieldLayout;
use Exception;

Expand Down Expand Up @@ -77,35 +78,35 @@ protected function tableAttributeHtml(string $attribute): string
}
case 'shippingFullName':
{
return $this->getShippingAddress() ? $this->getShippingAddress()->fullName ?? '' : '';
return $this->getShippingAddress() ? Html::encode($this->getShippingAddress()->fullName ?? '') : '';
}
case 'shippingFirstName':
{
return $this->getShippingAddress() ? $this->getShippingAddress()->firstName ?? '' : '';
return $this->getShippingAddress() ? Html::encode($this->getShippingAddress()->firstName ?? '') : '';
}
case 'shippingLastName':
{
return $this->getShippingAddress() ? $this->getShippingAddress()->lastName ?? '' : '';
return $this->getShippingAddress() ? Html::encode($this->getShippingAddress()->lastName ?? '') : '';
}
case 'billingFullName':
{
return $this->getBillingAddress() ? $this->getBillingAddress()->fullName ?? '' : '';
return $this->getBillingAddress() ? Html::encode($this->getBillingAddress()->fullName ?? '') : '';
}
case 'billingFirstName':
{
return $this->getBillingAddress() ? $this->getBillingAddress()->firstName ?? '' : '';
return $this->getBillingAddress() ? Html::encode($this->getBillingAddress()->firstName ?? '') : '';
}
case 'billingLastName':
{
return $this->getBillingAddress() ? $this->getBillingAddress()->lastName ?? '' : '';
return $this->getBillingAddress() ? Html::encode($this->getBillingAddress()->lastName ?? '') : '';
}
case 'shippingOrganizationName':
{
return $this->getShippingAddress()->organization ?? '';
return $this->getShippingAddress() ? Html::encode($this->getShippingAddress()->organization ?? '') : '';
}
case 'billingOrganizationName':
{
return $this->getBillingAddress()->organization ?? '';
return $this->getBillingAddress() ? Html::encode($this->getBillingAddress()->organization ?? '') : '';
}
case 'shippingMethodName':
{
Expand Down
11 changes: 11 additions & 0 deletions src/models/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ public function setLocationAddress(?Address $locationAddress = null): void
$this->setLocationAddressId($locationAddress?->id);
}

/**
* @inheritdoc
*/
public function extraFields(): array
{
$fields = parent::extraFields();
$fields[] = 'locationAddress';

return $fields;
}

/**
* @inheritdoc
*/
Expand Down
1 change: 1 addition & 0 deletions src/translations/en/commerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,7 @@
'Variant Has Unlimited Stock' => 'Variant Has Unlimited Stock',
'Variant Price' => 'Variant Price',
'Variant SKU' => 'Variant SKU',
'Variant Search' => 'Variant Search',
'Variant Stock' => 'Variant Stock',
'Variant Title Format' => 'Variant Title Format',
'Variants' => 'Variants',
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/commerceui/dist/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/commerceui/dist/js/app.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/web/assets/commerceui/src/js/order/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ window.OrderDetailsApp = new Vue({
this.$store
.dispatch('recalculateOrder', draft)
.then(() => {
this.$store.dispatch('displayNotice', 'Order recalculated.');
this.$store.dispatch(
'displayNotice',
this.$options.filters.t('Order recalculated.', 'commerce')
);
})
.catch((error) => {
this.$store.dispatch('displayError', error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,10 @@
.then(() => {
this.$store.dispatch(
'displayNotice',
'Order recalculated.'
this.$options.filters.t(
'Order recalculated.',
'commerce'
)
);
})
.catch((error) => {
Expand Down
10 changes: 8 additions & 2 deletions src/web/assets/commerceui/src/js/order/apps/OrderDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@
.then(() => {
this.$store.dispatch(
'displayNotice',
'Order recalculated.'
this.$options.filters.t(
'Order recalculated.',
'commerce'
)
);
})
.catch((error) => {
Expand All @@ -242,7 +245,10 @@
.then(() => {
this.$store.dispatch(
'displayNotice',
'Order recalculated.'
this.$options.filters.t(
'Order recalculated.',
'commerce'
)
);
})
.catch((error) => {
Expand Down
25 changes: 20 additions & 5 deletions src/web/assets/commerceui/src/js/order/apps/OrderMeta.vue
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,10 @@
.then(() => {
this.$store.dispatch(
'displayNotice',
'Order recalculated.'
this.$options.filters.t(
'Order recalculated.',
'commerce'
)
);
})
.catch((error) => {
Expand All @@ -373,7 +376,10 @@
.then(() => {
this.$store.dispatch(
'displayNotice',
'Order recalculated.'
this.$options.filters.t(
'Order recalculated.',
'commerce'
)
);
})
.catch((error) => {
Expand All @@ -394,7 +400,10 @@
.then(() => {
this.$store.dispatch(
'displayNotice',
'Order recalculated.'
this.$options.filters.t(
'Order recalculated.',
'commerce'
)
);
})
.catch((error) => {
Expand Down Expand Up @@ -450,7 +459,10 @@
.then(() => {
this.$store.dispatch(
'displayNotice',
'Order recalculated.'
this.$options.filters.t(
'Order recalculated.',
'commerce'
)
);
})
.catch((error) => {
Expand All @@ -476,7 +488,10 @@
.then(() => {
this.$store.dispatch(
'displayNotice',
'Order recalculated.'
this.$options.filters.t(
'Order recalculated.',
'commerce'
)
);
})
.catch((error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
},
computed: {
...mapGetters(['hasCustomer']),
...mapGetters(['hasCustomer', 'store']),
emptyMsg() {
if (!this.emptyMessage) {
Expand Down Expand Up @@ -192,12 +192,22 @@
},
handleNewAddress() {
let data = {
elementType: 'craft\\elements\\Address',
ownerId: this.$store.state.draft.order.id,
title: this.title,
};
if (
this.store &&
this.store.locationAddress &&
this.store.locationAddress.countryCode
) {
data.countryCode = this.store.locationAddress.countryCode;
}
Craft.sendActionRequest('POST', 'elements/create', {
data: {
elementType: 'craft\\elements\\Address',
ownerId: this.$store.state.draft.order.id,
title: this.title,
},
data: data,
}).then((response) => {
const slideout = Craft.createElementEditor(
'craft\\elements\\Address',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@
},
isLoadMoreVisible() {
if (!this.$store.state.draft.order.customer) {
return false;
}
if (
this.$store.state.draft.order.customer.totalAddresses ==
this.addresses.length
Expand Down
Loading

0 comments on commit 69b8b21

Please sign in to comment.