Skip to content

Commit

Permalink
[FEATURE] #23 Add 'is visible on checkout' option to backend attribut…
Browse files Browse the repository at this point in the history
…e mgmt
  • Loading branch information
therouv committed Jul 2, 2016
1 parent 00ed797 commit c51acb4
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Observer/AddProductAttributeVisibleCheckoutObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* Copyright © 2015 FireGento e.V. - All rights reserved.
* See LICENSE.md bundled with this module for license details.
*/
namespace FireGento\MageSetup\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Config\Model\Config\Source\Yesno;

/**
* Class AddProductAttributeVisibleCheckoutObserver
*
* @package FireGento\MageSetup\Observer
*/
class AddProductAttributeVisibleCheckoutObserver implements ObserverInterface
{
/**
* @var Yesno
*/
private $yesNo;

/**
* AddProductAttributeVisibleCheckoutObserver constructor.
*
* @param Yesno $yesNo
*/
public function __construct(Yesno $yesNo)
{
$this->yesNo = $yesNo;
}

/**
* lala
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
/** @var \Magento\Framework\Data\Form $form */
$form = $observer->getEvent()->getData('form');

/** @var \Magento\Framework\Data\Form\Element\Fieldset $fieldset */
$fieldset = $form->getElement('front_fieldset');

$fieldset->addField(
'is_visible_on_checkout',
'select',
[
'name' => 'is_visible_on_checkout',
'label' => __('Visible in Checkout'),
'title' => __('Visible in Checkout'),
'values' => $this->yesNo->toOptionArray(),
]
);
}
}
40 changes: 40 additions & 0 deletions Setup/InstallSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace FireGento\MageSetup\Setup;

use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;

/**
* Class InstallSchema
*
* @package FireGento\MageSetup\Setup
* @codeCoverageIgnore
*/
class InstallSchema implements InstallSchemaInterface
{
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$installer = $setup;
$installer->startSetup();

$installer->getConnection()->addColumn(
$installer->getTable('catalog_eav_attribute'),
'is_visible_on_checkout',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
'unsigned' => true,
'nullable' => false,
'default' => '0',
'comment' => 'Is Visible On Checkout'
]
);

$installer->endSetup();
}
}
12 changes: 12 additions & 0 deletions etc/adminhtml/events.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?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:Event/etc/events.xsd">
<event name="adminhtml_catalog_product_attribute_edit_frontend_prepare_form">
<observer name="product_attribute_form" instance="FireGento\MageSetup\Observer\AddProductAttributeVisibleCheckoutObserver" />
</event>
</config>

0 comments on commit c51acb4

Please sign in to comment.