Skip to content
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

[FEATURE] display attribute value of child product in cart #214

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use FireGento\MageSetup\Service\GetVisibleCheckoutAttributesServiceInterface;
use Magento\Catalog\Helper\Product\Configuration;
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
use Magento\Quote\Model\Quote\Item\AbstractItem;

/**
* Plugin to add visible in checkout attributes to the custom option list.
Expand Down Expand Up @@ -42,8 +43,34 @@
public function afterGetCustomOptions(Configuration $configuration, array $customOptions, ItemInterface $item)
{
$attributes = $this->getVisibleCheckoutAttributesService->execute();

$configurableAttributes = $item->getOptionByCode('attributes') ? $item->getOptionByCode('attributes')->getValue() : [];

Check warning on line 47 in Plugin/Catalog/Helper/Product/Configuration/AddVisibleInCheckoutAttributesToCustomOptionsPlugin.php

View workflow job for this annotation

GitHub Actions / M2 Coding Standard

Line exceeds 120 characters; contains 127 characters
$configurableAttributes = $configurableAttributes ? array_keys(json_decode($configurableAttributes, true)) : [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not check how this is encoded, but most probably, we should use \Magento\Framework\Serialize\Serializer\Json instead of directly using json_decode?


$product = $item->getProduct();

if (!$product) {
return [];
}

foreach ($attributes as $attribute) {
$value = $attribute->getFrontend()->getValue($item->getProduct());
$attributeFrontend = $attribute->getFrontend();
$value = $attributeFrontend->getValue($product);

if ($item instanceof AbstractItem && $product->getTypeId() === 'configurable') {
if (in_array($attribute->getId(), $configurableAttributes) || !count($item->getChildren())) {
// attribute is a configurable attribute. Magento will print it separately
// or item has no children (but this should never occur)
continue;
}

$children = $item->getChildren();
if ($children[0] instanceof AbstractItem && $children[0]->getProduct()) {
// fetch the attribute value of the child
$value = $attributeFrontend->getValue($children[0]->getProduct()) ?: $value;
}
}

if (!$value) {
continue;
}
Expand Down
Loading