Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.2 #3627

Merged
merged 178 commits into from
Oct 16, 2024
Merged

5.2 #3627

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
3314d53
Add warning alert if upgrade command not completed
lukeholder Jun 21, 2024
77a1a59
Code style
lukeholder Jun 21, 2024
8023870
Adjust language
AugustMiller Jun 21, 2024
0bccf5c
Start 4.7 WIP release notes
lukeholder Aug 15, 2024
71d0845
WIP
lukeholder Aug 20, 2024
efafb5f
Merge branch '5.1' into 5.2
nfourtythree Aug 22, 2024
05573b8
Null out WIP changelog
nfourtythree Aug 22, 2024
9bd4047
performance improvements
lukeholder Sep 4, 2024
e0c40d4
Merge branch '5.x' into feature/structured-product-types
lukeholder Sep 6, 2024
7137c70
#3132 Issue where it was impossible for store managers to remove all …
nfourtythree Sep 6, 2024
4489783
#3132 Add “Require Coupon Code” lightswitch to discounts
nfourtythree Sep 6, 2024
374ae56
Changelog
nfourtythree Sep 6, 2024
c08ce32
Run workflow for `4.7`
nfourtythree Sep 6, 2024
ef8b0c3
Merge branch '4.7' into feature/pt-1998-add-requires-coupon-code-ligh…
nfourtythree Sep 6, 2024
c717c1e
fix cs
nfourtythree Sep 6, 2024
9d91c3a
fix install typo
nfourtythree Sep 6, 2024
3ad5aa0
No need for extra logic
nfourtythree Sep 6, 2024
76f1a3f
Merge branch '4.x' into 4.7
nfourtythree Sep 6, 2024
70a8c36
Merge branch '4.7' into feature/pt-1998-add-requires-coupon-code-ligh…
nfourtythree Sep 6, 2024
46178fe
Fix tests
nfourtythree Sep 6, 2024
85bff2d
Orderable Products
lukeholder Sep 9, 2024
f89d406
Merge branch '5.2' into feature/orderable-product-types
lukeholder Sep 9, 2024
5f88efb
Merge branch '5.x' into 5.2
lukeholder Sep 9, 2024
69461c9
Merge branch '5.2' into feature/orderable-product-types
lukeholder Sep 9, 2024
655fc4b
Cleanup
lukeholder Sep 9, 2024
74e4c43
Fixes
lukeholder Sep 9, 2024
af20daf
Add missing install information
nfourtythree Sep 9, 2024
e9ae669
Query fix
nfourtythree Sep 9, 2024
69411a1
Cleanup
lukeholder Sep 10, 2024
35981e1
Cleanup
lukeholder Sep 10, 2024
dc130f3
Merge branch '4.7' into feature/shipping-condition-performance
lukeholder Sep 10, 2024
dcd49a1
Reapply "Performance improvement order condition on shipping"
lukeholder Sep 10, 2024
165d875
Improve cart performance
lukeholder Sep 10, 2024
ba3e1f8
Release notes
lukeholder Sep 10, 2024
20323dc
Save if new in cart
lukeholder Sep 10, 2024
c9f40f2
no need to save if it was forced saved
lukeholder Sep 10, 2024
5daaf25
No need
lukeholder Sep 10, 2024
ddd7dd9
#3306 default new address creation on order edit to store’s country
nfourtythree Sep 10, 2024
f60ac89
fix cs
nfourtythree Sep 10, 2024
d92aa5a
Cleanup
lukeholder Sep 11, 2024
6dfad2b
Merge branch '4.x' into 4.7
nfourtythree Sep 11, 2024
898f12a
isOnPromotion() and hasPromotionalPrice() methods for PurchasableQuery
AugustMiller Sep 13, 2024
3ec8093
De-dupe docs type hint
AugustMiller Sep 13, 2024
ec2dae7
Merge remote-tracking branch 'origin/5.x' into feature/promotion-quer…
AugustMiller Sep 13, 2024
c3a872f
ECS
AugustMiller Sep 13, 2024
ce75085
Merge branch '5.x' into 5.2
nfourtythree Sep 13, 2024
4f5cf77
Merge branch '5.x' into 5.2
nfourtythree Sep 13, 2024
785d70a
Merge branch '5.2' into feature/promotion-query-methods
nfourtythree Sep 13, 2024
d677f22
Tweak to one method
nfourtythree Sep 13, 2024
53cbc64
Add test for `hasPromotionalPrice()` purchasable query method
nfourtythree Sep 13, 2024
e0741a3
Tidy
nfourtythree Sep 13, 2024
2b752ec
Fix query
nfourtythree Sep 13, 2024
d301a62
Add events
lukeholder Sep 16, 2024
50f3aab
Merge branch '4.7' into feature/upgrade-events
lukeholder Sep 16, 2024
1081502
Merge branch '5.x' into 5.2
nfourtythree Sep 19, 2024
c3f3d5f
`hasPromotionalPrice` -> `onPromotion`
nfourtythree Sep 23, 2024
fac56cf
Added “Variant Search” condition rule for product conditions #3689
nfourtythree Sep 24, 2024
76b8eaf
Merge pull request #3691 from craftcms/feature/pt-2164-4x5x-variant-s…
lukeholder Sep 24, 2024
74369f4
Merge branch '4.7' into feature/pt-2142-4x-new-address-in-order-entry…
nfourtythree Sep 24, 2024
98acbed
build JS
nfourtythree Sep 24, 2024
7962a62
Tidy changelog
nfourtythree Sep 24, 2024
cf23533
Merge pull request #3665 from craftcms/feature/pt-2142-4x-new-address…
nfourtythree Sep 24, 2024
69b8b21
Merge branch '4.7' into feature/pt-1998-add-requires-coupon-code-ligh…
nfourtythree Sep 24, 2024
3f434d6
Merge branch '4.x' into 4.7
nfourtythree Sep 24, 2024
c4818d2
Merge branch '4.7' into feature/pt-1998-add-requires-coupon-code-ligh…
nfourtythree Sep 24, 2024
cfe4ce3
fix cs
nfourtythree Sep 24, 2024
85c819d
Merge branch '4.7' into feature/pt-1998-add-requires-coupon-code-ligh…
nfourtythree Sep 24, 2024
1078f1e
Merge pull request #3660 from craftcms/feature/pt-1998-add-requires-c…
nfourtythree Sep 24, 2024
86c54b5
Merge branch '4.7' into feature/upgrade-events
nfourtythree Sep 25, 2024
89062bb
doc block tweak
nfourtythree Sep 25, 2024
640b31a
fix cs
nfourtythree Sep 25, 2024
4bc9cca
Merge pull request #3675 from craftcms/feature/upgrade-events
lukeholder Sep 25, 2024
895fb63
Merge branch '4.x' into feature/shipping-condition-performance
lukeholder Sep 30, 2024
f2d2c10
Fix php error
lukeholder Sep 30, 2024
94bcfc9
Merge branch '4.7' into feature/shipping-condition-performance
lukeholder Oct 1, 2024
de7653e
Merge branch '4.x' into 4.7
lukeholder Oct 1, 2024
d9f4239
Merge branch '4.7' into feature/shipping-condition-performance
lukeholder Oct 1, 2024
67d3bb4
Merge branch '5.x' into 5.2
nfourtythree Oct 2, 2024
bfe814e
Merge branch '5.x' into 5.2
nfourtythree Oct 3, 2024
c811222
Merge branch '5.2' into feature/orderable-product-types
lukeholder Oct 9, 2024
87acb58
Cleanup
lukeholder Oct 9, 2024
b64ada0
Release notes
lukeholder Oct 9, 2024
bfb1521
Merge pull request #3663 from craftcms/feature/orderable-product-types
lukeholder Oct 9, 2024
b33f689
Use teller class for order comparisons
lukeholder Oct 9, 2024
55efd3c
cleanup
lukeholder Oct 9, 2024
d2551dd
Use teller
lukeholder Oct 9, 2024
7261c91
release notes
lukeholder Oct 9, 2024
0a11a07
Merge pull request #3712 from craftcms/feature/teller-rounding
lukeholder Oct 9, 2024
9ce7778
Fix translation
lukeholder Oct 9, 2024
1ec7779
Merge branch '4.7' into feature/upgrade-warning
lukeholder Oct 9, 2024
e0739cc
More simple translations
lukeholder Oct 9, 2024
94d518d
Merge branch '4.7' into feature/shipping-condition-performance
lukeholder Oct 9, 2024
9bfe91a
Test
lukeholder Oct 9, 2024
72cd613
Merge pull request #3550 from craftcms/feature/upgrade-warning
lukeholder Oct 9, 2024
2540239
Add since tag
lukeholder Oct 9, 2024
a6efd8e
Merge pull request #3653 from craftcms/feature/shipping-condition-per…
lukeholder Oct 9, 2024
ebfe563
Merge branch '4.x' into 4.7
lukeholder Oct 9, 2024
e92bf58
Merge pull request #3670 from craftcms/feature/promotion-query-methods
lukeholder Oct 9, 2024
91cf9a3
Release Notes
lukeholder Oct 9, 2024
8364060
Cleanup
lukeholder Oct 9, 2024
1f98969
Cleanup comments
lukeholder Oct 9, 2024
141bb55
Fix error due to missing defaults
lukeholder Oct 9, 2024
2f3dce0
WIp deletion translations
nfourtythree Oct 9, 2024
8404c31
Merge branch '5.2' into bugfix/deletion-translations
nfourtythree Oct 9, 2024
c6380a9
Merge branch '5.x' into 5.2
nfourtythree Oct 9, 2024
f04c605
More tweaks
nfourtythree Oct 9, 2024
c21bc28
Fix cs
nfourtythree Oct 9, 2024
17e7cf5
Merge pull request #3713 from craftcms/bugfix/deletion-translations
nfourtythree Oct 9, 2024
e91cb9a
Merge branch '4.7' into 5.2
lukeholder Oct 9, 2024
16a2115
fix cs
nfourtythree Oct 9, 2024
486060a
Remove duplicate `_getTeller()` method
nfourtythree Oct 9, 2024
f6d631e
Update defautl country selection on order edit for Commerce 5
nfourtythree Oct 9, 2024
be051d2
Use collection
nfourtythree Oct 9, 2024
14d7221
Update `ProductVariantSearchConditionRule` for 5.x
nfourtythree Oct 9, 2024
635ec7a
fix cs
nfourtythree Oct 9, 2024
ffb6257
Move to structure
lukeholder Oct 10, 2024
3a421bc
Merge branch 'feature/rename-structure' into 5.2
lukeholder Oct 10, 2024
1640fb1
Fix
lukeholder Oct 10, 2024
3b33390
cleanup
lukeholder Oct 10, 2024
405092c
Fixed max levels saving bug
nfourtythree Oct 10, 2024
c65c49d
Merge branch '5.2' of github.com:craftcms/commerce into 5.2
nfourtythree Oct 10, 2024
fb41962
parent selector
lukeholder Oct 10, 2024
a51b6be
Cleanup
lukeholder Oct 10, 2024
e545bdf
Merge branch '5.2' of github.com:craftcms/commerce into 5.2
lukeholder Oct 10, 2024
e6f49e6
same as entries
lukeholder Oct 10, 2024
a327d19
Use the data
lukeholder Oct 10, 2024
38f4026
Fixed before, after and child actions for structured product types
nfourtythree Oct 10, 2024
fd3f4a3
Wording
lukeholder Oct 11, 2024
fcc04a9
Tweak
brandonkelly Oct 11, 2024
02bc167
Redundant translation
brandonkelly Oct 11, 2024
a76af53
New translations commerce.php (French)
shinybrad Oct 11, 2024
bf91cf1
New translations commerce.php (German)
shinybrad Oct 11, 2024
98a566f
New translations commerce.php (Italian)
shinybrad Oct 11, 2024
692c9ee
New translations commerce.php (Japanese)
shinybrad Oct 11, 2024
64a3ffa
New translations commerce.php (Dutch)
shinybrad Oct 11, 2024
b010e66
New translations commerce.php (Portuguese)
shinybrad Oct 11, 2024
8521c6d
New translations commerce.php (Slovak)
shinybrad Oct 11, 2024
0236a6c
New translations commerce.php (English, United Kingdom)
shinybrad Oct 11, 2024
c269423
New translations commerce.php (French, Canada)
shinybrad Oct 11, 2024
0231d77
New translations commerce.php (Norwegian Bokmal)
shinybrad Oct 11, 2024
461763c
New translations commerce.php (Dutch)
shinybrad Oct 14, 2024
729840d
New translations commerce.php (French)
shinybrad Oct 14, 2024
1c41035
New translations commerce.php (Italian)
shinybrad Oct 14, 2024
7325a7d
New translations commerce.php (Slovak)
shinybrad Oct 14, 2024
05be1c4
New translations commerce.php (French, Canada)
shinybrad Oct 14, 2024
76903bc
New translations commerce.php (Italian)
shinybrad Oct 14, 2024
1370cf6
New translations commerce.php (Slovak)
shinybrad Oct 14, 2024
ab8f1b3
New translations commerce.php (French, Canada)
shinybrad Oct 14, 2024
1e04605
New translations commerce.php (Japanese)
shinybrad Oct 14, 2024
5562d76
New translations commerce.php (Portuguese)
shinybrad Oct 14, 2024
4caaaae
Fixes duplicate carts created
lukeholder Oct 15, 2024
ab45d9d
oops
lukeholder Oct 15, 2024
768a211
Fix code style
lukeholder Oct 15, 2024
58b62a5
Merge branch '4.7' into feature/fix-extra-carts-created
lukeholder Oct 15, 2024
859c92c
New translations commerce.php (Japanese)
shinybrad Oct 15, 2024
8511332
Better way
lukeholder Oct 15, 2024
83488b6
Formatting
lukeholder Oct 15, 2024
6d5494b
New translations commerce.php (Dutch)
shinybrad Oct 15, 2024
44ffb16
New translations commerce.php (Norwegian Bokmal)
shinybrad Oct 15, 2024
1d3bc08
cleanup
lukeholder Oct 16, 2024
7cb8d6f
Merge pull request #3723 from craftcms/feature/fix-extra-carts-created
lukeholder Oct 16, 2024
a0d443c
Merge branch '4.7' into 5.2
lukeholder Oct 16, 2024
4c6cee9
New translations commerce.php (Norwegian Bokmal)
shinybrad Oct 16, 2024
beaa1c5
Merge branch '5.x' into 5.2
nfourtythree Oct 16, 2024
4088ae6
build
nfourtythree Oct 16, 2024
b0b7e8e
New translations commerce.php (German)
shinybrad Oct 16, 2024
77efb56
Merge branch '5.x' into 5.2
lukeholder Oct 16, 2024
09389f4
Merge pull request #3718 from craftcms/t9n/5.2
lukeholder Oct 16, 2024
653173f
New translations commerce.php (French)
shinybrad Oct 16, 2024
b24fff6
New translations commerce.php (German)
shinybrad Oct 16, 2024
3e7f83d
New translations commerce.php (Japanese)
shinybrad Oct 16, 2024
a153777
New translations commerce.php (Dutch)
shinybrad Oct 16, 2024
e47d15d
New translations commerce.php (Portuguese)
shinybrad Oct 16, 2024
7c0173b
New translations commerce.php (Slovak)
shinybrad Oct 16, 2024
08b8349
New translations commerce.php (French, Canada)
shinybrad Oct 16, 2024
1fbb8e3
New translations commerce.php (Norwegian Bokmal)
shinybrad Oct 16, 2024
26d4db9
Merge pull request #3728 from craftcms/t9n/5.2
lukeholder Oct 16, 2024
39f1376
Changelog tweaks
brandonkelly Oct 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Release Notes for Craft Commerce 5.2 (WIP)

### Store Management
- Products can now be structured, per product type.
- It’s now possible for discounts to explicitly require a coupon code. ([#3132](https://github.com/craftcms/commerce/issues/3132))
- New order addresses now default to the store’s country on Order Edit screens. ([#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))

### Development
- Added the `onPromotion` purchasable query param.
- Added the `onPromotion` GraphQL variant query argument.

### Extensibility
- Added `craft\commerce\console\controllers\UpgradeController::$v3droppableColumns`
- Added `craft\commerce\console\controllers\UpgradeController::EVENT_BEFORE_DROP_V3_DATABASE_ENTITIES`.
- Added `craft\commerce\elements\Product::EVENT_DEFINE_PARENT_SELECTION_CRITERIA`.
- Added `craft\commerce\elements\conditions\products\ProductVariantSearchConditionRule`.
- Added `craft\commerce\elements\db\Purchasable::$onPromotion`.
- Added `craft\commerce\elements\db\Purchasable::onPromotion()`.
- Added `craft\commerce\events\UpgradeEvent`.
- Added `craft\commerce\models\Discount::$requireCouponCode`.
- Added `craft\commerce\models\ProductType::$isStructure`
- Added `craft\commerce\models\ProductType::$maxLevels`
- Added `craft\commerce\models\ProductType::$structureId`
- Added `craft\commerce\models\ProductType::DEFAULT_PLACEMENT_BEGINNING`
- Added `craft\commerce\models\ProductType::DEFAULT_PLACEMENT_END`
- Added `craft\commerce\models\ProductType::getConfig()`

### System
- Improved the performance of adding items to the cart.
- Improved the performance of shipping rule matching when an order condition formula is used. ([3653](https://github.com/craftcms/commerce/pull/3653))
- Craft Commerce now requires Money PHP 4.2 or later.
- Fixed a bug where outstanding order balances could be calculated incorrectly. ([#3403](https://github.com/craftcms/commerce/issues/3403))
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"craftcms/cms": "^5.2.0",
"dompdf/dompdf": "^2.0.2",
"ibericode/vat": "^1.2.2",
"iio/libmergepdf": "^4.0"
"iio/libmergepdf": "^4.0",
"moneyphp/money": "^4.2.0"
},
"require-dev": {
"codeception/codeception": "^5.0.11",
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public static function editions(): array
/**
* @inheritDoc
*/
public string $schemaVersion = '5.1.0.3';
public string $schemaVersion = '5.2.0.3';

/**
* @inheritdoc
Expand Down
9 changes: 6 additions & 3 deletions src/controllers/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function actionUpdateCart(): ?Response

// Get the cart from the request or from the session.
// When we are about to update the cart, we consider it a real cart at this point, and want to actually create it in the DB.
$this->_cart = $this->_getCart(true);
$this->_cart = $this->_getCart();

// Can clear line items when updating the cart
$clearLineItems = $this->request->getParam('clearLineItems');
Expand Down Expand Up @@ -584,7 +584,7 @@ private function _getCart(bool $forceSave = false): Order
// Get the cart from the order number
$cart = Order::find()->number($orderNumber)->isCompleted(false)->one();

if (!$cart) {
if ($cart === null) {
throw new NotFoundHttpException('Cart not found');
}

Expand All @@ -594,7 +594,9 @@ private function _getCart(bool $forceSave = false): Order
$requestForceSave = (bool)$this->request->getBodyParam('forceSave');
$doForceSave = ($requestForceSave || $forceSave);

return Plugin::getInstance()->getCarts()->getCart($doForceSave);
$this->_cart = Plugin::getInstance()->getCarts()->getCart($doForceSave);

return $this->_cart;
}

/**
Expand Down Expand Up @@ -699,6 +701,7 @@ private function _setAddresses(): void
'owner' => $this->_cart,
]
);

$this->_cart->setBillingAddress($cartBillingAddress);

if ($shippingIsBilling) {
Expand Down
9 changes: 4 additions & 5 deletions src/controllers/DiscountsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,11 @@ public function actionTableData(): Response
'discounts.dateTo',
'discounts.totalDiscountUses',
'discounts.ignorePromotions',
'discounts.requireCouponCode',
'discounts.stopProcessing',
'discounts.sortOrder',
'coupons.discountId',
])
->distinct()
->where(['discounts.storeId' => $storeId])
->leftJoin(Table::COUPONS . ' coupons', '[[coupons.discountId]] = [[discounts.id]]')
->orderBy(['sortOrder' => SORT_ASC]);


Expand Down Expand Up @@ -164,8 +162,7 @@ public function actionTableData(): Response
'status' => (bool)$item['enabled'],
'duration' => $dateRange,
'timesUsed' => $item['totalDiscountUses'],
// If there is joined data then there are coupons
'hasCoupons' => (bool)$item['discountId'],
'requireCouponCode' => (bool)$item['requireCouponCode'],
'ignore' => (bool)$item['ignorePromotions'],
'stop' => (bool)$item['stopProcessing'],
];
Expand Down Expand Up @@ -259,6 +256,7 @@ public function actionSave(): ?Response
$discount->setCustomerCondition($this->request->getBodyParam('customerCondition'));
$discount->setShippingAddressCondition($this->request->getBodyParam('shippingAddressCondition'));
$discount->setBillingAddressCondition($this->request->getBodyParam('billingAddressCondition'));
$discount->requireCouponCode = (bool)$this->request->getBodyParam('requireCouponCode');
$discount->stopProcessing = (bool)$this->request->getBodyParam('stopProcessing');
$discount->purchaseQty = $this->request->getBodyParam('purchaseQty');
$discount->maxPurchaseQty = $this->request->getBodyParam('maxPurchaseQty');
Expand Down Expand Up @@ -385,6 +383,7 @@ public function actionSave(): ?Response
private function _setCouponsOnDiscount(array $coupons, Discount $discount): void
{
if (empty($coupons)) {
$discount->setCoupons([]);
return;
}

Expand Down
3 changes: 3 additions & 0 deletions src/controllers/OrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,9 @@ private function _registerJavascript(array $variables): void
$forceEdit = ($order->hasErrors() || !$order->isCompleted);

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

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

/**
Expand Down
18 changes: 15 additions & 3 deletions src/controllers/ProductTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,17 @@ public function actionSaveProductType(): void
}

$this->requirePostRequest();
$productTypeId = $this->request->getBodyParam('productTypeId');

$productType = new ProductType();
if ($productTypeId) {
$productType = Plugin::getInstance()->getProductTypes()->getProductTypeById($productTypeId);

if (!$productType) {
throw new BadRequestHttpException("Invalid section ID: $productTypeId");
}
} else {
$productType = new ProductType();
}

// Shared attributes
$productType->id = $this->request->getBodyParam('productTypeId');
Expand All @@ -130,8 +139,11 @@ public function actionSaveProductType(): void
$productType->variantTitleTranslationKeyFormat = $this->request->getBodyParam('variantTitleTranslationKeyFormat', $productType->variantTitleTranslationKeyFormat);
$productType->skuFormat = $this->request->getBodyParam('skuFormat');
$productType->descriptionFormat = $this->request->getBodyParam('descriptionFormat');
$productType->propagationMethod = PropagationMethod::tryFrom($this->request->getBodyParam('propagationMethod') ?? '')
?? PropagationMethod::All;
$productType->propagationMethod = PropagationMethod::tryFrom($this->request->getBodyParam('propagationMethod') ?? '') ?? PropagationMethod::All;
$productType->isStructure = $this->request->getBodyParam('isStructure');
$maxLevels = (int)$this->request->getBodyParam('maxLevels');
$productType->maxLevels = $maxLevels ?: null; // zero should be null
$productType->defaultPlacement = $this->request->getBodyParam('defaultPlacement');

// Site-specific settings
$allSiteSettings = [];
Expand Down
24 changes: 24 additions & 0 deletions src/controllers/ProductsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ public function actionCreate(?string $productType = null)
$product->typeId = $productType->id;
$product->enabled = true;

// Structure parent
if (
$productType->isStructure &&
(int)$productType->maxLevels !== 1
) {
// Set the initially selected parent
$product->setParentId($this->request->getParam('parentId'));
}

// Make sure the user is allowed to create this entry
if (!Craft::$app->getElements()->canSave($product, $user)) {
throw new ForbiddenHttpException('User not authorized to create this product.');
Expand Down Expand Up @@ -131,6 +140,21 @@ public function actionCreate(?string $productType = null)
]), 'product');
}

// Set its position in the structure if a before/after param was passed
if ($productType->isStructure) {
if ($nextId = $this->request->getParam('before')) {
$nextEntry = Plugin::getInstance()->getProducts()->getProductById($nextId, $site->id, [
'structureId' => $productType->structureId,
]);
Craft::$app->getStructures()->moveBefore($productType->structureId, $product, $nextEntry);
} elseif ($prevId = $this->request->getParam('after')) {
$prevEntry = Plugin::getInstance()->getProducts()->getProductById($prevId, $site->id, [
'structureId' => $productType->structureId,
]);
Craft::$app->getStructures()->moveAfter($productType->structureId, $product, $prevEntry);
}
}

$editUrl = $product->getCpEditUrl();

$response = $this->asModelSuccess($product, Craft::t('app', '{type} created.', [
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/ShippingCategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ public function actionDelete(): ?Response
}

if (!empty($failedIds)) {
// @TODO: re-word this message at next translations update
return $this->asFailure(Craft::t('commerce', 'Could not delete shipping category'));
return $this->asFailure(Craft::t('commerce', 'Could not delete {count, number} shipping {count, plural, one{category} other{categories}}.', [
'count' => count($failedIds),
]));
}

// @TODO: re-word add better message in next translation update
return $this->asSuccess();
return $this->asSuccess(Craft::t('commerce', 'Shipping categories deleted.'));
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/ShippingMethodsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ public function actionDelete(): ?Response
}

if (!empty($failedIds)) {
// @TODO: re-word this message at next translations update
return $this->asFailure(Craft::t('commerce', 'Could not delete shipping method and its rules.'));
return $this->asFailure(Craft::t('commerce', 'Could not delete {count, number} shipping {count, plural, one{method} other{methods}} and rules.', [
'count' => count($failedIds),
]));
}

// @TODO: re-word add better message in next translation update
return $this->asSuccess();
return $this->asSuccess(Craft::t('commerce', 'Shipping methods and rules deleted.'));
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/TaxCategoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function actionSave(): ?Response
/**
* @throws HttpException
*/
public function actionDelete(): Response
public function actionDelete(): ?Response
{
$this->requirePostRequest();

Expand All @@ -171,12 +171,12 @@ public function actionDelete(): Response
}

if (!empty($failedIds)) {
// @TODO: re-word this message at next translations update
return $this->asFailure(Craft::t('commerce', 'Could not delete tax category'));
return $this->asFailure(Craft::t('commerce', 'Could not delete {count, number} tax {count, plural, one{category} other{categories}}.', [
'count' => count($failedIds),
]));
}

// @TODO: re-word add better message in next translation update
return $this->asSuccess();
return $this->asSuccess(Craft::t('commerce', 'Tax categories deleted.'));
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/elements/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -2592,11 +2592,9 @@ public function isPaymentAmountPartial(): bool
*/
public function getPaidStatus(): string
{
$teller = $this->_getTeller();

if ($this->getIsPaid() &&
$teller->greaterThan($this->getTotalPrice(), 0) &&
$teller->greaterThan($this->getTotalPaid(), $this->getTotalPrice())
$this->_getTeller()->greaterThan($this->getTotalPrice(), 0) &&
$this->_getTeller()->greaterThan($this->getTotalPaid(), $this->getTotalPrice())
) {
return self::PAID_STATUS_OVERPAID;
}
Expand All @@ -2605,7 +2603,7 @@ public function getPaidStatus(): string
return self::PAID_STATUS_PAID;
}

if ($this->getTotalPaid() > 0) {
if ($this->_getTeller()->greaterThan($this->getTotalPaid(), 0)) {
return self::PAID_STATUS_PARTIAL;
}

Expand Down Expand Up @@ -2726,7 +2724,7 @@ public function getOutstandingBalance(): float
*/
public function hasOutstandingBalance(): bool
{
return $this->getOutstandingBalance() > 0;
return $this->_getTeller()->greaterThan($this->getOutstandingBalance(), 0);
}

/**
Expand Down
Loading