Skip to content

Commit

Permalink
Merge branch '5.x' into 5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
nfourtythree committed Dec 4, 2024
2 parents c69ca44 + 0c70bfa commit b347d13
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release Notes for Craft Commerce

## Unreleased

- Fixed a bug where draft purchasables would show up on the Inventory page.
- Fixed a PHP error that could occur when creating inventory transfers.
- Fixed a bug where the price was not formatted correctly according to the locale in the payment model on the Order Edit screens. ([#3789](https://github.com/craftcms/commerce/issues/3789))

## 5.2.7 - 2024-11

- Fixed an error that occurred on the Orders index page when running Craft CMS 5.5.4 or later. ([#3793](https://github.com/craftcms/commerce/issues/3793))
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/InventoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ public function actionInventoryLevelsTableData(): Response
$inventoryQuery->leftJoin(['purchasables' => Table::PURCHASABLES], '[[ii.purchasableId]] = [[purchasables.id]]');
$inventoryQuery->addGroupBy(['[[purchasables.description]]', '[[purchasables.sku]]']);

$inventoryQuery->andWhere(['not', ['elements.id' => null]]);

if ($search) {
$inventoryQuery->andWhere(['or', ['like', 'purchasables.description', $search], ['like', 'purchasables.sku', $search]]);
}
Expand Down
6 changes: 5 additions & 1 deletion src/controllers/OrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1236,12 +1236,16 @@ public function actionPaymentAmountData(): Response
$paymentCurrencies = Plugin::getInstance()->getPaymentCurrencies();
$paymentCurrency = $this->request->getRequiredParam('paymentCurrency');
$paymentAmount = $this->request->getRequiredParam('paymentAmount');
$locale = $this->request->getRequiredParam('locale');
$orderId = $this->request->getRequiredParam('orderId');
/** @var Order $order */
$order = Order::find()->id($orderId)->one();
$baseCurrency = $order->currency;

$baseCurrencyPaymentAmount = $paymentCurrencies->convertCurrency($paymentAmount, $paymentCurrency, $baseCurrency);
$paymentAmount = MoneyHelper::toMoney(['value' => $paymentAmount, 'currency' => $baseCurrency, 'locale' => $locale]);
$paymentAmount = MoneyHelper::toDecimal($paymentAmount);

$baseCurrencyPaymentAmount = $paymentCurrencies->convertCurrency((float)$paymentAmount, $paymentCurrency, $baseCurrency);
$baseCurrencyPaymentAmountAsCurrency = Craft::t('commerce', 'Pay {amount} of {currency} on the order.', ['amount' => Currency::formatAsCurrency($baseCurrencyPaymentAmount, $baseCurrency), 'currency' => $baseCurrency]);

$outstandingBalance = $order->outstandingBalance;
Expand Down
16 changes: 14 additions & 2 deletions src/elements/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,18 @@ public function getVariants(bool $includeDisabled = false): VariantCollection
return $this->_variants->filter(fn(Variant $variant) => $includeDisabled || ($variant->getStatus() === self::STATUS_ENABLED));
}

/**
* @return VariantCollection
* @throws InvalidConfigException
* @internal Do not use. Temporary method until we get a nested element manager provider in core.
*
* TODO: Remove this once we have a nested element manager provider interface in core.
*/
public function getAllVariants(): VariantCollection
{
return $this->getVariants(true);
}

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -1187,9 +1199,9 @@ public function getVariantManager(): NestedElementManager
/** @phpstan-ignore-next-line */
fn(Product $product) => self::createVariantQuery($product),
[
'attribute' => 'variants',
'attribute' => 'allVariants', // TODO: can change this back to 'variants' once we have a nested element manager provider in core.
'propagationMethod' => $this->getType()->propagationMethod,
'valueGetter' => fn(Product $product) => $product->getVariants(true),
'valueSetter' => fn($variants) => $this->setVariants($variants), // TODO: can change this back to 'variants' once we have a nested element manager provider in core.
],
);
}
Expand Down
7 changes: 6 additions & 1 deletion src/services/Inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ public function getInventoryLocationLevels(InventoryLocation $inventoryLocation,
{
$levels = $this->getInventoryLevelQuery(withTrashed: $withTrashed)
->andWhere(['inventoryLocationId' => $inventoryLocation->id])
->andWhere(['not', ['elements.id' => null]])
->collect();

$inventoryItems = Plugin::getInstance()->getInventory()->getInventoryItemsByIds($levels->pluck('inventoryItemId')->unique()->toArray());
Expand Down Expand Up @@ -262,8 +263,12 @@ public function getInventoryLevelQuery(?int $limit = null, ?int $offset = null,
->limit($limit)
->offset($offset);

$query->leftJoin(
['elements' => CraftTable::ELEMENTS],
'[[ii.purchasableId]] = [[elements.id]] AND [[elements.draftId]] IS NULL AND [[elements.revisionId]] IS NULL'
);

if (!$withTrashed) {
$query->leftJoin(['elements' => CraftTable::ELEMENTS], '[[ii.purchasableId]] = [[elements.id]]');
$query->andWhere(['elements.dateDeleted' => null]);
}

Expand Down
1 change: 1 addition & 0 deletions src/services/InventoryLocations.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ private function _createInventoryLocationsQuery(bool $withTrashed = false): Quer
'dateCreated',
'dateUpdated',
])
->orderBy(['name' => SORT_ASC])
->from([Table::INVENTORYLOCATIONS]);

if (!$withTrashed) {
Expand Down
14 changes: 11 additions & 3 deletions src/templates/_components/gateways/_modalWrapper.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@
{{ formHtml|raw }}

<fieldset>
<legend>Payment Amount</legend>
<legend>{{ "Payment Amount"|t('commerce') }}</legend>
<div>
<input type="text" class="paymentAmount text" name="paymentAmount" autocomplete="off" placeholder="{{ order.outstandingBalance }}" step="any" min="1" max="{{ order.outstandingBalance }}" value="{{ order.getPaymentAmount() }}" style="margin: 0 0 0 5px; width:{{ 65 + (10*order.outstandingBalance|length) }}px;">
<input type="hidden" name="paymentAmount[locale]" value="{{ craft.app.formattingLocale.id }}" />
<input type="text" class="paymentAmount text"
name="paymentAmount[value]"
autocomplete="off"
placeholder="{{ order.outstandingBalance }}"
step="any" min="1" max="{{ order.outstandingBalance }}"
value="{{ order.getPaymentAmount() }}" style="margin: 0 0 0 5px; width:{{ 65 + (10*order.outstandingBalance|length) }}px;">

{% set currencies = craft.commerce.paymentCurrencies.getAllPaymentCurrencies() %}
{% set primaryCurrency = craft.commerce.paymentCurrencies.getPrimaryPaymentCurrency() %}
Expand Down Expand Up @@ -77,7 +83,8 @@


function updatePrice(form) {
var price = form.find("input.paymentAmount").val();
var price = form.find("input[name='paymentAmount[value]']").val();
var locale = form.find("input[name='paymentAmount[locale]']").val();

$.ajax({
type: "POST",
Expand All @@ -89,6 +96,7 @@
data: {
'action' : 'commerce/orders/payment-amount-data',
'paymentAmount': price,
'locale': locale,
'paymentCurrency': form.find(".paymentCurrency").val(),
'orderId' : orderId
},
Expand Down

0 comments on commit b347d13

Please sign in to comment.