Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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 CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Logged-in users who own the order or have appropriate permissions bypass the email verification flow and can download PDFs directly.
- Added a new system email message for sending PDF download links to customers.
- It is now possible to select multiple products in variant conditions. ([#4166](https://github.com/craftcms/commerce/pull/4166))
- Variants now include their owner products' title when being displayed in the control panel. ([#4155](https://github.com/craftcms/commerce/issues/4155))
- It is now possible to select multiple specific variants in pricing rule’s “Match Variant” condition. ([#4167](https://github.com/craftcms/commerce/issues/4167))
- It is now possible to select multiple specific users in pricing rule’s “Match Customer” condition. ([#4167](https://github.com/craftcms/commerce/issues/4167))

Expand Down
27 changes: 26 additions & 1 deletion src/elements/Variant.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,31 @@ public function init(): void
$this->ownerType = Product::class;
}

/**
* @inheritdoc
*/
public function getUiLabel(): string
{
$request = Craft::$app->getRequest();
$referrer = $request->getReferrer() ?? '';
$pathInfo = $request->getPathInfo();

$isCommerceProductContext = (
str_contains($pathInfo, 'commerce/products') ||
($request->getIsAjax() && str_contains($referrer, 'commerce/products'))
);

if ($isCommerceProductContext || !$this->owner) {
return parent::getUiLabel();
}

$labelParts = Craft::$app->getLocale()->getOrientation() === 'rtl'
? [parent::getUiLabel(), $this->owner->getUiLabel()]
: [$this->owner->getUiLabel(), parent::getUiLabel()];

return implode(' : ', $labelParts);
}

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -1181,7 +1206,7 @@ public function beforeSave(bool $isNew): bool
// Validate shipping category ID is available for this product type
$availableShippingCategories = $this->availableShippingCategories();
$availableShippingCategoryIds = ArrayHelper::getColumn($availableShippingCategories, 'id');

// If the current shipping category ID is not in the available categories, set it to the default one
$currentShippingCategoryId = $this->getShippingCategoryId();
if (!in_array($currentShippingCategoryId, $availableShippingCategoryIds)) {
Expand Down
Loading