Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <route url="/V1/attribute/AttributeOption" method="POST">
- <service class="VendorModuleApiAttributeInterface" method="AttributeOption"/>
- </route>
- <?php
- namespace VendorModuleApi;
- interface AttributeInterface
- {
- /**
- * POST for attribute api
- * @param mixed $param
- * @return array
- */
- public function AttributeOption($params);
- }
- <?php
- namespace VendorModuleModel;
- use VendorModuleApiAttributeInterface;
- use MagentoEavSetupEavSetupFactory;
- use MagentoStoreModelStoreManagerInterface;
- class Attribute implements AttributeInterface
- {
- protected $_eavSetupFactory;
- protected $_storeManager;
- protected $_attributeFactory;
- protected $eavAttributeFactory;
- protected $attributeOptionManagement;
- protected $productFactory;
- private $productAttributeRepository;
- protected $objectManager;
- public function __construct(
- MagentoFrameworkObjectManagerInterface $objectManager,
- MagentoEavSetupEavSetupFactory $eavSetupFactory,
- MagentoStoreModelStoreManagerInterface $storeManager,
- MagentoCatalogModelResourceModelEavAttribute $attributeFactory,
- MagentoEavModelEntityAttributeFactory $eavAttributeFactory,
- MagentoEavApiAttributeOptionManagementInterface $attributeOptionManagement,
- MagentoCatalogModelProductFactory $productFactory,
- MagentoCatalogModelProductAttributeRepository $productAttributeRepository
- ) {
- $this->_objectManager = $objectManager;
- $this->_eavSetupFactory = $eavSetupFactory;
- $this->_storeManager = $storeManager;
- $this->_attributeFactory = $attributeFactory;
- $this->eavAttributeFactory = $eavAttributeFactory;
- $this->attributeOptionManagement = $attributeOptionManagement;
- $this->productFactory = $productFactory;
- $this->productAttributeRepository = $productAttributeRepository;
- }
- public function AttributeOption($params) {
- // looking for logic to create / update options from request
- }
- }
- {
- "params":{
- "Type": "create",
- "attribute_id" : "159",
- "OptionValues": [
- {
- "OptionId": "01",
- "OptionName": "Test"
- },
- {
- "OptionId": "Null",
- "OptionName" : "Test2"
- }
- ]
- }
- }
- $OptionValues = json_decode('{"params":{"Type": "create", "attribute_id" : "159", "OptionValues": [{ "OptionId": "01", "OptionName": "Test"}, { "OptionId": "Null", "OptionName" : "Test2"}]}}');
- foreach($OptionValues->params->OptionValues as $optValue){
- $optionVal = $option->OptionName;
- if($option->OptionId == NULL){
- //Create Code
- }
- else{
- //Update Code
- }
- }
Add Comment
Please, Sign In to add comment