AllSoapAndRest.php 2.8 KB

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