diff --git a/Block/Catalog/Product/Usage.php b/Block/Catalog/Product/Usage.php
index aec9d41..9d51e0b 100644
--- a/Block/Catalog/Product/Usage.php
+++ b/Block/Catalog/Product/Usage.php
@@ -133,7 +133,7 @@ public function getAllCustomUsages()
$customerUsageItems = $this->usageRepository->getList($searchCriteria)->getItems();
/** @var \DevStone\UsageCalculator\Model\Usage $customerUsageItem */
foreach ($customerUsageItems as $key => $customerUsageItem) {
- if ( ! $customerUsageItem->getConditions()->validate($this->getProduct())) {
+ if (! $customerUsageItem->getConditions()->validate($this->getProduct())) {
unset($customerUsageItems[$key]);
}
}
@@ -175,7 +175,7 @@ public function getUsages($category = null): array
$customerUsageItems = $this->usageRepository->getList($searchCriteria)->getItems();
/** @var \DevStone\UsageCalculator\Model\Usage $customerUsageItem */
foreach ($customerUsageItems as $key => $customerUsageItem) {
- if(!$customerUsageItem->getConditions()->validate($this->getProduct())) {
+ if (!$customerUsageItem->getConditions()->validate($this->getProduct())) {
unset($customerUsageItems[$key]);
}
}
@@ -220,28 +220,29 @@ public function getUsageListAccordingToCustomer($customerId): Collection
return $usageCustomerCollection;
}
- public function getAllCategories() {
+ public function getAllCategories()
+ {
- if ($this->isCustomerLoggedIn()) {
- $customerId = $this->getCustomerId();
- $usageCollection = $this->getUsageListAccordingToCustomer($customerId);
- if ($usageCollection->getSize() > 0) {
- $searchCriteria = $this->searchCriteriaBuilder->create();
- return $this->categoryRepository->getList($searchCriteria)->getItems();
- }
- }
+ if ($this->isCustomerLoggedIn()) {
+ $customerId = $this->getCustomerId();
+ $usageCollection = $this->getUsageListAccordingToCustomer($customerId);
+ if ($usageCollection->getSize() > 0) {
+ $searchCriteria = $this->searchCriteriaBuilder->create();
+ return $this->categoryRepository->getList($searchCriteria)->getItems();
+ }
+ }
- $searchCriteria = $this->searchCriteriaBuilder
- ->addFilter('entity_id', $this->config->getCustomLicenseId(), 'neq')
- ->create();
- return $this->categoryRepository->getList($searchCriteria)->getItems();
- }
+ $searchCriteria = $this->searchCriteriaBuilder
+ ->addFilter('entity_id', $this->config->getCustomLicenseId(), 'neq')
+ ->create();
+ return $this->categoryRepository->getList($searchCriteria)->getItems();
+ }
public function getCustomLicenseCategory()
{
$searchCriteria = $this->searchCriteriaBuilder
- ->addFilter('entity_id', $this->config->getCustomLicenseId(), 'eq')
- ->create();
- $items = $this->categoryRepository->getList($searchCriteria)->getItems();
+ ->addFilter('entity_id', $this->config->getCustomLicenseId(), 'eq')
+ ->create();
+ $items = $this->categoryRepository->getList($searchCriteria)->getItems();
return array_pop($items);
}
/**
@@ -249,19 +250,19 @@ public function getCustomLicenseCategory()
*/
public function getCategories(): array
{
- if ( $this->hasData('customer_specific') && $this->getdata('customer_specific') ) {
- if ($this->isCustomerLoggedIn()) {
- $customerId = $this->getCustomerId();
- $usageCollection = $this->getUsageListAccordingToCustomer($customerId);
- if ($usageCollection->getSize() > 0) {
- $searchCriteria = $this->searchCriteriaBuilder
- ->addFilter('entity_id', $this->config->getCustomLicenseId(), 'eq')
- ->create();
- return $this->categoryRepository->getList($searchCriteria)->getItems();
- }
- }
- return [];
- }
+ if ($this->hasData('customer_specific') && $this->getdata('customer_specific')) {
+ if ($this->isCustomerLoggedIn()) {
+ $customerId = $this->getCustomerId();
+ $usageCollection = $this->getUsageListAccordingToCustomer($customerId);
+ if ($usageCollection->getSize() > 0) {
+ $searchCriteria = $this->searchCriteriaBuilder
+ ->addFilter('entity_id', $this->config->getCustomLicenseId(), 'eq')
+ ->create();
+ return $this->categoryRepository->getList($searchCriteria)->getItems();
+ }
+ }
+ return [];
+ }
$searchCriteria = $this->searchCriteriaBuilder
->addFilter('entity_id', $this->config->getCustomLicenseId(), 'neq')
diff --git a/Controller/Usage/Ajax.php b/Controller/Usage/Ajax.php
new file mode 100644
index 0000000..9202d9e
--- /dev/null
+++ b/Controller/Usage/Ajax.php
@@ -0,0 +1,70 @@
+getRequest()->getParam('id');
+ $product = $this->loadProduct($productId);
+
+ if (! $product) {
+ $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);
+ $resultForward->forward('noroute');
+ return $resultForward;
+ }
+
+ return $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
+ }
+
+
+ /**
+ * Load product model with data by passed id.
+ * Return false if product was not loaded or has incorrect status.
+ *
+ * @param int $productId
+ */
+ protected function loadProduct($productId)
+ {
+ if (!$productId) {
+ return false;
+ }
+
+ try {
+ $product = $this->productRepository->getById($productId);
+
+ if (!$product->isVisibleInCatalog() || !$product->isVisibleInSiteVisibility()) {
+ throw new NoSuchEntityException();
+ }
+ } catch (NoSuchEntityException $noEntityException) {
+ return false;
+ }
+
+ $this->coreRegistry->register('current_product', $product);
+ $this->coreRegistry->register('product', $product);
+
+ return $product;
+ }
+}
diff --git a/etc/frontend/routes.xml b/etc/frontend/routes.xml
new file mode 100644
index 0000000..3e8c4ca
--- /dev/null
+++ b/etc/frontend/routes.xml
@@ -0,0 +1,8 @@
+
+