123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Bundle\Setup\Patch\Data;
- use Magento\Framework\App\ResourceConnection;
- use Magento\Framework\Setup\ModuleDataSetupInterface;
- use Magento\Framework\Setup\Patch\DataPatchInterface;
- use Magento\Framework\Setup\Patch\PatchVersionInterface;
- use Magento\Eav\Setup\EavSetup;
- use Magento\Eav\Setup\EavSetupFactory;
- /**
- * Class ApplyAttributesUpdate
- * @package Magento\Bundle\Setup\Patch
- */
- class ApplyAttributesUpdate implements DataPatchInterface, PatchVersionInterface
- {
- /**
- * @var ModuleDataSetupInterface
- */
- private $moduleDataSetup;
- /**
- * @var EavSetupFactory
- */
- private $eavSetupFactory;
- /**
- * ApplyAttributesUpdate constructor.
- *
- * @param ModuleDataSetupInterface $moduleDataSetup
- * @param EavSetupFactory $eavSetupFactory
- */
- public function __construct(
- ModuleDataSetupInterface $moduleDataSetup,
- \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory
- ) {
- $this->moduleDataSetup = $moduleDataSetup;
- $this->eavSetupFactory = $eavSetupFactory;
- }
- /**
- * {@inheritdoc}
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- */
- public function apply()
- {
- /** @var EavSetup $eavSetup */
- $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
- $fieldList = [
- 'price',
- 'special_price',
- 'special_from_date',
- 'special_to_date',
- 'minimal_price',
- 'cost',
- 'tier_price',
- 'weight',
- ];
- foreach ($fieldList as $field) {
- $applyTo = explode(
- ',',
- $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $field, 'apply_to')
- );
- if (!in_array('bundle', $applyTo)) {
- $applyTo[] = 'bundle';
- $eavSetup->updateAttribute(
- \Magento\Catalog\Model\Product::ENTITY,
- $field,
- 'apply_to',
- implode(',', $applyTo)
- );
- }
- }
- $applyTo = explode(',', $eavSetup->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'cost', 'apply_to'));
- unset($applyTo[array_search('bundle', $applyTo)]);
- $eavSetup->updateAttribute(\Magento\Catalog\Model\Product::ENTITY, 'cost', 'apply_to', implode(',', $applyTo));
- /**
- * Add attributes to the eav/attribute
- */
- $eavSetup->addAttribute(
- \Magento\Catalog\Model\Product::ENTITY,
- 'price_type',
- [
- 'type' => 'int',
- 'backend' => '',
- 'frontend' => '',
- 'label' => '',
- 'input' => '',
- 'class' => '',
- 'source' => '',
- 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
- 'visible' => true,
- 'required' => true,
- 'user_defined' => false,
- 'default' => '',
- 'searchable' => false,
- 'filterable' => false,
- 'comparable' => false,
- 'visible_on_front' => false,
- 'used_in_product_listing' => true,
- 'unique' => false,
- 'apply_to' => 'bundle'
- ]
- );
- $eavSetup->addAttribute(
- \Magento\Catalog\Model\Product::ENTITY,
- 'sku_type',
- [
- 'type' => 'int',
- 'backend' => '',
- 'frontend' => '',
- 'label' => '',
- 'input' => '',
- 'class' => '',
- 'source' => '',
- 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
- 'visible' => false,
- 'required' => true,
- 'user_defined' => false,
- 'default' => '',
- 'searchable' => false,
- 'filterable' => false,
- 'comparable' => false,
- 'visible_on_front' => false,
- 'unique' => false,
- 'apply_to' => 'bundle'
- ]
- );
- $eavSetup->addAttribute(
- \Magento\Catalog\Model\Product::ENTITY,
- 'weight_type',
- [
- 'type' => 'int',
- 'backend' => '',
- 'frontend' => '',
- 'label' => '',
- 'input' => '',
- 'class' => '',
- 'source' => '',
- 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
- 'visible' => false,
- 'required' => true,
- 'user_defined' => false,
- 'default' => '',
- 'searchable' => false,
- 'filterable' => false,
- 'comparable' => false,
- 'visible_on_front' => false,
- 'used_in_product_listing' => true,
- 'unique' => false,
- 'apply_to' => 'bundle'
- ]
- );
- $eavSetup->addAttribute(
- \Magento\Catalog\Model\Product::ENTITY,
- 'price_view',
- [
- 'group' => 'Advanced Pricing',
- 'type' => 'int',
- 'backend' => '',
- 'frontend' => '',
- 'label' => 'Price View',
- 'input' => 'select',
- 'class' => '',
- 'source' => \Magento\Bundle\Model\Product\Attribute\Source\Price\View::class,
- 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
- 'visible' => true,
- 'required' => true,
- 'user_defined' => false,
- 'default' => '',
- 'searchable' => false,
- 'filterable' => false,
- 'comparable' => false,
- 'visible_on_front' => false,
- 'used_in_product_listing' => true,
- 'unique' => false,
- 'apply_to' => 'bundle'
- ]
- );
- $eavSetup->addAttribute(
- \Magento\Catalog\Model\Product::ENTITY,
- 'shipment_type',
- [
- 'type' => 'int',
- 'backend' => '',
- 'frontend' => '',
- 'label' => 'Shipment',
- 'input' => '',
- 'class' => '',
- 'source' => '',
- 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
- 'visible' => false,
- 'required' => true,
- 'user_defined' => false,
- 'default' => '',
- 'searchable' => false,
- 'filterable' => false,
- 'comparable' => false,
- 'visible_on_front' => false,
- 'used_in_product_listing' => true,
- 'unique' => false,
- 'apply_to' => 'bundle'
- ]
- );
- }
- /**
- * {@inheritdoc}
- */
- public static function getDependencies()
- {
- return [];
- }
- /**
- * {@inheritdoc}
- */
- public static function getVersion()
- {
- return '2.0.0';
- }
- /**
- * {@inheritdoc}
- */
- public function getAliases()
- {
- return [];
- }
- }
|