-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] #23 Add visible checkout attributes to frontend view (cart/…
…checkout)
- Loading branch information
Showing
6 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
Plugin/Catalog/Helper/Product/Configuration/AroundGetCustomOptionsPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 FireGento e.V. - All rights reserved. | ||
* See LICENSE.md bundled with this module for license details. | ||
*/ | ||
namespace FireGento\MageSetup\Plugin\Catalog\Helper\Product\Configuration; | ||
|
||
use \FireGento\MageSetup\Service\GetVisibleCheckoutAttributesServiceInterface; | ||
|
||
/** | ||
* Class AroundGetCustomOptionsPlugin | ||
* | ||
* @package FireGento\MageSetup\Plugin\Catalog\Helper\Product\Configuration | ||
*/ | ||
class AroundGetCustomOptionsPlugin | ||
{ | ||
/** | ||
* @var GetVisibleCheckoutAttributesServiceInterface | ||
*/ | ||
private $getVisibleCheckoutAttributesService; | ||
|
||
/** | ||
* AroundGetCustomOptionsPlugin constructor. | ||
* | ||
* @param GetVisibleCheckoutAttributesServiceInterface $getVisibleCheckoutAttributesService | ||
*/ | ||
public function __construct(GetVisibleCheckoutAttributesServiceInterface $getVisibleCheckoutAttributesService) | ||
{ | ||
$this->getVisibleCheckoutAttributesService = $getVisibleCheckoutAttributesService; | ||
} | ||
|
||
/** | ||
* @param \Magento\Catalog\Helper\Product\Configuration $subject | ||
* @param \Closure $proceed | ||
* @param \Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item | ||
* @return array | ||
*/ | ||
public function aroundGetCustomOptions( | ||
\Magento\Catalog\Helper\Product\Configuration $subject, | ||
\Closure $proceed, | ||
\Magento\Catalog\Model\Product\Configuration\Item\ItemInterface $item | ||
) | ||
{ | ||
$options = $proceed($item); | ||
|
||
$attributes = $this->getVisibleCheckoutAttributesService->execute(); | ||
if (count($attributes) > 0) { | ||
foreach ($attributes as $attributeCode => $attributeLabel) { | ||
$value = $item->getProduct()->getData($attributeCode); | ||
if (!$value) { | ||
continue; | ||
} | ||
|
||
$options[] = [ | ||
'label' => $attributeLabel, | ||
'value' => $value, | ||
'print_value' => $value | ||
]; | ||
} | ||
} | ||
|
||
return $options; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
Plugin/Catalog/Model/Attribute/AroundGetAttributeNamesPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 FireGento e.V. - All rights reserved. | ||
* See LICENSE.md bundled with this module for license details. | ||
*/ | ||
namespace FireGento\MageSetup\Plugin\Catalog\Model\Attribute; | ||
|
||
use \FireGento\MageSetup\Service\GetVisibleCheckoutAttributesServiceInterface; | ||
|
||
/** | ||
* Class AroundGetAttributeNamesPlugin | ||
* | ||
* @package FireGento\MageSetup\Plugin\Catalog\Model\Attribute | ||
*/ | ||
class AroundGetAttributeNamesPlugin | ||
{ | ||
/** | ||
* @var GetVisibleCheckoutAttributesServiceInterface | ||
*/ | ||
private $getVisibleCheckoutAttributesService; | ||
|
||
/** | ||
* AroundGetCustomOptionsPlugin constructor. | ||
* | ||
* @param GetVisibleCheckoutAttributesServiceInterface $getVisibleCheckoutAttributesService | ||
*/ | ||
public function __construct(GetVisibleCheckoutAttributesServiceInterface $getVisibleCheckoutAttributesService) | ||
{ | ||
$this->getVisibleCheckoutAttributesService = $getVisibleCheckoutAttributesService; | ||
} | ||
|
||
/** | ||
* @param \Magento\Catalog\Model\Attribute\Config $subject | ||
* @param \Closure $proceed | ||
* @param string $groupName | ||
* @return array | ||
*/ | ||
public function aroundGetAttributeNames(\Magento\Catalog\Model\Attribute\Config $subject, \Closure $proceed, $groupName) | ||
{ | ||
$attributeNames = $proceed($groupName); | ||
|
||
if ($groupName == 'quote_item') { | ||
$attributes = $this->getVisibleCheckoutAttributesService->execute(); | ||
foreach ($attributes as $attributeCode => $attributeLabel) { | ||
$attributeNames[] = $attributeCode; | ||
} | ||
} | ||
|
||
return $attributeNames; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 FireGento e.V. - All rights reserved. | ||
* See LICENSE.md bundled with this module for license details. | ||
*/ | ||
namespace FireGento\MageSetup\Service; | ||
|
||
/** | ||
* Class GetVisibleCheckoutAttributesService | ||
* | ||
* @package FireGento\MageSetup\Service | ||
*/ | ||
class GetVisibleCheckoutAttributesService implements GetVisibleCheckoutAttributesServiceInterface | ||
{ | ||
/** | ||
* @var \Magento\Catalog\Api\ProductAttributeRepository | ||
*/ | ||
private $productAttributeRepository; | ||
/** | ||
* @var \Magento\Framework\Api\SearchCriteriaBuilder | ||
*/ | ||
private $searchCriteriaBuilder; | ||
|
||
/** | ||
* GetVisibleCheckoutAttributesService constructor. | ||
* | ||
* @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $productAttributeRepository | ||
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder | ||
*/ | ||
public function __construct( | ||
\Magento\Catalog\Api\ProductAttributeRepositoryInterface $productAttributeRepository, | ||
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder | ||
) { | ||
$this->productAttributeRepository = $productAttributeRepository; | ||
$this->searchCriteriaBuilder = $searchCriteriaBuilder; | ||
} | ||
|
||
/** | ||
* @return array|bool | ||
*/ | ||
public function execute() | ||
{ | ||
$searchCriteria = $this->searchCriteriaBuilder->addFilter('is_visible_on_checkout', 1)->create(); | ||
$attributes = $this->productAttributeRepository->getList($searchCriteria); | ||
|
||
$options = []; | ||
if (count($attributes->getItems()) > 0) { | ||
foreach ($attributes->getItems() as $attribute) { | ||
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $handle */ | ||
|
||
$options[$attribute->getAttributeCode()] = $attribute->getDefaultFrontendLabel(); | ||
} | ||
} | ||
|
||
return $options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
/** | ||
* Copyright © 2015 FireGento e.V. - All rights reserved. | ||
* See LICENSE.md bundled with this module for license details. | ||
*/ | ||
namespace FireGento\MageSetup\Service; | ||
|
||
/** | ||
* Interface GetVisibleCheckoutAttributesServiceInterface | ||
* | ||
* @package FireGento\MageSetup\Service | ||
*/ | ||
interface GetVisibleCheckoutAttributesServiceInterface | ||
{ | ||
/** | ||
* @return array|bool | ||
*/ | ||
public function execute(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © 2015 FireGento e.V. - All rights reserved. | ||
* See LICENSE.md bundled with this module for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Catalog\Helper\Product\Configuration"> | ||
<plugin name="mageSetupCustomOptions" type="FireGento\MageSetup\Plugin\Catalog\Helper\Product\Configuration\AroundGetCustomOptionsPlugin" sortOrder="1"/> | ||
</type> | ||
<type name="Magento\Catalog\Model\Attribute\Config"> | ||
<plugin name="mageSetupAddCustomQuoteItemAttributes" type="FireGento\MageSetup\Plugin\Catalog\Model\Attribute\AroundGetAttributeNamesPlugin" sortOrder="1"/> | ||
</type> | ||
</config> |