|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 FireGento e.V. - All rights reserved. |
| 4 | + * See LICENSE.md bundled with this module for license details. |
| 5 | + */ |
| 6 | +namespace FireGento\MageSetup\Plugin\Catalog\Helper\Product\Configuration; |
| 7 | + |
| 8 | +use \FireGento\MageSetup\Service\GetVisibleCheckoutAttributesServiceInterface; |
| 9 | + |
| 10 | +/** |
| 11 | + * Class AroundGetCustomOptionsPlugin |
| 12 | + * |
| 13 | + * @package FireGento\MageSetup\Plugin\Catalog\Helper\Product\Configuration |
| 14 | + */ |
| 15 | +class AroundGetCustomOptionsPlugin |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @var GetVisibleCheckoutAttributesServiceInterface |
| 19 | + */ |
| 20 | + private $getVisibleCheckoutAttributesService; |
| 21 | + |
| 22 | + /** |
| 23 | + * AroundGetCustomOptionsPlugin constructor. |
| 24 | + * |
| 25 | + * @param GetVisibleCheckoutAttributesServiceInterface $getVisibleCheckoutAttributesService |
| 26 | + */ |
| 27 | + public function __construct(GetVisibleCheckoutAttributesServiceInterface $getVisibleCheckoutAttributesService) |
| 28 | + { |
| 29 | + $this->getVisibleCheckoutAttributesService = $getVisibleCheckoutAttributesService; |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * @param \Magento\Catalog\Helper\Product\Configuration $subject |
| 34 | + * @param \Closure $proceed |
| 35 | + * @param \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item |
| 36 | + * @return array |
| 37 | + */ |
| 38 | + public function aroundGetCustomOptions( |
| 39 | + \Magento\Catalog\Helper\Product\Configuration $subject, |
| 40 | + \Closure $proceed, |
| 41 | + \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item |
| 42 | + ) |
| 43 | + { |
| 44 | + $options = $proceed($item); |
| 45 | + |
| 46 | + $attributes = $this->getVisibleCheckoutAttributesService->execute(); |
| 47 | + if (count($attributes) > 0) { |
| 48 | + foreach ($attributes as $attributeCode => $attributeLabel) { |
| 49 | + $value = $item->getProduct()->getData($attributeCode); |
| 50 | + if (!$value) { |
| 51 | + continue; |
| 52 | + } |
| 53 | + |
| 54 | + $options[] = [ |
| 55 | + 'label' => $attributeLabel, |
| 56 | + 'value' => $value, |
| 57 | + 'print_value' => $value |
| 58 | + ]; |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + return $options; |
| 63 | + } |
| 64 | +} |
0 commit comments