AllSoapAndRest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\TestModuleMSC\Model;
  7. use Magento\TestModuleMSC\Api\Data\CustomAttributeDataObjectInterfaceFactory;
  8. use Magento\TestModuleMSC\Api\Data\ItemInterfaceFactory;
  9. class AllSoapAndRest implements \Magento\TestModuleMSC\Api\AllSoapAndRestInterface
  10. {
  11. /**
  12. * @var ItemInterfaceFactory
  13. */
  14. protected $itemDataFactory;
  15. /**
  16. * @var CustomAttributeDataObjectInterfaceFactory
  17. */
  18. protected $customAttributeDataObjectDataFactory;
  19. /**
  20. * @param ItemInterfaceFactory $itemDataFactory
  21. * @param CustomAttributeDataObjectInterfaceFactory $customAttributeNestedDataObjectFactory
  22. */
  23. public function __construct(
  24. ItemInterfaceFactory $itemDataFactory,
  25. CustomAttributeDataObjectInterfaceFactory $customAttributeNestedDataObjectFactory
  26. ) {
  27. $this->itemDataFactory = $itemDataFactory;
  28. $this->customAttributeDataObjectDataFactory = $customAttributeNestedDataObjectFactory;
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function item($itemId)
  34. {
  35. return $this->itemDataFactory->create()->setItemId($itemId)->setName('testProduct1');
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function items()
  41. {
  42. $result1 = $this->itemDataFactory->create()->setItemId(1)->setName('testProduct1');
  43. $result2 = $this->itemDataFactory->create()->setItemId(2)->setName('testProduct2');
  44. return [$result1, $result2];
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function create($name)
  50. {
  51. return $this->itemDataFactory->create()->setItemId(rand())->setName($name);
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. public function update(\Magento\TestModuleMSC\Api\Data\ItemInterface $entityItem)
  57. {
  58. return $this->itemDataFactory->create()->setItemId($entityItem->getItemId())
  59. ->setName('Updated' . $entityItem->getName());
  60. }
  61. public function testOptionalParam($name = null)
  62. {
  63. if ($name === null) {
  64. return $this->itemDataFactory->create()->setItemId(3)->setName('No Name');
  65. } else {
  66. return $this->itemDataFactory->create()->setItemId(3)->setName($name);
  67. }
  68. }
  69. /**
  70. * {@inheritdoc}
  71. */
  72. public function itemAnyType(\Magento\TestModuleMSC\Api\Data\ItemInterface $entityItem)
  73. {
  74. return $entityItem;
  75. }
  76. /**
  77. * {@inheritdoc}
  78. */
  79. public function getPreconfiguredItem()
  80. {
  81. $customAttributeDataObject = $this->customAttributeDataObjectDataFactory->create()
  82. ->setName('nameValue')
  83. ->setCustomAttribute('custom_attribute_int', 1);
  84. $item = $this->itemDataFactory->create()
  85. ->setItemId(1)
  86. ->setName('testProductAnyType')
  87. ->setCustomAttribute('custom_attribute_data_object', $customAttributeDataObject)
  88. ->setCustomAttribute('custom_attribute_string', 'someStringValue');
  89. return $item;
  90. }
  91. }