Skip to content

Commit

Permalink
Merge branch '5.x' into 5.1
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
nfourtythree committed Aug 16, 2024
2 parents 92ebaab + 40a99e7 commit 37dfbed
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes for Craft Commerce

## Unreleased

- Fixed a bug where variants’ `sku` values could be cleared out when saving a product.
- Fixed a bug where `craft\commerce\elements\Product::getVariants()` wasn’t respecting variants’ site statuses.

## 5.1.0-beta.1 - 2024-08-14

### Store Management
Expand Down Expand Up @@ -69,6 +74,11 @@
### System
- Craft Commerce now requires Craft CMS 5.2 or later.

## 5.0.16.1 - 2024-08-16

- Fixed a bug where variants’ `sku` values could be cleared out when saving a product.
- Fixed a bug where `craft\commerce\elements\Product::getVariants()` wasn’t respecting variants’ site statuses.

## 5.0.16 - 2024-08-14

- It’s now possible to duplicate variants.
Expand Down
13 changes: 11 additions & 2 deletions src/base/Purchasable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Craft;
use craft\base\Element;
use craft\base\NestedElementInterface;
use craft\commerce\db\Table;
use craft\commerce\elements\Order;
use craft\commerce\errors\StoreNotFoundException;
Expand Down Expand Up @@ -918,8 +919,16 @@ public function afterSave(bool $isNew): void
{
$purchasableId = $this->getCanonicalId();
if (!$this->propagating) {
if ($this->duplicateOf !== null) {
$this->sku = \craft\commerce\helpers\Purchasable::tempSku() . '-' . $this->getSku();
$isOwnerDraftApplying = false;

// If this is a nested element, check if the owner is a draft and is being applied
if ($this instanceof NestedElementInterface) {
$owner = $this->getOwner();
$isOwnerDraftApplying = $owner && $owner->getIsCanonical() && $owner->duplicateOf !== null && $owner->duplicateOf->getIsDraft();
}

if ($this->duplicateOf !== null && !$isOwnerDraftApplying) {
$this->sku = PurchasableHelper::tempSku() . '-' . $this->getSku();
// Nullify inventory item so a new one is created
$this->inventoryItemId = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/elements/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ public function getVariants(bool $includeDisabled = false): VariantCollection
$this->_variants = self::createVariantQuery($this)->status(null)->collect();
}

return $this->_variants->filter(fn(Variant $variant) => $includeDisabled || $variant->enabled);
return $this->_variants->filter(fn(Variant $variant) => $includeDisabled || ($variant->getStatus() === self::STATUS_ENABLED));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{% for method in shippingMethods %}
{% set tableData = tableData|merge([{
id: method.id,
title: method.getName()|t('site')|e,
title: method.getName()|t('site'),
status: method.getIsEnabled(),
url: method.getCpEditUrl(),
handle: method.handle,
Expand Down

0 comments on commit 37dfbed

Please sign in to comment.