Skip to content

Commit

Permalink
Merge pull request #431 from AcclaroInc/release/3.2.5
Browse files Browse the repository at this point in the history
Release/3.2.5
  • Loading branch information
bhupeshappfoster authored Apr 15, 2023
2 parents 636fbb3 + 15b11f6 commit 33bc2df
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .craftplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"pluginName": "Translations for Craft",
"pluginDescription": "Drive global growth with simplified translation workflows.",
"pluginVersion": "3.2.4",
"pluginVersion": "3.2.5",
"pluginAuthorName": "Acclaro",
"pluginVendorName": "Acclaro",
"pluginAuthorUrl": "http://www.acclaro.com/",
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 3.2.5 - 2023-04-15

### Fixed
- An issue where merging changes to draft throwing error when commerce product/variant are referenced inside another commerce product/variant.

## 3.2.4 - 2023-04-05

### Fixed
Expand Down
14 changes: 13 additions & 1 deletion src/services/ElementTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use acclaro\translations\Constants;
use acclaro\translations\Translations;
use craft\commerce\elements\Product;
use craft\fields\Color;

class ElementTranslator
{
Expand Down Expand Up @@ -164,7 +165,18 @@ public function toPostArrayFromTranslationTarget(Element $element, $sourceSite,
$translator = Translations::$plugin->fieldTranslatorFactory->makeTranslator($fieldType);

if (!$translator) {
if ($includeNonTranslatable) {
// @TODO: Might need to move these check to seprate class to fetch nested content of variants
if ($field instanceof Color) {
$post[$fieldHandle] = $element->getFieldValue($fieldHandle)?->getHex() ?? '';
} elseif (in_array(get_class($field), ['craft\commerce\fields\Variants', 'craft\commerce\fields\Products'])) {
if (! isset($post[$fieldHandle])) {
$post[$fieldHandle] = [];
}

foreach ($element->getFieldValue($fieldHandle)->all() as $variant) {
array_push($post[$fieldHandle], $variant->id);
}
} elseif ($includeNonTranslatable) {
$post[$fieldHandle] = $element->$fieldHandle;
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/repository/CommerceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function publishDraft(Product $draft)
$product->setFieldValues($post);
$product->setVariants($draft->getVariants(true));

$success = Craft::$app->elements->saveElement($product);
$success = Craft::$app->elements->saveElement($product, false);

if (!$success) {
Translations::$plugin->logHelper->log('[' . __METHOD__ . '] Couldn’t publish draft "' . $draft->title . '"', Constants::LOG_LEVEL_ERROR);
Expand Down

0 comments on commit 33bc2df

Please sign in to comment.