diff --git a/Api/Data/DeletePayloadInterface.php b/Api/Data/DeletePayloadInterface.php
new file mode 100644
index 0000000..d4294fc
--- /dev/null
+++ b/Api/Data/DeletePayloadInterface.php
@@ -0,0 +1,39 @@
+entityId;
+ }
+
+ public function setEntityId(int $entityId): void
+ {
+ $this->entityId = $entityId;
+ }
+
+ public function getStoreViewId(): int
+ {
+ return $this->storeViewId;
+ }
+
+ public function setStoreViewId(int $storeViewId): void
+ {
+ $this->storeViewId = $storeViewId;
+ }
+
+ public function getAttributeCode(): string
+ {
+ return $this->attributeCode;
+ }
+
+ public function setAttributeCode(string $attributeCode): void
+ {
+ $this->attributeCode = $attributeCode;
+ }
+}
diff --git a/Model/Data/Delete/DeleteResponse.php b/Model/Data/Delete/DeleteResponse.php
new file mode 100644
index 0000000..ee2442d
--- /dev/null
+++ b/Model/Data/Delete/DeleteResponse.php
@@ -0,0 +1,61 @@
+type;
+ }
+
+ /**
+ * @param string $type
+ * @return void
+ */
+ public function setType(string $type): void
+ {
+ $this->type = $type;
+ }
+
+ /**
+ * @return string
+ */
+ public function getMessage(): string
+ {
+ return $this->message;
+ }
+
+ /**
+ * @param string $message
+ * @return void
+ */
+ public function setMessage(string $message): void
+ {
+ $this->message = $message;
+ }
+}
diff --git a/Model/Data/Get/GetPayload.php b/Model/Data/Get/GetPayload.php
index e5119f8..0e0ab63 100644
--- a/Model/Data/Get/GetPayload.php
+++ b/Model/Data/Get/GetPayload.php
@@ -16,7 +16,7 @@ public function getAttributeCode(): string
public function setAttributeCode(string $attribute): void
{
- $this->attributeCode = $attribute;
+ $this->attributeCode = $attribute;
}
public function getEntityId(): int
diff --git a/Model/ProductManagement.php b/Model/ProductManagement.php
index a01938c..93c8e1e 100644
--- a/Model/ProductManagement.php
+++ b/Model/ProductManagement.php
@@ -13,17 +13,22 @@
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Serialize\SerializerInterface;
+use Opengento\BetterBo\Api\Data\DeletePayloadInterface;
+use Opengento\BetterBo\Api\Data\DeletePayloadInterfaceFactory;
+use Opengento\BetterBo\Api\Data\DeleteResponseInterface;
+use Opengento\BetterBo\Api\Data\DeleteResponseInterfaceFactory;
use Opengento\BetterBo\Api\Data\GetPayloadInterface;
use Opengento\BetterBo\Api\Data\GetPayloadInterfaceFactory;
-use Opengento\BetterBo\Api\Data\SavePayloadInterfaceFactory;
use Opengento\BetterBo\Api\Data\SavePayloadInterface;
+use Opengento\BetterBo\Api\Data\SavePayloadInterfaceFactory;
use Opengento\BetterBo\Api\Data\SavePayloadValueInterface;
use Opengento\BetterBo\Api\Data\SaveResponseInterface;
use Opengento\BetterBo\Api\Data\SaveResponseInterfaceFactory;
use Opengento\BetterBo\Api\GetProductAttributesInterface;
use Opengento\BetterBo\Api\ProductManagementInterface;
use Opengento\BetterBo\Model\Exception\PayloadValidationException;
-use function array_column;
+use Opengento\BetterBo\Model\Service\DeleteProductAttribute;
+use Opengento\BetterBo\Model\Service\SaveProductAttributes;
class ProductManagement implements ProductManagementInterface
{
@@ -31,14 +36,16 @@ class ProductManagement implements ProductManagementInterface
public const TYPE_ERROR = 'error';
public function __construct(
- protected GetPayloadInterfaceFactory $getPayloadFactory,
- protected SavePayloadInterfaceFactory $savePayloadInterfaceFactory,
- protected SerializerInterface $serializer,
- protected GetProductAttributesInterface $getProductAttributes,
- protected SaveProductAttributes $saveProductAttributes,
- protected SaveResponseInterfaceFactory $saveResponseInterfaceFactory
- )
- {
+ protected GetPayloadInterfaceFactory $getPayloadFactory,
+ protected SavePayloadInterfaceFactory $savePayloadInterfaceFactory,
+ protected SerializerInterface $serializer,
+ protected GetProductAttributesInterface $getProductAttributes,
+ protected SaveProductAttributes $saveProductAttributes,
+ protected SaveResponseInterfaceFactory $saveResponseInterfaceFactory,
+ protected DeleteResponseInterfaceFactory $deleteResponseInterfaceFactory,
+ protected DeletePayloadInterfaceFactory $deletePayloadInterfaceFactory,
+ protected DeleteProductAttribute $deleteProductAttribute
+ ) {
}
/**
@@ -78,7 +85,7 @@ public function getProductData(string $entityId, string $attributeCode): string
$result = [
'type' => self::TYPE_ERROR,
'message' => '',
- 'data' => []
+ 'data' => [],
];
try {
@@ -129,4 +136,28 @@ protected function initSavePayload(string $entityId, string $attributeCode, arra
return $payload;
}
+
+ /**
+ * @throws PayloadValidationException
+ */
+ protected function initDeletePayload(string $entityId, string $attributeCode, string $storeViewId): DeletePayloadInterface
+ {
+ if (empty($entityId) || empty($attributeCode) || empty($storeViewId)) {
+ throw new PayloadValidationException(__('Invalid DeletePayload'));
+ }
+
+ /** @var \Opengento\BetterBo\Api\Data\DeletePayloadInterface $payload */
+ $payload = $this->deletePayloadInterfaceFactory->create();
+ $payload->setEntityId((int)$entityId);
+ $payload->setStoreViewId((int)$storeViewId);
+ $payload->setAttributeCode($attributeCode);
+
+ return $payload;
+ }
+
+ public function deleteProductData(string $entityId, string $attributeCode, string $storeViewId): DeleteResponseInterface
+ {
+ $payload = $this->initDeletePayload($entityId, $attributeCode, $storeViewId);
+ return $this->deleteProductAttribute->execute($payload);
+ }
}
diff --git a/Model/Service/DeleteProductAttribute.php b/Model/Service/DeleteProductAttribute.php
new file mode 100644
index 0000000..b7e229c
--- /dev/null
+++ b/Model/Service/DeleteProductAttribute.php
@@ -0,0 +1,58 @@
+productAction->updateAttributes(
+ [$payload->getEntityId()],
+ [$payload->getAttributeCode() => null],
+ $payload->getStoreViewId()
+ );
+ $type = 'success';
+ } catch (Exception $e) {
+ $message = $e->getMessage();
+ }
+
+ return $this->getResponse($type, $message);
+ }
+
+ protected function getResponse(string $type, string $message): \Opengento\BetterBo\Api\Data\DeleteResponseInterface
+ {
+ /** @var \Opengento\BetterBo\Api\Data\DeleteResponseInterface $response */
+ $response = $this->deleteResponseValueFactory->create();
+ $response->setMessage($message);
+ $response->setType($type);
+ return $response;
+ }
+}
diff --git a/Model/GetProductAttributes.php b/Model/Service/GetProductAttributes.php
similarity index 87%
rename from Model/GetProductAttributes.php
rename to Model/Service/GetProductAttributes.php
index 7368965..e173d2c 100644
--- a/Model/GetProductAttributes.php
+++ b/Model/Service/GetProductAttributes.php
@@ -9,11 +9,11 @@
declare(strict_types=1);
-namespace Opengento\BetterBo\Model;
+namespace Opengento\BetterBo\Model\Service;
use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
-use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory;
+use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Eav\Api\AttributeRepositoryInterface;
use Magento\Eav\Api\Data\AttributeOptionInterface;
use Magento\Framework\Exception\NoSuchEntityException;
@@ -38,11 +38,10 @@ class GetProductAttributes implements GetProductAttributesInterface
public function __construct(
protected GroupRepositoryInterface $groupRepository,
protected AttributeRepositoryInterface $attributeRepository,
- protected \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
+ protected CollectionFactory $productCollectionFactory,
protected StoreManagerInterface $storeManager,
protected ProductRepositoryInterface $productRepository,
- )
- {
+ ) {
}
/**
@@ -53,7 +52,7 @@ public function execute(GetPayloadInterface $payload): array
{
return [
'config' => $this->getAttributeConfig($payload->getAttributeCode()),
- 'values' => $this->getAttributeValues($payload)
+ 'values' => $this->getAttributeValues($payload),
];
}
@@ -75,16 +74,15 @@ protected function getAttributeConfig(string $attributeCode): array
'type' => $attribute->getFrontendInput(),
'frontendLabel' => $attribute->getDefaultFrontendLabel(),
'options' => array_map(
- static fn(AttributeOptionInterface $option) => [
+ static fn (AttributeOptionInterface $option) => [
'label' => $option->getLabel(),
- 'value' => (string)$option->getValue()
+ 'value' => (string)$option->getValue(),
],
$attribute->getOptions()
),
];
}
-
/**
* @param GetPayloadInterface $payload
* @return array
@@ -100,7 +98,7 @@ protected function getAttributeValues(GetPayloadInterface $payload): array
$results[] = [
'storeViewId' => $storeView->getId(),
'storeViewLabel' => $this->buildStoreViewLabel($storeView),
- 'value' => $product->getData($payload->getAttributeCode())
+ 'value' => $product->getData($payload->getAttributeCode()),
];
}
@@ -132,8 +130,6 @@ protected function getStoreGroups(): array
protected function sortResults(array &$results): void
{
- usort($results, function ($a, $b) {
- return strcmp($a['storeViewLabel'], $b['storeViewLabel']);
- });
+ usort($results, fn ($a, $b) => strcmp($a['storeViewLabel'], $b['storeViewLabel']));
}
}
diff --git a/Model/SaveProductAttributes.php b/Model/Service/SaveProductAttributes.php
similarity index 97%
rename from Model/SaveProductAttributes.php
rename to Model/Service/SaveProductAttributes.php
index ca586b0..efcccb6 100644
--- a/Model/SaveProductAttributes.php
+++ b/Model/Service/SaveProductAttributes.php
@@ -9,7 +9,7 @@
declare(strict_types=1);
-namespace Opengento\BetterBo\Model;
+namespace Opengento\BetterBo\Model\Service;
use Magento\Catalog\Model\Product\Action;
use Opengento\BetterBo\Api\Data\SavePayloadInterface;
@@ -21,8 +21,7 @@ class SaveProductAttributes
public function __construct(
protected Action $productAction,
protected SaveResponseValueInterfaceFactory $saveResponseValueFactory
- )
- {
+ ) {
}
/**
@@ -37,7 +36,7 @@ public function execute(SavePayloadInterface $payload): \Opengento\BetterBo\Api\
$payload->getValues(),
static function ($r, SavePayloadValueInterface $value) use ($payload) {
$r[$value->getStoreViewId()] = [
- $payload->getAttributeCode() => $value->getValue()
+ $payload->getAttributeCode() => $value->getValue(),
];
return $r;
},
diff --git a/Plugin/CategoryEavDataProviderPlugin.php b/Plugin/CategoryEavDataProviderPlugin.php
index 0b2ec11..d2719fa 100644
--- a/Plugin/CategoryEavDataProviderPlugin.php
+++ b/Plugin/CategoryEavDataProviderPlugin.php
@@ -40,7 +40,7 @@ public function afterPrepareFieldsMeta(
foreach ($fieldsMap as $fieldSet => $fields) {
foreach ($fields as $field) {
// if (isset($result[$fieldSet]['children'][$field]['arguments']['data']['config']) && (int) $currentStoreViewId === (int) $adminStoreViewId) {
- $result[$fieldSet]['children'][$field]['arguments']['data']['config']['storebtn'] = "";
+ $result[$fieldSet]['children'][$field]['arguments']['data']['config']['storebtn'] = "";
// }
}
}
diff --git a/Plugin/ConfigFieldPlugin.php b/Plugin/ConfigFieldPlugin.php
index 71f463a..0a4cc1a 100644
--- a/Plugin/ConfigFieldPlugin.php
+++ b/Plugin/ConfigFieldPlugin.php
@@ -1,4 +1,5 @@
scopeConfig->getValue($path);
// }
// $scopeValue = $this->scopeConfig->getValue($path, $scopeType, $scope->getId());
-
+
// if (is_array($currentValue) || is_array($scopeValue)) {
// return $scopeLine;
// }
-
+
// $currentValue = (string) $currentValue;
// $scopeValue = (string) $scopeValue;
-
+
// // dd($currentValue, $scopeValue);
// if ($scopeValue != $currentValue) {
// $scopeValue = $this->escaper->escapeHtml($scopeValue);
@@ -200,4 +201,4 @@ private function getPath(Subject $subject)
// {
// return $this->request->getParam('store');
// }
-}
\ No newline at end of file
+}
diff --git a/etc/di.xml b/etc/di.xml
index 3696c90..cdc3e6d 100644
--- a/etc/di.xml
+++ b/etc/di.xml
@@ -12,5 +12,7 @@
-
+
+
+
diff --git a/etc/webapi.xml b/etc/webapi.xml
index d289292..5448a4a 100644
--- a/etc/webapi.xml
+++ b/etc/webapi.xml
@@ -23,4 +23,12 @@
+
+
+
+
+
+
+
+
diff --git a/registration.php b/registration.php
index 2b5345d..3a15405 100644
--- a/registration.php
+++ b/registration.php
@@ -1,6 +1,7 @@
getRequest()->getParam('id');
+$productId = $block->getRequest()->getParam('id');
?>