Guest User

Untitled

a guest
Jan 23rd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. <route url="/V1/attribute/AttributeOption" method="POST">
  2. <service class="VendorModuleApiAttributeInterface" method="AttributeOption"/>
  3. </route>
  4.  
  5. <?php
  6. namespace VendorModuleApi;
  7.  
  8. interface AttributeInterface
  9. {
  10. /**
  11. * POST for attribute api
  12. * @param mixed $param
  13. * @return array
  14. */
  15.  
  16. public function AttributeOption($params);
  17. }
  18.  
  19. <?php
  20. namespace VendorModuleModel;
  21. use VendorModuleApiAttributeInterface;
  22. use MagentoEavSetupEavSetupFactory;
  23. use MagentoStoreModelStoreManagerInterface;
  24. class Attribute implements AttributeInterface
  25. {
  26. protected $_eavSetupFactory;
  27. protected $_storeManager;
  28. protected $_attributeFactory;
  29. protected $eavAttributeFactory;
  30. protected $attributeOptionManagement;
  31. protected $productFactory;
  32. private $productAttributeRepository;
  33. protected $objectManager;
  34. public function __construct(
  35. MagentoFrameworkObjectManagerInterface $objectManager,
  36. MagentoEavSetupEavSetupFactory $eavSetupFactory,
  37. MagentoStoreModelStoreManagerInterface $storeManager,
  38. MagentoCatalogModelResourceModelEavAttribute $attributeFactory,
  39. MagentoEavModelEntityAttributeFactory $eavAttributeFactory,
  40. MagentoEavApiAttributeOptionManagementInterface $attributeOptionManagement,
  41. MagentoCatalogModelProductFactory $productFactory,
  42. MagentoCatalogModelProductAttributeRepository $productAttributeRepository
  43. ) {
  44. $this->_objectManager = $objectManager;
  45. $this->_eavSetupFactory = $eavSetupFactory;
  46. $this->_storeManager = $storeManager;
  47. $this->_attributeFactory = $attributeFactory;
  48. $this->eavAttributeFactory = $eavAttributeFactory;
  49. $this->attributeOptionManagement = $attributeOptionManagement;
  50. $this->productFactory = $productFactory;
  51. $this->productAttributeRepository = $productAttributeRepository;
  52. }
  53.  
  54. public function AttributeOption($params) {
  55. // looking for logic to create / update options from request
  56. }
  57.  
  58. }
  59.  
  60. {
  61. "params":{
  62. "Type": "create",
  63. "attribute_id" : "159",
  64. "OptionValues": [
  65. {
  66. "OptionId": "01",
  67. "OptionName": "Test"
  68. },
  69. {
  70. "OptionId": "Null",
  71. "OptionName" : "Test2"
  72. }
  73. ]
  74. }
  75. }
  76.  
  77. $OptionValues = json_decode('{"params":{"Type": "create", "attribute_id" : "159", "OptionValues": [{ "OptionId": "01", "OptionName": "Test"}, { "OptionId": "Null", "OptionName" : "Test2"}]}}');
  78.  
  79. foreach($OptionValues->params->OptionValues as $optValue){
  80. $optionVal = $option->OptionName;
  81. if($option->OptionId == NULL){
  82. //Create Code
  83. }
  84. else{
  85. //Update Code
  86. }
  87. }
Add Comment
Please, Sign In to add comment