Skip to content

Commit 47bf868

Browse files
committed
Merge branch 'feature/additional-attributes' into develop
2 parents 00ed797 + d5c729e commit 47bf868

File tree

9 files changed

+318
-0
lines changed

9 files changed

+318
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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\Observer;
7+
8+
use Magento\Framework\Event\ObserverInterface;
9+
use Magento\Config\Model\Config\Source\Yesno;
10+
11+
/**
12+
* Class AddProductAttributeVisibleCheckoutObserver
13+
*
14+
* @package FireGento\MageSetup\Observer
15+
*/
16+
class AddProductAttributeVisibleCheckoutObserver implements ObserverInterface
17+
{
18+
/**
19+
* @var Yesno
20+
*/
21+
private $yesNo;
22+
23+
/**
24+
* AddProductAttributeVisibleCheckoutObserver constructor.
25+
*
26+
* @param Yesno $yesNo
27+
*/
28+
public function __construct(Yesno $yesNo)
29+
{
30+
$this->yesNo = $yesNo;
31+
}
32+
33+
/**
34+
* lala
35+
*
36+
* @param \Magento\Framework\Event\Observer $observer
37+
* @return void
38+
*/
39+
public function execute(\Magento\Framework\Event\Observer $observer)
40+
{
41+
/** @var \Magento\Framework\Data\Form $form */
42+
$form = $observer->getEvent()->getData('form');
43+
44+
/** @var \Magento\Framework\Data\Form\Element\Fieldset $fieldset */
45+
$fieldset = $form->getElement('front_fieldset');
46+
47+
$fieldset->addField(
48+
'is_visible_on_checkout',
49+
'select',
50+
[
51+
'name' => 'is_visible_on_checkout',
52+
'label' => __('Visible in Checkout'),
53+
'title' => __('Visible in Checkout'),
54+
'values' => $this->yesNo->toOptionArray(),
55+
]
56+
);
57+
}
58+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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\Model\Attribute;
7+
8+
use \FireGento\MageSetup\Service\GetVisibleCheckoutAttributesServiceInterface;
9+
10+
/**
11+
* Class AroundGetAttributeNamesPlugin
12+
*
13+
* @package FireGento\MageSetup\Plugin\Catalog\Model\Attribute
14+
*/
15+
class AroundGetAttributeNamesPlugin
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\Model\Attribute\Config $subject
34+
* @param \Closure $proceed
35+
* @param string $groupName
36+
* @return array
37+
*/
38+
public function aroundGetAttributeNames(\Magento\Catalog\Model\Attribute\Config $subject, \Closure $proceed, $groupName)
39+
{
40+
$attributeNames = $proceed($groupName);
41+
42+
if ($groupName == 'quote_item') {
43+
$attributes = $this->getVisibleCheckoutAttributesService->execute();
44+
foreach ($attributes as $attributeCode => $attributeLabel) {
45+
$attributeNames[] = $attributeCode;
46+
}
47+
}
48+
49+
return $attributeNames;
50+
}
51+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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\Service;
7+
8+
/**
9+
* Class GetVisibleCheckoutAttributesService
10+
*
11+
* @package FireGento\MageSetup\Service
12+
*/
13+
class GetVisibleCheckoutAttributesService implements GetVisibleCheckoutAttributesServiceInterface
14+
{
15+
/**
16+
* @var \Magento\Catalog\Api\ProductAttributeRepository
17+
*/
18+
private $productAttributeRepository;
19+
/**
20+
* @var \Magento\Framework\Api\SearchCriteriaBuilder
21+
*/
22+
private $searchCriteriaBuilder;
23+
24+
/**
25+
* GetVisibleCheckoutAttributesService constructor.
26+
*
27+
* @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $productAttributeRepository
28+
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
29+
*/
30+
public function __construct(
31+
\Magento\Catalog\Api\ProductAttributeRepositoryInterface $productAttributeRepository,
32+
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
33+
) {
34+
$this->productAttributeRepository = $productAttributeRepository;
35+
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
36+
}
37+
38+
/**
39+
* @return array|bool
40+
*/
41+
public function execute()
42+
{
43+
$searchCriteria = $this->searchCriteriaBuilder->addFilter('is_visible_on_checkout', 1)->create();
44+
$attributes = $this->productAttributeRepository->getList($searchCriteria);
45+
46+
$options = [];
47+
if (count($attributes->getItems()) > 0) {
48+
foreach ($attributes->getItems() as $attribute) {
49+
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $handle */
50+
51+
$options[$attribute->getAttributeCode()] = $attribute->getDefaultFrontendLabel();
52+
}
53+
}
54+
55+
return $options;
56+
}
57+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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\Service;
7+
8+
/**
9+
* Interface GetVisibleCheckoutAttributesServiceInterface
10+
*
11+
* @package FireGento\MageSetup\Service
12+
*/
13+
interface GetVisibleCheckoutAttributesServiceInterface
14+
{
15+
/**
16+
* @return array|bool
17+
*/
18+
public function execute();
19+
}

Setup/InstallSchema.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace FireGento\MageSetup\Setup;
4+
5+
use Magento\Framework\Setup\InstallSchemaInterface;
6+
use Magento\Framework\Setup\SchemaSetupInterface;
7+
use Magento\Framework\Setup\ModuleContextInterface;
8+
9+
/**
10+
* Class InstallSchema
11+
*
12+
* @package FireGento\MageSetup\Setup
13+
* @codeCoverageIgnore
14+
*/
15+
class InstallSchema implements InstallSchemaInterface
16+
{
17+
/**
18+
* {@inheritdoc}
19+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
20+
*/
21+
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
22+
{
23+
$installer = $setup;
24+
$installer->startSetup();
25+
26+
$installer->getConnection()->addColumn(
27+
$installer->getTable('catalog_eav_attribute'),
28+
'is_visible_on_checkout',
29+
[
30+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
31+
'unsigned' => true,
32+
'nullable' => false,
33+
'default' => '0',
34+
'comment' => 'Is Visible On Checkout'
35+
]
36+
);
37+
38+
$installer->endSetup();
39+
}
40+
}

etc/adminhtml/events.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 FireGento e.V. - All rights reserved.
5+
* See LICENSE.md bundled with this module for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
9+
<event name="adminhtml_catalog_product_attribute_edit_frontend_prepare_form">
10+
<observer name="product_attribute_form" instance="FireGento\MageSetup\Observer\AddProductAttributeVisibleCheckoutObserver" />
11+
</event>
12+
</config>

etc/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<preference for="FireGento\MageSetup\Service\GetVisibleCheckoutAttributesServiceInterface" type="FireGento\MageSetup\Service\GetVisibleCheckoutAttributesService"/>
10+
911
<type name="FireGento\MageSetup\Model\Config\Reader">
1012
<arguments>
1113
<argument name="fileName" xsi:type="string">magesetup.xml</argument>

etc/frontend/di.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 FireGento e.V. - All rights reserved.
5+
* See LICENSE.md bundled with this module for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\Catalog\Helper\Product\Configuration">
10+
<plugin name="mageSetupCustomOptions" type="FireGento\MageSetup\Plugin\Catalog\Helper\Product\Configuration\AroundGetCustomOptionsPlugin" sortOrder="1"/>
11+
</type>
12+
<type name="Magento\Catalog\Model\Attribute\Config">
13+
<plugin name="mageSetupAddCustomQuoteItemAttributes" type="FireGento\MageSetup\Plugin\Catalog\Model\Attribute\AroundGetAttributeNamesPlugin" sortOrder="1"/>
14+
</type>
15+
</config>

0 commit comments

Comments
 (0)