Skip to content

[5.x] Reports #3628

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

Draft
wants to merge 41 commits into
base: 5.x
Choose a base branch
from
Draft
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
655490b
Start WIP release notes
lukeholder Aug 15, 2024
a5826f0
Merge branch '5.3' into feature/reports
lukeholder Nov 13, 2024
19aba08
remove
lukeholder Nov 13, 2024
3469ae4
Merge branch '5.3' into feature/reports
lukeholder Nov 13, 2024
c5ee466
WIP
lukeholder Nov 13, 2024
b610e23
Start 5.4 release notes
lukeholder Jan 31, 2025
4d262e6
Merge branch '5.x' into 5.4
lukeholder Feb 6, 2025
84df8fe
Merge branch '5.x' into 5.4
nfourtythree Feb 10, 2025
8d4188b
Update workflow
nfourtythree Feb 10, 2025
168bc61
Merge branch '5.x' into 5.4
nfourtythree Mar 3, 2025
6df935c
WIP
lukeholder Mar 5, 2025
c3cd6bb
Merge branch '5.4' into feature/com-223-gateway-condition-rules
lukeholder Mar 13, 2025
6a076f2
Merge branch '5.x' into 5.4
lukeholder Mar 13, 2025
81fdb91
Merge branch '5.4' into feature/com-223-gateway-condition-rules
lukeholder Mar 14, 2025
7ee203f
Merge branch '5.x' into 5.4
lukeholder Mar 14, 2025
fa8dc96
Merge branch '5.4' into feature/com-223-gateway-condition-rules
lukeholder Mar 14, 2025
392b49f
Finish gateway order condition
lukeholder Mar 14, 2025
c457fbd
Release notes
lukeholder Mar 14, 2025
c05167e
Cleanup
lukeholder Mar 14, 2025
0deacff
Cleanup
lukeholder Mar 17, 2025
24cd3c2
centralize the gateway config creation
lukeholder Mar 17, 2025
502cecf
Cleanup
lukeholder Mar 17, 2025
333509c
Cleanup
lukeholder Mar 17, 2025
cb81228
Merge branch '5.4' into feature/reports
lukeholder Mar 27, 2025
ed22442
WIP
lukeholder Mar 27, 2025
d5ae40d
WIP
lukeholder Mar 27, 2025
69de98e
Merge branch '5.x' into 5.4
nfourtythree Apr 1, 2025
5879d72
Fixed translations typo
nfourtythree Apr 1, 2025
e7e1812
Merge branch '5.x' into 5.4
nfourtythree Apr 3, 2025
4671abd
Add #3953 ability to set variant status from the product edit screen
nfourtythree Apr 4, 2025
17b7366
Merge pull request #3962 from craftcms/feature/pt-2700-54-add-set-sta…
lukeholder Apr 14, 2025
e81d794
Merge branch '5.4' into feature/com-223-gateway-condition-rules
lukeholder Apr 14, 2025
d958dda
Merge pull request #3940 from craftcms/feature/com-223-gateway-condit…
lukeholder Apr 14, 2025
9b66c38
Methods not needed
nfourtythree Apr 14, 2025
1e0ca49
Merge branch '5.4' into feature/reports
lukeholder Apr 15, 2025
1b6e6e3
Changelog tweaks
brandonkelly Apr 15, 2025
cd6ce15
Finish 5.3.9
nfourtythree Apr 15, 2025
79e457b
Merge branch '5.x' into 5.4
nfourtythree Apr 15, 2025
210ed9f
Merge branch '5.4' into feature/reports
lukeholder Apr 16, 2025
3b6d44b
WIP
lukeholder Apr 16, 2025
aadfa43
WIP
lukeholder Apr 16, 2025
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ on:
push:
branches:
- '5.x'
- '5.4'
pull_request:
permissions:
contents: read
17 changes: 17 additions & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Release Notes for Craft Commerce 5.4 (WIP)

### Store Management
- It is now possible to set a variant’s status from the Product Edit screen. ([#3953](https://github.com/craftcms/commerce/discussions/3953))
- Added an Order condition builder to gateways. ([#3913](https://github.com/craftcms/commerce/discussions/3913))

### Extensibility
- Added `craft\commerce\base\Gateway::setOrderCondition()`.
- Added `craft\commerce\base\Gateway::getOrderCondition()`.
- Added `craft\commerce\base\Gateway::getConfig()`.
- Added `craft\commerce\base\Gateway::hasOrderCondition()`.

### System
- Fixed a bug where gateway settings weren’t storing project config values consistently. ([#3941](https://github.com/craftcms/commerce/issues/3941))



6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Release Notes for Craft Commerce

## Unreleased
## 5.3.9 - 2025-04-15

- Fixed a bug where the customer selection UI was being hidden on the Edit Order page. ([#3968](https://github.com/craftcms/commerce/issues/3968))
- Fixed a bug where the customer selection menu on Edit Order pgaes could be hidden behind an address card. ([#3968](https://github.com/craftcms/commerce/issues/3968))
- Fixed a PHP error that could occur when rendering a PDF. ([#3967](https://github.com/craftcms/commerce/issues/3967))
- Fixed a bug where the account activation email template wasn’t always getting rendered in the correct site.
- Fixed a bug where account activation emails weren’t always getting rendered for the correct site.

## 5.3.8 - 2025-04-02

10 changes: 10 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
@@ -83,6 +83,7 @@
use craft\commerce\services\Products;
use craft\commerce\services\ProductTypes;
use craft\commerce\services\Purchasables;
use craft\commerce\services\Reports;
use craft\commerce\services\Sales;
use craft\commerce\services\ShippingCategories;
use craft\commerce\services\ShippingMethods;
@@ -218,6 +219,7 @@ public static function config(): array
'productTypes' => ['class' => ProductTypes::class],
'products' => ['class' => Products::class],
'purchasables' => ['class' => Purchasables::class],
'reports' => ['class' => Reports::class],
'sales' => ['class' => Sales::class],
'shippingCategories' => ['class' => ShippingCategories::class],
'shippingMethods' => ['class' => ShippingMethods::class],
@@ -391,6 +393,13 @@ public function getCpNavItem(): ?array
];
}

if ($userService->checkPermission('commerce-manageReporting')) {
$ret['subnav']['reporting'] = [
'label' => Craft::t('commerce', 'Reporting'),
'url' => 'commerce/reporting',
];
}

if (Craft::$app->getUser()->checkPermission('commerce-manageInventoryStockLevels')) {
$ret['subnav']['inventory'] = [
'label' => Craft::t('commerce', 'Inventory'),
@@ -599,6 +608,7 @@ private function _registerPermissions(): void

],
],
'commerce-manageReporting' => ['label' => Craft::t('commerce', 'Manage reporting')],
'commerce-manageSubscriptions' => ['label' => Craft::t('commerce', 'Manage subscriptions')],
'commerce-manageSubscriptionPlans' => ['label' => Craft::t('commerce', 'Manage subscription plans')],
'commerce-manageInventoryStockLevels' => ['label' => Craft::t('commerce', 'Manage inventory stock levels')],
88 changes: 87 additions & 1 deletion src/base/Gateway.php
Original file line number Diff line number Diff line change
@@ -9,9 +9,13 @@

use Craft;
use craft\base\SavableComponent;
use craft\commerce\elements\conditions\orders\DiscountOrderCondition;
use craft\commerce\elements\conditions\orders\GatewayOrderCondition;
use craft\commerce\elements\Order;
use craft\commerce\models\payments\BasePaymentForm;
use craft\commerce\models\Transaction;
use craft\elements\conditions\ElementConditionInterface;
use craft\helpers\Json;
use craft\helpers\StringHelper;
use craft\helpers\UrlHelper;

@@ -32,6 +36,12 @@ abstract class Gateway extends SavableComponent implements GatewayInterface
{
use GatewayTrait;

/**
* @var ElementConditionInterface|null
* @since 5.4.0
*/
private ?ElementConditionInterface $_orderCondition = null;

/**
* Returns the name of this payment method.
*
@@ -103,7 +113,7 @@ public function defineRules(): array
$rules = parent::defineRules();
$rules[] = [['paymentType', 'handle'], 'required'];

$rules[] = [['name', 'handle', 'paymentType', 'isFrontendEnabled', 'sortOrder'], 'safe'];
$rules[] = [['name', 'handle', 'paymentType', 'isFrontendEnabled', 'orderCondition', 'sortOrder'], 'safe'];

return $rules;
}
@@ -124,6 +134,10 @@ public function getPaymentConfirmationFormHtml(array $params): string
*/
public function availableForUseWithOrder(Order $order): bool
{
if ($this->hasOrderCondition() && !$this->getOrderCondition()->matchElement($order)) {
return false;
}

return true;
}

@@ -135,6 +149,16 @@ public function supportsPartialPayment(): bool
return true;
}

/**
* Returns true if this gateway has an order condition
*
* @since 5.4.0
*/
public function hasOrderCondition(): bool
{
return $this->getOrderCondition()->getConditionRules() !== [];
}

/**
* Returns payment Form HTML
*/
@@ -157,4 +181,66 @@ public function transactionSupportsRefund(Transaction $transaction): bool
{
return true;
}


/**
* Gets the order condition for this gateway
*
* @since 5.4.0
*/
public function getOrderCondition(): ElementConditionInterface
{
/** @var DiscountOrderCondition $condition */
$condition = $this->_orderCondition ?? new GatewayOrderCondition();
$condition->mainTag = 'div';
$condition->name = 'orderCondition';

return $condition;
}

/**
* Sets the order condition for this gateway
*
* @since 5.4.0
*/
public function setOrderCondition(ElementConditionInterface|string|array $condition): void
{
if (empty($condition)) {
$this->_orderCondition = null;
return;
}

if (is_string($condition)) {
$condition = Json::decodeIfJson($condition);
}

if (!$condition instanceof GatewayOrderCondition) {
$condition['class'] = GatewayOrderCondition::class;
/** @var GatewayOrderCondition $condition */
$condition = \Craft::$app->getConditions()->createCondition($condition);
}
$condition->forProjectConfig = true;

$this->_orderCondition = $condition;
}

/**
* @return array
* @since 5.4.0
*/
public function getConfig(): array
{
$configData = [
'name' => $this->name,
'handle' => $this->handle,
'type' => get_class($this),
'settings' => $this->getSettings(),
'sortOrder' => ($this->sortOrder ?? 99),
'paymentType' => $this->paymentType,
'isFrontendEnabled' => $this->getIsFrontendEnabled(false),
'orderCondition' => $this->getOrderCondition()->getConfig(),
];

return $configData;
}
}
Loading