-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add is_purchasable & can_show_price attributes
- Loading branch information
1 parent
9463c72
commit b3fcabd
Showing
7 changed files
with
135 additions
and
26 deletions.
There are no files selected for viewing
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
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,99 @@ | ||
<?php | ||
/** | ||
* Copyright © OpenGento, All rights reserved. | ||
* See LICENSE bundled with this library for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Opengento\Saleable\Setup\Patch\Data; | ||
|
||
use Magento\Catalog\Model\Product; | ||
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface; | ||
use Magento\Eav\Setup\EavSetupFactory; | ||
use Magento\Eav\Setup\EavSetup; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Setup\ModuleDataSetupInterface; | ||
use Magento\Framework\Setup\Patch\DataPatchInterface; | ||
use Zend_Validate_Exception; | ||
|
||
final class ProductAttributes implements DataPatchInterface | ||
{ | ||
private ModuleDataSetupInterface $moduleDataSetup; | ||
|
||
private EavSetupFactory $eavSetupFactory; | ||
|
||
public function __construct( | ||
ModuleDataSetupInterface $moduleDataSetup, | ||
EavSetupFactory $eavSetupFactory | ||
) { | ||
$this->moduleDataSetup = $moduleDataSetup; | ||
$this->eavSetupFactory = $eavSetupFactory; | ||
} | ||
|
||
/** | ||
* @throws Zend_Validate_Exception | ||
* @throws LocalizedException | ||
*/ | ||
public function apply() | ||
{ | ||
$this->moduleDataSetup->startSetup(); | ||
|
||
/** @var EavSetup $eavSetup */ | ||
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); | ||
|
||
$eavSetup->addAttribute(Product::ENTITY, 'is_purchasable', [ | ||
'type' => 'int', | ||
'backend' => '', | ||
'frontend' => '', | ||
'label' => 'Is Salable', | ||
'input' => 'boolean', | ||
'class' => '', | ||
'source' => '', | ||
'global' => ScopedAttributeInterface::SCOPE_STORE, | ||
'visible' => true, | ||
'required' => true, | ||
'user_defined' => false, | ||
'default' => true, | ||
'searchable' => false, | ||
'filterable' => false, | ||
'comparable' => false, | ||
'visible_on_front' => false, | ||
'used_in_product_listing' => true, | ||
'unique' => false, | ||
'apply_to' => '', | ||
]); | ||
$eavSetup->addAttribute(Product::ENTITY, 'can_show_price', [ | ||
'type' => 'int', | ||
'backend' => '', | ||
'frontend' => '', | ||
'label' => 'Show Price', | ||
'input' => 'boolean', | ||
'class' => '', | ||
'source' => '', | ||
'global' => ScopedAttributeInterface::SCOPE_STORE, | ||
'visible' => true, | ||
'required' => true, | ||
'user_defined' => false, | ||
'default' => true, | ||
'searchable' => false, | ||
'filterable' => false, | ||
'comparable' => false, | ||
'visible_on_front' => false, | ||
'used_in_product_listing' => true, | ||
'unique' => false, | ||
'apply_to' => '', | ||
]); | ||
|
||
$this->moduleDataSetup->endSetup(); | ||
} | ||
|
||
public function getAliases(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public static function getDependencies(): array | ||
{ | ||
return []; | ||
} | ||
} |
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 © OpenGento, All rights reserved. | ||
* See LICENSE bundled with this library 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\Framework\Pricing\SaleableInterface"> | ||
<plugin name="Opengento_Saleable::isSaleable" type="Opengento\Saleable\Plugin\Pricing\CanShowPrice" sortOrder="10"/> | ||
</type> | ||
<type name="Magento\Catalog\Model\Product"> | ||
<plugin name="Opengento_Saleable::getCanShowPrice" type="Opengento\Saleable\Plugin\Saleable\CanShowPrice" sortOrder="10"/> | ||
</type> | ||
</config> |
File renamed without changes.