diff --git a/Api/CategoryRepositoryInterface.php b/Api/CategoryRepositoryInterface.php
index 48d8b29..276cb23 100644
--- a/Api/CategoryRepositoryInterface.php
+++ b/Api/CategoryRepositoryInterface.php
@@ -20,11 +20,11 @@ public function save(
/**
* Retrieve Category
- * @param string $usageId
+ * @param string $categoryId
* @return \DevStone\UsageCalculator\Api\Data\CategoryInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
- public function getById($usageId);
+ public function getById($categoryId);
/**
* Retrieve Category matching the specified criteria.
diff --git a/Api/Data/UsageCustomerInterface.php b/Api/Data/UsageCustomerInterface.php
new file mode 100644
index 0000000..b481e6b
--- /dev/null
+++ b/Api/Data/UsageCustomerInterface.php
@@ -0,0 +1,52 @@
+registry = $registry;
- $this->jsonEncoder = $jsonEncoder;
+ $this->serializer = $serializer;
$this->request = $request;
$this->collectionFactory = $collectionFactory;
parent::__construct($context, $data);
}
/**
- * @return \Magento\Framework\View\Element\BlockInterface
- * @throws \Magento\Framework\Exception\LocalizedException
+ * @throws LocalizedException
*/
- public function getBlockGrid()
+ public function getBlockGrid(): BlockInterface
{
if (null === $this->blockGrid) {
$this->blockGrid = $this->getLayout()->createBlock(
- \DevStone\UsageCalculator\Block\Adminhtml\Customer\Tab\Customer::class,
+ Customer::class,
'usage.customer.grid'
);
}
@@ -84,31 +69,24 @@ public function getBlockGrid()
}
/**
- * @return string
- * @throws \Magento\Framework\Exception\LocalizedException
+ * @throws LocalizedException
*/
- public function getGridHtml()
+ public function getGridHtml(): string
{
return $this->getBlockGrid()->toHtml();
}
- /**
- * @return string
- */
- public function getProductsJson()
+ public function getProductsJson(): string
{
$customer = $this->getUsageCustomer();
if (!empty($customer)) {
- return $this->jsonEncoder->encode($customer);
+ return $this->serializer->serialize($customer);
}
return '{}';
}
- /**
- * @return array
- */
- public function getUsageCustomer()
+ public function getUsageCustomer(): array
{
$id = $this->getRequest()->getParam('entity_id');
$customerArray = [];
@@ -122,14 +100,11 @@ public function getUsageCustomer()
return $customerArray;
}
- /**
- * @return bool|mixed
- */
- public function showGrid()
+ public function showGrid(): bool
{
$customLicense = $this->request->getParam('custom_license');
if (isset($customLicense)) {
- return $customLicense;
+ return true;
}
return false;
}
diff --git a/Block/Catalog/Product/Usage.php b/Block/Catalog/Product/Usage.php
index 0f01eb5..7256580 100644
--- a/Block/Catalog/Product/Usage.php
+++ b/Block/Catalog/Product/Usage.php
@@ -1,4 +1,6 @@
-pricingHelper = $pricingHelper;
- $this->encoder = $encoder;
+ $this->serializer = $serializer;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->usageRepository = $usageRepository;
$this->categoryRepository = $categoryRepository;
@@ -139,52 +93,37 @@ public function __construct(
$this->orderCollectionFactory = $orderCollectionFactory;
$this->sortOrderBuilder = $sortOrderBuilder;
parent::__construct($context, $data);
+ $this->config = $config;
}
- /**
- *
- * @return boolean
- */
- public function getLinksPurchasedSeparately()
+ public function getLinksPurchasedSeparately(): bool
{
return $this->getProduct()->getLinksPurchasedSeparately();
}
- /**
- * @return boolean
- */
- public function getLinkSelectionRequired()
+ public function getLinkSelectionRequired(): bool
{
return $this->getProduct()->getTypeInstance()->getLinkSelectionRequired($this->getProduct());
}
- /**
- * @return boolean
- */
- public function hasLinks()
+ public function hasLinks(): bool
{
return $this->getProduct()->getTypeInstance()->hasLinks($this->getProduct());
}
- /**
- * @return array
- */
- public function getLinks()
+ public function getLinks(): array
{
return $this->getProduct()->getTypeInstance()->getLinks($this->getProduct());
}
- /**
- * @return array
- */
- public function getUsages($category = null)
+ public function getUsages($category = null): array
{
if (empty($this->usages)) {
- $customLicenseId = $this->getCustomLicenseId();
+ $customLicenseId = $this->config->getCustomLicenseId();
$sortOrder = $this->sortOrderBuilder
->setField('name')
- ->setDirection(\Magento\Framework\Api\SortOrder::SORT_ASC)
+ ->setDirection(SortOrder::SORT_ASC)
->create();
$searchCriteria = $this->searchCriteriaBuilder
->addFilter('category_id', $customLicenseId, 'neq')
@@ -202,8 +141,11 @@ public function getUsages($category = null)
$customerUsage[] = $usage->getUsageId();
}
- $searchCriteria = $this->searchCriteriaBuilder->addFilter('entity_id', $customerUsage,
- 'in')->create();
+ $searchCriteria = $this->searchCriteriaBuilder->addFilter(
+ 'entity_id',
+ $customerUsage,
+ 'in'
+ )->create();
$customerUsageItems = $this->usageRepository->getList($searchCriteria)->getItems();
$items = array_merge_recursive($items, $customerUsageItems);
}
@@ -229,75 +171,54 @@ public function getUsages($category = null)
}
}
- /**
- * @return bool
- */
- public function isCustomerLoggedIn()
+ public function isCustomerLoggedIn(): bool
{
return $this->session->isLoggedIn();
}
- /**
- * @return int|null
- */
- public function getCustomerId()
+ public function getCustomerId(): ?int
{
return $this->session->getCustomerId();
}
- /**
- * @param $customerId
- * @return \DevStone\UsageCalculator\Model\ResourceModel\UsageCustomer\Collection
- */
- public function getUsageListAccordingToCustomer($customerId)
+ public function getUsageListAccordingToCustomer($customerId): Collection
{
- /**
- * @var \DevStone\UsageCalculator\Model\ResourceModel\UsageCustomer\Collection $usageCustomerCollection
- */
$usageCustomerCollection = $this->usageCustomerCollectionFactory->create();
$usageCustomerCollection->addFieldToFilter('customer_id', $customerId);
return $usageCustomerCollection;
}
/**
- * @return array|\DevStone\UsageCalculator\Api\Data\CategoryInterface[]
- * @throws \Magento\Framework\Exception\LocalizedException
+ * @throws LocalizedException
*/
- public function getCategories()
+ public function getCategories(): array
{
- $list = [];
if ($this->isCustomerLoggedIn()) {
$customerId = $this->getCustomerId();
$usageCollection = $this->getUsageListAccordingToCustomer($customerId);
if ($usageCollection->getSize() > 0) {
$searchCriteria = $this->searchCriteriaBuilder->create();
- $list = $this->categoryRepository->getList($searchCriteria)->getItems();
- return $list;
-
+ return $this->categoryRepository->getList($searchCriteria)->getItems();
}
}
$searchCriteria = $this->searchCriteriaBuilder
- ->addFilter('entity_id', $this->getCustomLicenseId(), 'neq')
+ ->addFilter('entity_id', $this->config->getCustomLicenseId(), 'neq')
->create();
- $list = $this->categoryRepository->getList($searchCriteria)->getItems();
- return $list;
+ return $this->categoryRepository->getList($searchCriteria)->getItems();
}
/**
- * @param $usages
- * @param $category
- * @return mixed
- * @throws \Magento\Framework\Exception\LocalizedException
+ * @throws LocalizedException
*/
public function getUsagesSelectHtml(
$usages,
$category
- ) {
+ ): string {
$store = $this->getProduct()->getStore();
$extraParams = '';
$select = $this->getLayout()->createBlock(
- \Magento\Framework\View\Element\Html\Select::class
+ Select::class
)->setData(
[
'id' => 'usage_' . $category->getId() . '_usages',
@@ -308,7 +229,6 @@ public function getUsagesSelectHtml(
$select->setName('usage_id[' . $category->getId() . ']')->addOption('', __('-- Please Select --'));
foreach ($usages as $usage) {
-
$select->addOption(
$usage->getId(),
$usage->getName(),
@@ -317,7 +237,6 @@ public function getUsagesSelectHtml(
'data-terms' => $usage->getTerms(),
]
);
-
}
$extraParams .= ' data-selector="' . $select->getName() . '"';
$select->setExtraParams($extraParams);
@@ -326,14 +245,13 @@ public function getUsagesSelectHtml(
}
/**
- * @return mixed
- * @throws \Magento\Framework\Exception\LocalizedException
+ * @throws LocalizedException
*/
- public function getCategoriesSelectHtml()
+ public function getCategoriesSelectHtml(): string
{
$extraParams = '';
$select = $this->getLayout()->createBlock(
- \Magento\Framework\View\Element\Html\Select::class
+ Select::class
)->setData(
[
'id' => 'usage_category',
@@ -344,7 +262,6 @@ public function getCategoriesSelectHtml()
$select->setName('usage_category')->addOption('', __('-- Please Select --'));
foreach ($this->getCategories() as $category) {
-
$select->addOption(
$category->getId(),
$category->getName()
@@ -364,28 +281,21 @@ public function getCategoriesSelectHtml()
/**
* Returns price converted to current currency rate
- *
- * @param float $price
- * @return float
*/
public function getCurrencyPrice(
- $price
- ) {
+ float $price
+ ): float {
$store = $this->getProduct()->getStore();
return $this->pricingHelper->currencyByStore($price, $store, false);
}
- /**
- * @return string
- */
- public function getJsonConfig()
+ public function getJsonConfig(): string
{
$finalPrice = $this->getProduct()->getPriceInfo()
->getPrice(FinalPrice::PRICE_CODE);
$linksConfig = [];
foreach ($this->getUsages() as $usage) {
-
$amount = $finalPrice->getCustomAmount($usage->getPrice());
$linksConfig[$usage->getId()] = [
'finalPrice' => $amount->getValue(),
@@ -393,92 +303,74 @@ public function getJsonConfig()
];
}
- return $this->encoder->encode(['links' => $linksConfig]);
+ return $this->serializer->serialize(['links' => $linksConfig]);
}
/**
- * @param Link $link
- * @return string
+ * @throws NoSuchEntityException
*/
- public function getLinkSampleUrl(
- $link
- ) {
+ protected function getLinkSampleUrl(
+ Link $link
+ ): string {
$store = $this->getProduct()->getStore();
return $store->getUrl('downloadable/download/linkSample', ['link_id' => $link->getId()]);
}
/**
* Return title of links section
- *
- * @return string
*/
- public function getLinksTitle()
+ public function getLinksTitle(): string
{
if ($this->getProduct()->getLinksTitle()) {
return $this->getProduct()->getLinksTitle();
}
return $this->_scopeConfig->getValue(
- \Magento\Downloadable\Model\Link::XML_PATH_LINKS_TITLE,
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE
+ Link::XML_PATH_LINKS_TITLE,
+ ScopeInterface::SCOPE_STORE
);
}
/**
* Return true if target of link new window
- *
- * @return bool
- * @SuppressWarnings(PHPMD.BooleanGetMethodName)
*/
- public function getIsOpenInNewWindow()
+ public function getIsOpenInNewWindow(): bool
{
return $this->_scopeConfig->isSetFlag(
- \Magento\Downloadable\Model\Link::XML_PATH_TARGET_NEW_WINDOW,
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE
+ Link::XML_PATH_TARGET_NEW_WINDOW,
+ ScopeInterface::SCOPE_STORE
);
}
/**
* Returns whether link checked by default or not
- *
- * @param Link $link
- * @return bool
- * @SuppressWarnings(PHPMD.BooleanGetMethodName)
*/
- public function getIsLinkChecked($link)
+ public function getIsLinkChecked(Link $link): bool
{
$configValue = $this->getProduct()->getPreconfiguredValues()->getLinks();
if (!$configValue || !is_array($configValue)) {
return false;
}
- return $configValue && in_array($link->getId(), $configValue);
+ return in_array($link->getId(), $configValue);
}
/**
* Returns value for link's input checkbox - either 'checked' or ''
- *
- * @param Link $link
- * @return string
*/
- public function getLinkCheckedValue($link)
+ public function getLinkCheckedValue(Link $link): string
{
return $this->getIsLinkChecked($link) ? 'checked' : '';
}
- /**
- * @param Link $link
- * @return \Magento\Framework\Pricing\Amount\AmountInterface
- */
- protected function getLinkAmount($link)
+ protected function getLinkAmount(Link $link): AmountInterface
{
return $this->getPriceType()->getLinkAmount($link);
}
/**
- * @param Link $link
- * @return string
+ * @throws LocalizedException
*/
- public function getLinkPrice(Link $link)
+ public function getLinkPrice(Link $link): string
{
return $this->getLayout()->getBlock('product.price.render.default')->renderAmount(
$this->getLinkAmount($link),
@@ -489,21 +381,16 @@ public function getLinkPrice(Link $link)
/**
* Get LinkPrice Type
- *
- * @return \Magento\Framework\Pricing\Price\PriceInterface
*/
- protected function getPriceType()
+ protected function getPriceType(): PriceInterface
{
return $this->getProduct()->getPriceInfo()->getPrice(LinkPrice::PRICE_CODE);
}
/**
* Get option html block
- *
- * @param \DevStone\UsageCalculator\Model\Usage\Option $option
- * @return string
*/
- public function getOptionHtml(\DevStone\UsageCalculator\Model\Usage\Option $option)
+ public function getOptionHtml(Option $option): string
{
$type = $this->getGroupOfOption($option->getType());
$renderer = $this->getChildBlock($type);
@@ -513,11 +400,7 @@ public function getOptionHtml(\DevStone\UsageCalculator\Model\Usage\Option $opti
return $this->getChildHtml($type, false);
}
- /**
- * @param string $type
- * @return string
- */
- public function getGroupOfOption($type)
+ public function getGroupOfOption(string $type): string
{
$group = $this->optionModel->getGroupByType($type);
@@ -525,25 +408,13 @@ public function getGroupOfOption($type)
}
/**
- * @return mixed
- */
- public function getCustomLicenseId()
- {
- return $this->_scopeConfig->getValue(
- 'usage_cal/general/category_id',
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE
- );
- }
-
- /**
- * @return mixed
- * @throws \Magento\Framework\Exception\LocalizedException
+ * @throws LocalizedException
*/
- public function getPreviousSelectHtml()
+ public function getPreviousSelectHtml(): string
{
$extraParams = '';
$select = $this->getLayout()->createBlock(
- \Magento\Framework\View\Element\Html\Select::class
+ Select::class
)->setData(
[
'id' => 'usage_previous_usages',
@@ -554,7 +425,6 @@ public function getPreviousSelectHtml()
$select->setName('previous_category')->addOption('', __('-- Please Select --'));
foreach ($this->getPreviousCategories() as $category) {
-
$select->addOption(
$category['id'],
$category['name']
@@ -567,18 +437,14 @@ public function getPreviousSelectHtml()
}
/**
- * @return array
- * @throws \Magento\Framework\Exception\LocalizedException
- * @throws \Magento\Framework\Exception\NoSuchEntityException
+ * @throws LocalizedException
+ * @throws NoSuchEntityException
*/
- public function getPreviousCategories()
+ public function getPreviousCategories(): array
{
$previousCategories = [];
$items = $this->checkoutSession->getQuote()->getAllVisibleItems();
foreach ($items as $item) {
- /**
- * @var \Magento\Quote\Model\Quote\Item $item
- */
$getBuyRequest = $item->getBuyRequest();
$previousCategoriesByItems = $this->getPreviousCategoriesByItemsFromBuyRequest($getBuyRequest);
if (count($previousCategoriesByItems) && !in_array($previousCategoriesByItems, $previousCategories)) {
@@ -595,25 +461,25 @@ public function getPreviousCategories()
->setPageSize(20 - count($previousCategories))
->setOrder('created_at', 'desc');
/**
- * @var \Magento\Sales\Model\Order $order
- * @var \Magento\Sales\Api\Data\OrderItemInterface $item
+ * @var Order $order
+ * @var OrderItemInterface $item
*/
foreach ($ordersCollection as $order) {
$items = $order->getAllVisibleItems();
foreach ($items as $item) {
try {
/**
- * @var \Magento\Quote\Model\Quote\Item $item
+ * @var Item $item
*/
$getBuyRequest = $item->getProductOptions()['info_buyRequest'];
$previousCategoriesByItems = $this->getPreviousCategoriesByItemsFromBuyRequest($getBuyRequest);
if (count($previousCategoriesByItems) && !in_array(
- $previousCategoriesByItems,
- $previousCategories
- )) {
+ $previousCategoriesByItems,
+ $previousCategories
+ )) {
$previousCategories[] = $previousCategoriesByItems;
}
- } catch (\Exception $e){
+ } catch (Exception $e) {
// Probably usage was deleted, skip.
continue;
}
@@ -627,7 +493,11 @@ public function getPreviousCategories()
return $previousCategories;
}
- public function getPreviousCategoriesByItemsFromBuyRequest($buyRequest)
+ /**
+ * @throws NoSuchEntityException
+ * @throws LocalizedException
+ */
+ public function getPreviousCategoriesByItemsFromBuyRequest($buyRequest): array
{
$id = '';
$value = '';
@@ -650,43 +520,31 @@ public function getPreviousCategoriesByItemsFromBuyRequest($buyRequest)
}
/**
- * @param $categoryId
- * @return string|null
- * @throws \Magento\Framework\Exception\LocalizedException
+ * @throws LocalizedException
*/
- public function getCategoryName($categoryId)
+ public function getCategoryName($categoryId): ?string
{
- $searchCriteria = $this->searchCriteriaBuilder
- ->addFilter('entity_id', $categoryId, 'eq')
- ->create();
- $list = $this->categoryRepository->getList($searchCriteria)->getItems();
- return $list[$categoryId]->getName();
+ $category = $this->categoryRepository->getById($categoryId);
+ return $category->getName();
}
/**
- * @param $usageId
- * @return mixed
- * @throws \Magento\Framework\Exception\LocalizedException
+ * @throws LocalizedException
*/
- public function getUsageName($usageId)
+ public function getUsageName($usageId): string
{
- $searchCriteria = $this->searchCriteriaBuilder
- ->addFilter('entity_id', $usageId, 'eq')
- ->create();
- $list = $this->usageRepository->getList($searchCriteria)->getItems();
- return $list[$usageId]->getName();
+ $usage = $this->usageRepository->getById($usageId);
+ return $usage->getName();
}
/**
- * @param $optionId
- * @return mixed
- * @throws \Magento\Framework\Exception\NoSuchEntityException
+ * @throws NoSuchEntityException
*/
- public function getOptionName($optionId)
+ public function getOptionName($optionId): string
{
$usageOptionCollection = $this->usageOptionCollectionFactory->create();
$usageOptionCollection->addTitlesToResult($this->_storeManager->getStore()->getId());
$usageOptionCollection->addFieldToFilter('main_table.option_type_id', $optionId);
- return $usageOptionCollection->count() ? $usageOptionCollection->getFirstItem()->getTitle() : $optionId;
+ return $usageOptionCollection->count() ? $usageOptionCollection->getFirstItem()->getTitle() : "";
}
}
diff --git a/Controller/Adminhtml/Usage/Save.php b/Controller/Adminhtml/Usage/Save.php
index ba4f5e6..b6c0d13 100644
--- a/Controller/Adminhtml/Usage/Save.php
+++ b/Controller/Adminhtml/Usage/Save.php
@@ -8,9 +8,13 @@
namespace DevStone\UsageCalculator\Controller\Adminhtml\Usage;
+use DevStone\UsageCalculator\Helper\Data;
+use Exception;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use DevStone\UsageCalculator\Model\UsageFactory;
+use Magento\Backend\Model\View\Result\Redirect;
+use Magento\Framework\Controller\ResultInterface;
/**
* Class Save
@@ -18,13 +22,9 @@
*/
class Save extends Action
{
- /** @var UsageFactory $objectFactory */
- protected $objectFactory;
-
- /**
- * @var Initialization\Helper $helper
- */
- protected $helper;
+ protected UsageFactory $objectFactory;
+ protected Initialization\Helper $helper;
+ protected Data $data;
/**
* @param Context $context
@@ -33,35 +33,34 @@ class Save extends Action
public function __construct(
Context $context,
UsageFactory $objectFactory,
- Initialization\Helper $helper
+ Initialization\Helper $helper,
+ Data $data
) {
$this->objectFactory = $objectFactory;
$this->helper = $helper;
+ $this->data = $data;
parent::__construct($context);
+
}
/**
* {@inheritdoc}
*/
- protected function _isAllowed()
+ protected function _isAllowed(): bool
{
return $this->_authorization->isAllowed('DevStone_UsageCalculator::usage');
}
- /**
- * Save action
- *
- * @return \Magento\Framework\Controller\ResultInterface
- */
- public function execute()
+ public function execute(): ResultInterface
{
$storeId = (int)$this->getRequest()->getParam('store_id');
$data = $this->getRequest()->getParams();
- /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
+ /** @var Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
if ($data) {
$params = [];
$objectInstance = $this->objectFactory->create();
+
$objectInstance->setStoreId($storeId);
$params['store'] = $storeId;
if (empty($data['entity_id'])) {
@@ -85,10 +84,14 @@ public function execute()
if ($this->getRequest()->getParam('back')) {
$params['entity_id'] = $objectInstance->getId();
$params['_current'] = true;
+ $customLicenseId = $this->data->getCustomLicenseId();
+ if ($objectInstance->getCategoryId() == $customLicenseId) {
+ $params['custom_license'] = true;
+ }
return $resultRedirect->setPath('*/*/edit', $params);
}
return $resultRedirect->setPath('*/*/');
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
$this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the record.'));
}
diff --git a/Helper/Data.php b/Helper/Data.php
new file mode 100644
index 0000000..694d813
--- /dev/null
+++ b/Helper/Data.php
@@ -0,0 +1,19 @@
+scopeConfig->getValue(
+ 'usage_cal/general/category_id',
+ \Magento\Store\Model\ScopeInterface::SCOPE_STORE
+ );
+ }
+}
diff --git a/Model/CategoryRepository.php b/Model/CategoryRepository.php
index 2b88dea..1e4e66d 100644
--- a/Model/CategoryRepository.php
+++ b/Model/CategoryRepository.php
@@ -1,21 +1,22 @@
setItems($collection->getItems());
return $searchResults;
-//
+//
// $searchResults = $this->searchResultsFactory->create();
// $searchResults->setSearchCriteria($searchCriteria);
// /** @var \Magento\Customer\Model\ResourceModel\Customer\Collection $collection */
@@ -193,7 +194,6 @@ public function getList(
// }
// $searchResults->setItems($customers);
// return $searchResults;
-
}
/**
diff --git a/Model/Usage/CatagoriesOptionsProvider.php b/Model/Usage/CatagoriesOptionsProvider.php
index c6dce12..5888c43 100644
--- a/Model/Usage/CatagoriesOptionsProvider.php
+++ b/Model/Usage/CatagoriesOptionsProvider.php
@@ -2,6 +2,8 @@
namespace DevStone\UsageCalculator\Model\Usage;
+use DevStone\UsageCalculator\Helper\Data;
+
/**
* Class CatagoriesOptionsProvider
* @package DevStone\UsageCalculator\Model\Usage
@@ -27,6 +29,7 @@ class CatagoriesOptionsProvider implements \Magento\Framework\Data\OptionSourceI
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;
+ protected Data $config;
/**
* CatagoriesOptionsProvider constructor.
@@ -39,12 +42,14 @@ public function __construct(
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
\Magento\Framework\Convert\DataObject $objectConverter,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
- \DevStone\UsageCalculator\Api\CategoryRepositoryInterface $categoryRepository
+ \DevStone\UsageCalculator\Api\CategoryRepositoryInterface $categoryRepository,
+ Data $config
) {
$this->categoryRepository = $categoryRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->objectConverter = $objectConverter;
$this->scopeConfig = $scopeConfig;
+ $this->config = $config;
}
/**
@@ -54,7 +59,7 @@ public function __construct(
public function allOptionsExcludingCustomLicense()
{
$searchCriteria = $this->searchCriteriaBuilder
- ->addFilter('entity_id', $this->getCustomLicenseId(), 'neq')
+ ->addFilter('entity_id', $this->config->getCustomLicenseId(), 'neq')
->create();
$catagories = $this->categoryRepository->getList($searchCriteria)->getItems();
return $this->objectConverter->toOptionArray($catagories, 'entity_id', 'name');
@@ -67,7 +72,7 @@ public function allOptionsExcludingCustomLicense()
public function customLicenseOption()
{
$searchCriteria = $this->searchCriteriaBuilder
- ->addFilter('entity_id', $this->getCustomLicenseId(), 'eq')
+ ->addFilter('entity_id', $this->config->getCustomLicenseId(), 'eq')
->create();
$catagories = $this->categoryRepository->getList($searchCriteria)->getItems();
return $this->objectConverter->toOptionArray($catagories, 'entity_id', 'name');
@@ -83,15 +88,4 @@ public function toOptionArray()
$catagories = $this->categoryRepository->getList($searchCriteria)->getItems();
return $this->objectConverter->toOptionArray($catagories, 'entity_id', 'name');
}
-
- /**
- * @return mixed
- */
- public function getCustomLicenseId()
- {
- return $this->scopeConfig->getValue(
- 'usage_cal/general/category_id',
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE
- );
- }
}
diff --git a/Model/UsageCustomer.php b/Model/UsageCustomer.php
index 8823285..f4846d0 100644
--- a/Model/UsageCustomer.php
+++ b/Model/UsageCustomer.php
@@ -2,40 +2,59 @@
namespace DevStone\UsageCalculator\Model;
+use DevStone\UsageCalculator\Api\Data\UsageCustomerInterface;
+use DevStone\UsageCalculator\Setup\UsageSetup;
+use Magento\Framework\DataObject\IdentityInterface;
+use Magento\Framework\Model\AbstractModel;
+
/**
* Class UsageCustomer
* @package DevStone\UsageCalculator\Model
*/
-class UsageCustomer extends \Magento\Framework\Model\AbstractModel implements \Magento\Framework\DataObject\IdentityInterface
+class UsageCustomer extends AbstractModel implements IdentityInterface, UsageCustomerInterface
{
- /**
- *
- */
- const CACHE_TAG = \DevStone\UsageCalculator\Setup\UsageSetup::ENTITY_TYPE_CODE . '_customer';
-
- /**
- * @var string
- */
- protected $_cacheTag = \DevStone\UsageCalculator\Setup\UsageSetup::ENTITY_TYPE_CODE . '_customer';
-
- /**
- * @var string
- */
- protected $_eventPrefix = \DevStone\UsageCalculator\Setup\UsageSetup::ENTITY_TYPE_CODE . '_customer';
-
- /**
- *
- */
+ const CACHE_TAG = UsageSetup::ENTITY_TYPE_CODE . '_customer';
+ protected $_cacheTag = UsageSetup::ENTITY_TYPE_CODE . '_customer';
+ protected $_eventPrefix = UsageSetup::ENTITY_TYPE_CODE . '_customer';
+ protected $_idFieldName = 'entity_id';
+
protected function _construct()
{
- $this->_init(\DevStone\UsageCalculator\Model\ResourceModel\UsageCustomer::class);
+ $this->_init(ResourceModel\UsageCustomer::class);
}
- /**
- * @return array|string[]
- */
- public function getIdentities()
+ public function getIdentities(): array
{
return [self::CACHE_TAG . '_' . $this->getId()];
}
+
+ public function getUsageId(): int
+ {
+ return (int) $this->getData('usage_id');
+ }
+
+ public function setUsageId(int $usageId): UsageCustomerInterface
+ {
+ return $this->setData('usage_id', $usageId);
+ }
+
+ public function getCustomerId(): int
+ {
+ return (int) $this->getData('customer_id');
+ }
+
+ public function setCustomerId(int $customerId): UsageCustomerInterface
+ {
+ return $this->setData('customer_id', $customerId);
+ }
+
+ public function getPendingCustomerEmail(): string
+ {
+ return (string) $this->getData('pending_customer_email');
+ }
+
+ public function setPendingCustomerEmail(string $pendingCustomerEmail): UsageCustomerInterface
+ {
+ return $this->setData('pending_customer_email', $pendingCustomerEmail);
+ }
}
diff --git a/Model/UsageCustomerRepository.php b/Model/UsageCustomerRepository.php
new file mode 100644
index 0000000..76207e3
--- /dev/null
+++ b/Model/UsageCustomerRepository.php
@@ -0,0 +1,176 @@
+resource = $resource;
+ $this->usageCustomerFactory = $usageCustomerFactory;
+ $this->usageCustomerCollectionFactory = $usageCustomerCollectionFactory;
+ $this->searchResultsFactory = $searchResultsFactory;
+ $this->collectionProcessor = $collectionProcessor;
+ $this->searchCriteriaBuilder = $searchCriteriaBuilder;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function save(UsageCustomerInterface $usageCustomer): UsageCustomerInterface
+ {
+ try {
+ $this->resource->save($usageCustomer);
+ } catch (Exception $exception) {
+ throw new CouldNotSaveException(__(
+ 'Could not save the usageCustomer: %1',
+ $exception->getMessage()
+ ));
+ }
+ return $usageCustomer;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function get($usageCustomerId): UsageCustomerInterface
+ {
+ $usageCustomer = $this->usageCustomerFactory->create();
+ $this->resource->load($usageCustomer, $usageCustomerId);
+ if (!$usageCustomer->getId()) {
+ throw new NoSuchEntityException(__('UsageCustomer with id "%1" does not exist.', $usageCustomerId));
+ }
+ return $usageCustomer;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getByUsageAndCustomer($usageId, $customerId): ?UsageCustomerInterface
+ {
+ $searchCriteria = $this->searchCriteriaBuilder
+ ->addFilter('usage_id', $usageId)
+ ->addFilter('customer_id', $customerId)
+ ->create();
+ $items = $this->getList($searchCriteria)->getItems();
+
+ if (sizeof($items) > 0) {
+ return $items[0];
+ }
+ return null;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getByUsageAndEmail($usageId, $email): ?UsageCustomerInterface
+ {
+ $searchCriteria = $this->searchCriteriaBuilder
+ ->addFilter('usage_id', $usageId)
+ ->addFilter('pending_customer_email', $email)
+ ->create();
+ $items = $this->getList($searchCriteria)->getItems();
+
+ if (sizeof($items) > 0) {
+ return $items[0];
+ }
+ return null;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getList(SearchCriteriaInterface $searchCriteria): SearchResultsInterface
+ {
+ $collection = $this->usageCustomerCollectionFactory->create();
+
+ $this->collectionProcessor->process($searchCriteria, $collection);
+
+ $searchResults = $this->searchResultsFactory->create();
+ $searchResults->setSearchCriteria($searchCriteria);
+
+ $items = [];
+ foreach ($collection as $model) {
+ $items[] = $model;
+ }
+
+ $searchResults->setItems($items);
+ $searchResults->setTotalCount($collection->getSize());
+ return $searchResults;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function delete(UsageCustomerInterface $usageCustomer): bool
+ {
+ try {
+ $usageCustomerModel = $this->usageCustomerFactory->create();
+ $this->resource->load($usageCustomerModel, $usageCustomer->getId());
+ $this->resource->delete($usageCustomerModel);
+ } catch (Exception $exception) {
+ throw new CouldNotDeleteException(__(
+ 'Could not delete the UsageCustomer: %1',
+ $exception->getMessage()
+ ));
+ }
+ return true;
+ }
+
+
+
+ /**
+ * @inheritDoc
+ */
+ public function deleteList(SearchCriteriaInterface $searchCriteria): bool
+ {
+ $collection = $this->usageCustomerCollectionFactory->create();
+
+ $this->collectionProcessor->process($searchCriteria, $collection);
+ $collection->walk('delete');
+
+ return true;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function deleteById($usageCustomerId): bool
+ {
+ return $this->delete($this->get($usageCustomerId));
+ }
+}
diff --git a/Model/UsageRepository.php b/Model/UsageRepository.php
index d1fd7df..22267a6 100644
--- a/Model/UsageRepository.php
+++ b/Model/UsageRepository.php
@@ -3,6 +3,7 @@
namespace DevStone\UsageCalculator\Model;
+use DevStone\UsageCalculator\Api\Data\UsageInterface;
use Magento\Framework\Exception\CouldNotDeleteException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Exception\CouldNotSaveException;
@@ -116,7 +117,7 @@ public function save(
/**
* {@inheritdoc}
*/
- public function getById($usageId)
+ public function getById(int $usageId): UsageInterface
{
// $usage = $this->usageFactory->create();
// $usage->setData('store_id', 5);
diff --git a/Observer/CheckNewCustomerLicenses.php b/Observer/CheckNewCustomerLicenses.php
new file mode 100644
index 0000000..ec237f7
--- /dev/null
+++ b/Observer/CheckNewCustomerLicenses.php
@@ -0,0 +1,54 @@
+searchCriteriaBuilder = $searchCriteriaBuilder;
+ $this->usageCustomerRepository = $usageCustomerRepository;
+ $this->logger = $logger;
+ }
+
+ public function execute(Observer $observer)
+ {
+ try {
+ /** @var CustomerInterface $customer */
+ $customer = $observer->getCustomer();
+ $searchCriteria = $this->searchCriteriaBuilder
+ ->addFilter('pending_customer_email', $customer->getEmail())
+ ->addFilter('customer_id', 0)
+ ->create();
+ $usageCustomers = $this->usageCustomerRepository->getList($searchCriteria);
+ if ($usageCustomers->getTotalCount() > 0) {
+ /** @var UsageCustomerInterface $usageCustomer */
+ foreach ($usageCustomers->getItems() as $usageCustomer) {
+ $usageCustomer->setCustomerId((int)$customer->getId());
+ $usageCustomer->setPendingCustomerEmail("");
+ $this->usageCustomerRepository->save($usageCustomer);
+ }
+ }
+ } catch (\Exception $e) {
+ $this->logger->error(__('Unable to attach licenses to customer %s', $customer->getId()));
+ $this->logger->error($e->getMessage());
+ }
+ }
+}
diff --git a/Observer/SaveCustomer.php b/Observer/SaveCustomer.php
index c61ef6a..aacf06b 100644
--- a/Observer/SaveCustomer.php
+++ b/Observer/SaveCustomer.php
@@ -2,83 +2,104 @@
namespace DevStone\UsageCalculator\Observer;
-use Magento\Framework\App\Config;
+use DevStone\UsageCalculator\Api\UsageCustomerRepositoryInterface;
+use DevStone\UsageCalculator\Model\ResourceModel\UsageCustomer\CollectionFactory;
+use DevStone\UsageCalculator\Model\Usage;
+use DevStone\UsageCalculator\Model\UsageCustomerFactory;
+use Exception;
+use Magento\Framework\Api\SearchCriteriaBuilder;
+use Magento\Framework\App\Config\ScopeConfigInterface;
+use Magento\Framework\App\RequestInterface;
use Magento\Framework\Event\Observer;
+use Magento\Framework\Event\ObserverInterface;
+use Magento\Store\Model\ScopeInterface;
/**
* Class SaveCustomer
* @package DevStone\UsageCalculator\Observer
*/
-class SaveCustomer implements \Magento\Framework\Event\ObserverInterface
+class SaveCustomer implements ObserverInterface
{
+ protected UsageCustomerFactory $usageCustomerFactory;
+ protected CollectionFactory $usageCustomerCollectionFactory;
+ protected ScopeConfigInterface $scopeConfig;
+ protected UsageCustomerRepositoryInterface $usageCustomerRepository;
+ protected SearchCriteriaBuilder $searchCriteriaBuilder;
- /**
- * @var \DevStone\UsageCalculator\Model\UsageCustomerFactory
- */
- protected $usageCustomerFactory;
-
- /**
- * @var \DevStone\UsageCalculator\Model\ResourceModel\UsageCustomer\CollectionFactory
- */
- protected $usageCustomerCollectionFactory;
-
- /**
- * @var \Magento\Framework\App\Config\ScopeConfigInterface
- */
- protected $scopeConfig;
-
- /**
- * SaveCustomer constructor.
- * @param Config\ScopeConfigInterface $config
- * @param \DevStone\UsageCalculator\Model\UsageCustomerFactory $usageCustomerFactory
- * @param \DevStone\UsageCalculator\Model\ResourceModel\UsageCustomer\CollectionFactory $collectionFactory
- */
public function __construct(
- \Magento\Framework\App\Config\ScopeConfigInterface $config,
- \DevStone\UsageCalculator\Model\UsageCustomerFactory $usageCustomerFactory,
- \DevStone\UsageCalculator\Model\ResourceModel\UsageCustomer\CollectionFactory $collectionFactory
+ ScopeConfigInterface $config,
+ UsageCustomerFactory $usageCustomerFactory,
+ CollectionFactory $collectionFactory,
+ UsageCustomerRepositoryInterface $usageCustomerRepository,
+ SearchCriteriaBuilder $searchCriteriaBuilder
) {
$this->usageCustomerFactory = $usageCustomerFactory;
$this->usageCustomerCollectionFactory = $collectionFactory;
$this->scopeConfig = $config;
+ $this->usageCustomerRepository = $usageCustomerRepository;
+ $this->searchCriteriaBuilder = $searchCriteriaBuilder;
}
/**
* @param Observer $observer
- * @throws \Exception
+ * @throws Exception
*/
public function execute(Observer $observer)
{
/**
- * @var \Magento\Framework\App\RequestInterface $request
+ * @var RequestInterface $request
*/
$request = $observer->getData('request');
$customers = $request->getParam('usage_customers');
+ $pendingCustomers = $request->getParam('pending_customer_emails');
/**
- * @var \DevStone\UsageCalculator\Model\Usage $usage
+ * @var Usage $usage
*/
$usage = $observer->getData('usage');
$usageId = $usage->getEntityId();
-
+ $savedIds = [];
+ $searchCriteria = $this->searchCriteriaBuilder
+ ->addFilter('usage_id', $usage->getId())
+ ->addFilter('customer_id', 0, 'neq');
if (isset($customers)) {
+
$customersArray = json_decode($customers);
foreach ($customersArray as $customerId) {
$usageCustomer = $this->usageCustomerFactory->create();
- $usageCustomers = $this->usageCustomerCollectionFactory->create()
- ->addFieldToFilter('usage_id', ['eq' => $usageId])
- ->addFieldToFilter('customer_id', ['eq' => $customerId]);
+ $usageCustomer = $this->usageCustomerRepository->getByUsageAndCustomer($usageId, $customerId) ?? $usageCustomer;
+
+ $usageCustomer->setUsageId($usage->getId());
+ $usageCustomer->setCustomerId($customerId);
+ $usageCustomer = $this->usageCustomerRepository->save($usageCustomer);
+ $savedIds[] = $usageCustomer->getId();
+ }
+ $searchCriteria->addFilter('entity_id', $savedIds, 'nin');
+ }
+ $this->usageCustomerRepository->deleteList($searchCriteria->create());
+
+ $savedIds = [];
- //If usage already exsist then override its value
- if ($usageCustomers->getSize()) {
- $usageCustomer->setEntityId($usageCustomers->getFirstItem()->getEntityId());
+ $searchCriteria = $this->searchCriteriaBuilder
+ ->addFilter('usage_id', $usage->getId())
+ ->addFilter('customer_id', 0);
+ if (isset($pendingCustomers)) {
+ foreach ($pendingCustomers as $pendingCustomer) {
+ if (!isset($pendingCustomer['email']) || $pendingCustomer['email'] === "") {
+ continue;
}
+ $usageCustomer = $this->usageCustomerFactory->create();
- $usageCustomer->setUsageId($observer->getData('usage')->getId());
- $usageCustomer->setCustomerId($customerId);
- $usageCustomer->save();
+ $usageCustomer = $this->usageCustomerRepository->getByUsageAndEmail($usageId, $pendingCustomer['email']) ?? $usageCustomer;
+
+ $usageCustomer->setUsageId($usage->getId());
+ $usageCustomer->setPendingCustomerEmail($pendingCustomer['email']);
+ $usageCustomer = $this->usageCustomerRepository->save($usageCustomer);
+ $savedIds[] = $usageCustomer->getId();
}
+ $searchCriteria->addFilter('entity_id', $savedIds, 'nin');
}
+ $this->usageCustomerRepository->deleteList($searchCriteria->create());
}
/**
@@ -88,7 +109,7 @@ public function getCustomLicenseId()
{
return $this->scopeConfig->getValue(
'usage_cal/general/category_id',
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE
+ ScopeInterface::SCOPE_STORE
);
}
}
diff --git a/Plugin/Controller/Cart/Add.php b/Plugin/Controller/Cart/Add.php
index 84a6446..c2fb3cb 100644
--- a/Plugin/Controller/Cart/Add.php
+++ b/Plugin/Controller/Cart/Add.php
@@ -8,72 +8,46 @@
namespace DevStone\UsageCalculator\Plugin\Controller\Cart;
+use DevStone\UsageCalculator\Api\UsageRepositoryInterface;
+use DevStone\UsageCalculator\Helper\Data;
+use Magento\Checkout\Controller\Cart\Add as AddSubject;
+use Magento\Checkout\Model\Session;
+use Magento\Customer\Model\Session as CustomerSession;
+use Magento\Framework\App\Config\ScopeConfigInterface;
+use Magento\Framework\App\RequestInterface;
+use Magento\Framework\Controller\Result\RedirectFactory;
+use Magento\Framework\Exception\LocalizedException;
+use Magento\Framework\Message\ManagerInterface;
+use Magento\Sales\Api\Data\OrderItemInterface;
+use Magento\Sales\Model\Order;
+use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
+
/**
* Class Add
* @package DevStone\UsageCalculator\Plugin\Controller\Cart
*/
class Add
{
- /**
- * @var \Magento\Customer\Model\Session
- */
- private $customerSession;
-
- /**
- * @var \Magento\Framework\App\RequestInterface
- */
- private $request;
-
- /**
- * @var \DevStone\UsageCalculator\Api\UsageRepositoryInterface
- */
- private $usageRepository;
-
- /**
- * @var \Magento\Sales\Model\ResourceModel\Order\CollectionFactory
- */
- private $orderCollectionFactory;
-
- /**
- * @var \Magento\Checkout\Model\Session
- */
- private $checkoutSession;
+ protected CustomerSession $customerSession;
+ protected RequestInterface $request;
+ protected UsageRepositoryInterface $usageRepository;
+ protected CollectionFactory $orderCollectionFactory;
+ protected Session $checkoutSession;
+ protected ScopeConfigInterface $scopeConfig;
+ protected ManagerInterface $messageInterface;
+ protected RedirectFactory $resultRedirectFactory;
+ private Data $data;
- /**
- * @var \Magento\Framework\App\Config\ScopeConfigInterface
- */
- private $scopeConfig;
-
- /**
- * @var \Magento\Framework\Message\ManagerInterface
- */
- private $messageInterface;
-
- /**
- * @var \Magento\Framework\Controller\Result\RedirectFactory
- */
- private $resultRedirectFactory;
-
- /**
- * Add constructor.
- * @param \Magento\Customer\Model\Session $session
- * @param \Magento\Framework\App\RequestInterface $request
- * @param \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory
- * @param \Magento\Checkout\Model\Session $checkoutSession
- * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
- * @param \Magento\Framework\Message\ManagerInterface $messageInterface
- * @param \Magento\Framework\Controller\Result\RedirectFactory $redirectFactory
- * @param \DevStone\UsageCalculator\Api\UsageRepositoryInterface $usageRepository
- */
public function __construct(
- \Magento\Customer\Model\Session $session,
- \Magento\Framework\App\RequestInterface $request,
- \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
- \Magento\Checkout\Model\Session $checkoutSession,
- \Magento\Framework\App\Config\ScopeConfigInterface $config,
- \Magento\Framework\Message\ManagerInterface $messageInterface,
- \Magento\Framework\Controller\Result\RedirectFactory $redirectFactory,
- \DevStone\UsageCalculator\Api\UsageRepositoryInterface $usageRepository
+ CustomerSession $session,
+ RequestInterface $request,
+ CollectionFactory $orderCollectionFactory,
+ Session $checkoutSession,
+ ScopeConfigInterface $config,
+ ManagerInterface $messageInterface,
+ RedirectFactory $redirectFactory,
+ UsageRepositoryInterface $usageRepository,
+ Data $data
) {
$this->request = $request;
$this->customerSession = $session;
@@ -83,48 +57,45 @@ public function __construct(
$this->scopeConfig = $config;
$this->messageInterface = $messageInterface;
$this->resultRedirectFactory = $redirectFactory;
+ $this->data = $data;
}
- /**
- * @param \Magento\Checkout\Controller\Cart\Add $subject
- * @param callable $proceed
- * @return mixed
- */
- public function aroundExecute(\Magento\Checkout\Controller\Cart\Add $subject, callable $proceed)
+ public function aroundExecute(AddSubject $subject, callable $proceed): mixed
{
$usageId = $this->request->getParam('usage_id');
- if ($this->request->getParam('usage_category') != $this->getCustomLicenseId()) {
+ if ($this->request->getParam('usage_category') != $this->data->getCustomLicenseId()) {
return $proceed();
- } elseif (array_key_exists($this->getCustomLicenseId(), $usageId)) {
+ } elseif (array_key_exists($this->data->getCustomLicenseId(), $usageId)) {
if ($this->customerSession->isLoggedIn()) {
- $customerLicensedUsage = $this->usageRepository->getById($usageId[$this->getCustomLicenseId()]);
- if ($customerLicensedUsage) {
- $maxUsage = $customerLicensedUsage->getMaxUsage();
- if (!isset($maxUsage)|| !($maxUsage > 0)) {
- return $proceed();
- }
- $totalUsageCountByOrder = $this->getUsageCountByOrders($usageId);
- $totalUsageCountByQuote = $this->getUsageCountByQuote($usageId);
- if (($totalUsageCountByOrder + $totalUsageCountByQuote) < $maxUsage) {
- return $proceed();
- } else {
- $this->messageInterface->addErrorMessage(
- __('You cannot add this item to your cart because this
- custom license can only be used %1 times', $maxUsage)
- );
- return $this->resultRedirectFactory->create()->setPath('*/*/');
+ try {
+ $customerLicensedUsage = $this->usageRepository->getById($usageId[$this->data->getCustomLicenseId()]);
+ if ($customerLicensedUsage) {
+ $maxUsage = $customerLicensedUsage->getMaxUsage();
+ if (!isset($maxUsage) || !($maxUsage > 0)) {
+ return $proceed();
+ }
+ $totalUsageCountByOrder = $this->getUsageCountByOrders($usageId);
+ $totalUsageCountByQuote = $this->getUsageCountByQuote($usageId);
+
+ if (($totalUsageCountByOrder + $totalUsageCountByQuote) < $maxUsage) {
+ return $proceed();
+ } else {
+ $this->messageInterface->addErrorMessage(
+ __('You cannot add this item to your cart because this
+ custom license can only be used %1 time(s)', $maxUsage)
+ );
+ return $this->resultRedirectFactory->create()->setPath('*/*/');
+ }
}
+ } catch (LocalizedException $e) {
+
}
}
}
return $proceed();
}
- /**
- * @param $usageId
- * @return int
- */
- public function getUsageCountByOrders($usageId)
+ public function getUsageCountByOrders($usageId): int
{
$totalUsageCount = 0;
$ordersCollection = $this->orderCollectionFactory->create()
@@ -133,14 +104,14 @@ public function getUsageCountByOrders($usageId)
->setPageSize(20)
->setOrder('created_at', 'desc');
/**
- * @var \Magento\Sales\Model\Order $order
- * @var \Magento\Sales\Api\Data\OrderItemInterface $item
+ * @var Order $order
+ * @var OrderItemInterface $item
*/
foreach ($ordersCollection as $order) {
$items = $order->getAllVisibleItems();
foreach ($items as $item) {
$productOptions = $item->getProductOptions();
- if (isset($productOptions['usage_id']) && $usageId === $productOptions['usage_id']) {
+ if (isset($productOptions['usage_id']) && $usageId[$this->data->getCustomLicenseId()] === $productOptions['usage_id']) {
$totalUsageCount++;
}
}
@@ -149,40 +120,28 @@ public function getUsageCountByOrders($usageId)
return $totalUsageCount;
}
- /**
- * @return mixed
- */
- public function getCustomLicenseId()
- {
- return $this->scopeConfig->getValue(
- 'usage_cal/general/category_id',
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE
- );
- }
-
- /**
- * @param $usageId
- * @return int
- * @throws \Magento\Framework\Exception\LocalizedException
- * @throws \Magento\Framework\Exception\NoSuchEntityException
- */
- public function getUsageCountByQuote($usageId)
+ public function getUsageCountByQuote($usageId): int
{
$totalUsageCount = 0;
- $items = $this->checkoutSession->getQuote()->getAllVisibleItems();
- foreach ($items as $item) {
- $buyRequest = $item->getBuyRequest();
- $categoryId = $buyRequest->getUsageCategory();
- if ($categoryId == $this->getCustomLicenseId()) {
- $usageIds = $buyRequest->getUsageId();
- if (array_key_exists($this->getCustomLicenseId(), $usageIds)) {
- if ($usageIds[$this->getCustomLicenseId()] == $usageId[$this->getCustomLicenseId()]) {
- $totalUsageCount++;
+ try {
+ $items = $this->checkoutSession->getQuote()->getAllVisibleItems();
+ foreach ($items as $item) {
+ $buyRequest = $item->getBuyRequest();
+ $categoryId = $buyRequest->getUsageCategory();
+ if ($categoryId == $this->data->getCustomLicenseId()) {
+ $usageIds = $buyRequest->getUsageId();
+ if (array_key_exists($this->data->getCustomLicenseId(), $usageIds)) {
+ if ($usageIds[$this->data->getCustomLicenseId()] == $usageId[$this->data->getCustomLicenseId()]) {
+ $totalUsageCount++;
+ }
}
}
}
- }
+ return $totalUsageCount;
+ } catch (LocalizedException $e) {
+
+ }
return $totalUsageCount;
}
}
diff --git a/Setup/EavTablesSetup.php b/Setup/EavTablesSetup.php
deleted file mode 100644
index dc6f843..0000000
--- a/Setup/EavTablesSetup.php
+++ /dev/null
@@ -1,203 +0,0 @@
-setup = $setup;
- }
-
- public function createEavTables($entityCode)
- {
- $this->createEAVMainTable($entityCode);
- $this->createEntityTable($entityCode, 'datetime', Table::TYPE_DATETIME);
- $this->createEntityTable($entityCode, 'decimal', Table::TYPE_DECIMAL, '12,4');
- $this->createEntityTable($entityCode, 'int', Table::TYPE_INTEGER);
- $this->createEntityTable($entityCode, 'text', Table::TYPE_TEXT, '64k');
- $this->createEntityTable($entityCode, 'varchar', Table::TYPE_TEXT, 255);
- }
-
- protected function createEAVMainTable($entityCode)
- {
- $tableName = $entityCode . '_eav_attribute';
-
- $table = $this->setup->getConnection()->newTable(
- $this->setup->getTable($tableName)
- )->addColumn(
- 'attribute_id',
- Table::TYPE_SMALLINT,
- null,
- ['identity' => false, 'unsigned' => true, 'nullable' => false, 'primary' => true],
- 'Attribute Id'
- )->addColumn(
- 'is_global',
- Table::TYPE_SMALLINT,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '1'],
- 'Is Global'
- )->addColumn(
- 'is_filterable',
- Table::TYPE_SMALLINT,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Is Filterable'
- )->addColumn(
- 'is_visible',
- Table::TYPE_SMALLINT,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '1'],
- 'Is Visible'
- )->addColumn(
- 'validate_rules',
- Table::TYPE_TEXT,
- '64k',
- [],
- 'Validate Rules'
- )->addColumn(
- 'is_system',
- Table::TYPE_SMALLINT,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Is System'
- )->addColumn(
- 'sort_order',
- Table::TYPE_INTEGER,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Sort Order'
- )->addColumn(
- 'data_model',
- Table::TYPE_TEXT,
- 255,
- [],
- 'Data Model'
- )->addForeignKey(
- $this->setup->getFkName($tableName, 'attribute_id', 'eav_attribute', 'attribute_id'),
- 'attribute_id',
- $this->setup->getTable('eav_attribute'),
- 'attribute_id',
- Table::ACTION_CASCADE
- )->setComment(
- $entityCode . 'Eav Attribute'
- );
- $this->setup->getConnection()->createTable($table);
- }
-
- protected function createEntityTable($entityCode, $type, $valueType, $valueLength = null)
- {
- $tableName = $entityCode . '_entity_' . $type;
-
- $table = $this->setup->getConnection()
- ->newTable($this->setup->getTable($tableName))
- ->addColumn(
- 'value_id',
- Table::TYPE_INTEGER,
- null,
- ['identity' => true, 'nullable' => false, 'primary' => true],
- 'Value ID'
- )
- ->addColumn(
- 'attribute_id',
- Table::TYPE_SMALLINT,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Attribute ID'
- )
- ->addColumn(
- 'store_id',
- Table::TYPE_SMALLINT,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Store ID'
- )
- ->addColumn(
- 'entity_id',
- Table::TYPE_INTEGER,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Entity ID'
- )
- ->addColumn(
- 'value',
- $valueType,
- $valueLength,
- [],
- 'Value'
- )
- ->addIndex(
- $this->setup->getIdxName(
- $tableName,
- ['entity_id', 'attribute_id', 'store_id'],
- AdapterInterface::INDEX_TYPE_UNIQUE
- ),
- ['entity_id', 'attribute_id', 'store_id'],
- ['type' => AdapterInterface::INDEX_TYPE_UNIQUE]
- )
- ->addIndex(
- $this->setup->getIdxName($tableName, ['entity_id']),
- ['entity_id']
- )
- ->addIndex(
- $this->setup->getIdxName($tableName, ['attribute_id']),
- ['attribute_id']
- )
- ->addIndex(
- $this->setup->getIdxName($tableName, ['store_id']),
- ['store_id']
- )
- ->addForeignKey(
- $this->setup->getFkName(
- $tableName,
- 'attribute_id',
- 'eav_attribute',
- 'attribute_id'
- ),
- 'attribute_id',
- $this->setup->getTable('eav_attribute'),
- 'attribute_id',
- Table::ACTION_CASCADE
- )
- ->addForeignKey(
- $this->setup->getFkName(
- $tableName,
- 'entity_id',
- $entityCode,
- 'entity_id'
- ),
- 'entity_id',
- $this->setup->getTable($entityCode . '_entity'),
- 'entity_id',
- Table::ACTION_CASCADE
- )
- ->addForeignKey(
- $this->setup->getFkName($tableName, 'store_id', 'store', 'store_id'),
- 'store_id',
- $this->setup->getTable('store'),
- 'store_id',
- Table::ACTION_CASCADE
- )
- ->setComment($entityCode . ' ' . $type . 'Attribute Backend Table');
- $this->setup->getConnection()->createTable($table);
- }
-}
diff --git a/Setup/InstallSchema.php b/Setup/InstallSchema.php
deleted file mode 100644
index 34025ca..0000000
--- a/Setup/InstallSchema.php
+++ /dev/null
@@ -1,710 +0,0 @@
-eavTablesSetupFactory = $eavTablesSetupFactory;
- }
-
- /**
- * {@inheritdoc}
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- */
- public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) //@codingStandardsIgnoreLine
- {
- $setup->startSetup();
-
- /** @var \DevStone\UsageCalculator\Setup\EavTablesSetup $eavTablesSetup */
- $eavTablesSetup = $this->eavTablesSetupFactory->create(['setup' => $setup]);
-
- $categoryTableName = 'devstone_usage_category';
-
- $categoryTable = $setup->getConnection()
- ->newTable($setup->getTable($categoryTableName))
- ->addColumn(
- 'entity_id',
- Table::TYPE_INTEGER,
- null,
- ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
- 'Entity ID'
- )->addColumn(
- 'name',
- \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
- 100,
- ['nullable' => false, 'default' => ''],
- 'Category Name'
- )->addColumn(
- 'terms',
- \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
- 10000,
- ['nullable' => false, 'default' => ''],
- 'Category Terms'
- )->addColumn(
- 'created_at',
- Table::TYPE_TIMESTAMP,
- null,
- ['nullable' => false, 'default' => Table::TIMESTAMP_INIT],
- 'Creation Time'
- )->addColumn(
- 'updated_at',
- Table::TYPE_TIMESTAMP,
- null,
- ['nullable' => false, 'default' => Table::TIMESTAMP_INIT_UPDATE],
- 'Update Time'
- )->setComment('Usage Category Entity Table');
-
- $setup->getConnection()->createTable($categoryTable);
-
- $sizeTableName = 'devstone_downloadable_image_size';
-
- $sizeTable = $setup->getConnection()
- ->newTable($setup->getTable($sizeTableName))
- ->addColumn(
- 'entity_id',
- Table::TYPE_INTEGER,
- null,
- ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
- 'Entity ID'
- )->addColumn(
- 'is_active',
- \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '1'],
- 'Is Active'
- )->addColumn(
- 'max_width',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'maximum width in pixels (0 unlimited)'
- )->addColumn(
- 'max_height',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'maximum width in pixels (0 unlimited)'
- )->addColumn(
- 'code',
- \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
- 100,
- ['nullable' => false, 'default' => ''],
- 'code to identify size'
- )->addColumn(
- 'created_at',
- Table::TYPE_TIMESTAMP,
- null,
- ['nullable' => false, 'default' => Table::TIMESTAMP_INIT],
- 'Creation Time'
- )->addColumn(
- 'updated_at',
- Table::TYPE_TIMESTAMP,
- null,
- ['nullable' => false, 'default' => Table::TIMESTAMP_INIT_UPDATE],
- 'Update Time'
- )->setComment('Downloadable image sizes');
-
- $setup->getConnection()->createTable($sizeTable);
-
- $tableName = UsageSetup::ENTITY_TYPE_CODE . '_entity';
-
- $table = $setup->getConnection()
- ->newTable($setup->getTable($tableName))
- ->addColumn(
- 'entity_id',
- Table::TYPE_INTEGER,
- null,
- ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
- 'Entity ID'
- )->setComment('Usage Entity Table');
- $table->addColumn(
- 'category_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Usage Category Id'
- )->addIndex(
- $setup->getIdxName($tableName, ['category_id']),
- ['category_id']
- )->addForeignKey(
- $setup->getFkName($tableName, 'category_id', $categoryTableName, 'entity_id'),
- 'category_id',
- $setup->getTable($categoryTableName),
- 'entity_id'
- )->addColumn(
- 'is_active',
- \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '1'],
- 'Is Active'
- );
-
- $table->addColumn(
- 'size_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Usage Size Id'
- )->addIndex(
- $setup->getIdxName($tableName, ['size_id']),
- ['size_id']
- )->addForeignKey(
- $setup->getFkName($tableName, 'size_id', $sizeTableName, 'entity_id'),
- 'size_id',
- $setup->getTable($sizeTableName),
- 'entity_id'
- );
-
- $table->addColumn(
- 'created_at',
- Table::TYPE_TIMESTAMP,
- null,
- ['nullable' => false, 'default' => Table::TIMESTAMP_INIT],
- 'Creation Time'
- )->addColumn(
- 'updated_at',
- Table::TYPE_TIMESTAMP,
- null,
- ['nullable' => false, 'default' => Table::TIMESTAMP_INIT_UPDATE],
- 'Update Time'
- );
-
- $setup->getConnection()->createTable($table);
-
- $eavTablesSetup->createEavTables(UsageSetup::ENTITY_TYPE_CODE);
-
-
- /**
- * Create table 'devstone_usage_option'
- */
- $table = $setup->getConnection()
- ->newTable(
- $setup->getTable(UsageSetup::ENTITY_TYPE_CODE.'_option')
- )
- ->addColumn(
- 'option_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
- 'Option ID'
- )
- ->addColumn(
- 'usage_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Usage ID'
- )
- ->addColumn(
- 'type',
- \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
- 50,
- ['nullable' => true, 'default' => null],
- 'Type'
- )
- ->addColumn(
- 'is_require',
- \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
- null,
- ['nullable' => false, 'default' => '1'],
- 'Is Required'
- )
- ->addColumn(
- 'sort_order',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Sort Order'
- )
- ->addIndex(
- $setup->getIdxName(UsageSetup::ENTITY_TYPE_CODE.'_option', ['usage_id']),
- ['usage_id']
- )
- ->addForeignKey(
- $setup->getFkName(UsageSetup::ENTITY_TYPE_CODE.'_option', 'usage_id', UsageSetup::ENTITY_TYPE_CODE.'_entity', 'entity_id'),
- 'usage_id',
- $setup->getTable(UsageSetup::ENTITY_TYPE_CODE.'_entity'),
- 'entity_id',
- \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
- )
- ->setComment(
- 'Usage Option Table'
- );
- $setup->getConnection()
- ->createTable($table);
-
- /**
- * Create table 'devstone_usage_option_price'
- */
- $table = $setup->getConnection()
- ->newTable(
- $setup->getTable(UsageSetup::ENTITY_TYPE_CODE.'_option_price')
- )
- ->addColumn(
- 'option_price_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
- 'Option Price ID'
- )
- ->addColumn(
- 'option_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Option ID'
- )
- ->addColumn(
- 'store_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Store ID'
- )
- ->addColumn(
- 'price',
- \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
- '12,4',
- ['nullable' => false, 'default' => '0.0000'],
- 'Price'
- )
- ->addColumn(
- 'price_type',
- \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
- 7,
- ['nullable' => false, 'default' => 'fixed'],
- 'Price Type'
- )
- ->addIndex(
- $setup->getIdxName(
- UsageSetup::ENTITY_TYPE_CODE.'_option_price',
- ['option_id', 'store_id'],
- \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE
- ),
- ['option_id', 'store_id'],
- ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE]
- )
- ->addIndex(
- $setup->getIdxName(UsageSetup::ENTITY_TYPE_CODE.'_option_price', ['store_id']),
- ['store_id']
- )
- ->addForeignKey(
- $setup->getFkName(
- UsageSetup::ENTITY_TYPE_CODE.'_option_price',
- 'option_id',
- UsageSetup::ENTITY_TYPE_CODE.'_option',
- 'option_id'
- ),
- 'option_id',
- $setup->getTable(UsageSetup::ENTITY_TYPE_CODE.'_option'),
- 'option_id',
- \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
- )
- ->addForeignKey(
- $setup->getFkName(UsageSetup::ENTITY_TYPE_CODE.'_option_price', 'store_id', 'store', 'store_id'),
- 'store_id',
- $setup->getTable('store'),
- 'store_id',
- \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
- )
- ->setComment(
- 'Usage Option Price Table'
- );
- $setup->getConnection()
- ->createTable($table);
-
- /**
- * Create table 'devstone_usage_option_title'
- */
- $table = $setup->getConnection()
- ->newTable(
- $setup->getTable(UsageSetup::ENTITY_TYPE_CODE.'_option_title')
- )
- ->addColumn(
- 'option_title_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
- 'Option Title ID'
- )
- ->addColumn(
- 'option_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Option ID'
- )
- ->addColumn(
- 'store_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Store ID'
- )
- ->addColumn(
- 'title',
- \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
- 255,
- ['nullable' => true, 'default' => null],
- 'Title'
- )
- ->addIndex(
- $setup->getIdxName(
- UsageSetup::ENTITY_TYPE_CODE.'_option_title',
- ['option_id', 'store_id'],
- \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE
- ),
- ['option_id', 'store_id'],
- ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE]
- )
- ->addIndex(
- $setup->getIdxName(UsageSetup::ENTITY_TYPE_CODE.'_option_title', ['store_id']),
- ['store_id']
- )
- ->addForeignKey(
- $setup->getFkName(
- UsageSetup::ENTITY_TYPE_CODE.'_option_title',
- 'option_id',
- UsageSetup::ENTITY_TYPE_CODE.'_option',
- 'option_id'
- ),
- 'option_id',
- $setup->getTable(UsageSetup::ENTITY_TYPE_CODE.'_option'),
- 'option_id',
- \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
- )
- ->addForeignKey(
- $setup->getFkName(UsageSetup::ENTITY_TYPE_CODE.'_option_title', 'store_id', 'store', 'store_id'),
- 'store_id',
- $setup->getTable('store'),
- 'store_id',
- \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
- )
- ->setComment(
- 'Usage Option Title Table'
- );
- $setup->getConnection()
- ->createTable($table);
-
- /**
- * Create table 'devstone_usage_option_help'
- */
- $table = $setup->getConnection()
- ->newTable(
- $setup->getTable(UsageSetup::ENTITY_TYPE_CODE.'_option_help')
- )
- ->addColumn(
- 'option_help_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
- 'Option Title ID'
- )
- ->addColumn(
- 'option_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Option ID'
- )
- ->addColumn(
- 'store_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Store ID'
- )
- ->addColumn(
- 'help',
- \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
- 1024,
- ['nullable' => true, 'default' => null],
- 'Help Text'
- )
- ->addIndex(
- $setup->getIdxName(
- UsageSetup::ENTITY_TYPE_CODE.'_option_help',
- ['option_id', 'store_id'],
- \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE
- ),
- ['option_id', 'store_id'],
- ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE]
- )
- ->addIndex(
- $setup->getIdxName(UsageSetup::ENTITY_TYPE_CODE.'_option_title', ['store_id']),
- ['store_id']
- )
- ->addForeignKey(
- $setup->getFkName(
- UsageSetup::ENTITY_TYPE_CODE.'_option_help',
- 'option_id',
- UsageSetup::ENTITY_TYPE_CODE.'_option',
- 'option_id'
- ),
- 'option_id',
- $setup->getTable(UsageSetup::ENTITY_TYPE_CODE.'_option'),
- 'option_id',
- \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
- )
- ->addForeignKey(
- $setup->getFkName(UsageSetup::ENTITY_TYPE_CODE.'_option_help', 'store_id', 'store', 'store_id'),
- 'store_id',
- $setup->getTable('store'),
- 'store_id',
- \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
- )
- ->setComment(
- 'Usage Option Help Text Table'
- );
- $setup->getConnection()
- ->createTable($table);
-
-
- /**
- * Create table 'devstone_usage_option_type_value'
- */
- $table = $setup->getConnection()
- ->newTable(
- $setup->getTable(UsageSetup::ENTITY_TYPE_CODE.'_option_type_value')
- )
- ->addColumn(
- 'option_type_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
- 'Option Type ID'
- )
- ->addColumn(
- 'option_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Option ID'
- )
- ->addColumn(
- 'size_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['unsigned' => true, 'nullable' => true, 'default' => 'NULL'],
- 'Usage Option Size Id'
- )->addIndex(
- $setup->getIdxName(UsageSetup::ENTITY_TYPE_CODE.'_option_type_value', ['size_id']),
- ['size_id']
- )->addForeignKey(
- $setup->getFkName(UsageSetup::ENTITY_TYPE_CODE.'_option_type_value', 'size_id', $sizeTableName, 'entity_id'),
- 'size_id',
- $setup->getTable($sizeTableName),
- 'entity_id'
- )
- ->addColumn(
- 'sort_order',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Sort Order'
- )
- ->addIndex(
- $setup->getIdxName(UsageSetup::ENTITY_TYPE_CODE.'_option_type_value', ['option_id']),
- ['option_id']
- )
- ->addForeignKey(
- $setup->getFkName(
- UsageSetup::ENTITY_TYPE_CODE.'_option_type_value',
- 'option_id',
- UsageSetup::ENTITY_TYPE_CODE.'_option',
- 'option_id'
- ),
- 'option_id',
- $setup->getTable(UsageSetup::ENTITY_TYPE_CODE.'_option'),
- 'option_id',
- \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
- )
- ->setComment(
- 'Usage Option Type Value Table'
- );
- $setup->getConnection()
- ->createTable($table);
-
- /**
- * Create table 'devstone_usage_option_type_price'
- */
- $table = $setup->getConnection()
- ->newTable(
- $setup->getTable(UsageSetup::ENTITY_TYPE_CODE.'_option_type_price')
- )
- ->addColumn(
- 'option_type_price_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
- 'Option Type Price ID'
- )
- ->addColumn(
- 'option_type_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Option Type ID'
- )
- ->addColumn(
- 'store_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Store ID'
- )
- ->addColumn(
- 'price',
- \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
- '12,4',
- ['nullable' => false, 'default' => '0.0000'],
- 'Price'
- )
- ->addColumn(
- 'price_type',
- \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
- 7,
- ['nullable' => false, 'default' => 'fixed'],
- 'Price Type'
- )
- ->addIndex(
- $setup->getIdxName(
- UsageSetup::ENTITY_TYPE_CODE.'_option_type_price',
- ['option_type_id', 'store_id'],
- \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE
- ),
- ['option_type_id', 'store_id'],
- ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE]
- )
- ->addIndex(
- $setup->getIdxName(UsageSetup::ENTITY_TYPE_CODE.'_option_type_price', ['store_id']),
- ['store_id']
- )
- ->addForeignKey(
- $setup->getFkName(
- UsageSetup::ENTITY_TYPE_CODE.'_option_type_price',
- 'option_type_id',
- UsageSetup::ENTITY_TYPE_CODE.'_option_type_value',
- 'option_type_id'
- ),
- 'option_type_id',
- $setup->getTable(UsageSetup::ENTITY_TYPE_CODE.'_option_type_value'),
- 'option_type_id',
- \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
- )
- ->addForeignKey(
- $setup->getFkName(UsageSetup::ENTITY_TYPE_CODE.'_option_type_price', 'store_id', 'store', 'store_id'),
- 'store_id',
- $setup->getTable('store'),
- 'store_id',
- \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
- )
- ->setComment(
- 'Usage Option Type Price Table'
- );
- $setup->getConnection()
- ->createTable($table);
-
- /**
- * Create table 'devstone_usage_option_type_title'
- */
- $table = $setup->getConnection()
- ->newTable(
- $setup->getTable(UsageSetup::ENTITY_TYPE_CODE.'_option_type_title')
- )
- ->addColumn(
- 'option_type_title_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
- 'Option Type Title ID'
- )
- ->addColumn(
- 'option_type_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Option Type ID'
- )
- ->addColumn(
- 'store_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
- null,
- ['unsigned' => true, 'nullable' => false, 'default' => '0'],
- 'Store ID'
- )
- ->addColumn(
- 'title',
- \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
- 255,
- ['nullable' => true, 'default' => null],
- 'Title'
- )
- ->addIndex(
- $setup->getIdxName(
- UsageSetup::ENTITY_TYPE_CODE.'_option_type_title',
- ['option_type_id', 'store_id'],
- \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE
- ),
- ['option_type_id', 'store_id'],
- ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE]
- )
- ->addIndex(
- $setup->getIdxName(UsageSetup::ENTITY_TYPE_CODE.'_option_type_title', ['store_id']),
- ['store_id']
- )
- ->addForeignKey(
- $setup->getFkName(
- UsageSetup::ENTITY_TYPE_CODE.'_option_type_title',
- 'option_type_id',
- UsageSetup::ENTITY_TYPE_CODE.'_option_type_value',
- 'option_type_id'
- ),
- 'option_type_id',
- $setup->getTable(UsageSetup::ENTITY_TYPE_CODE.'_option_type_value'),
- 'option_type_id',
- \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
- )
- ->addForeignKey(
- $setup->getFkName(UsageSetup::ENTITY_TYPE_CODE.'_option_type_title', 'store_id', 'store', 'store_id'),
- 'store_id',
- $setup->getTable('store'),
- 'store_id',
- \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
- )
- ->setComment(
- 'Usage Option Type Title Table'
- );
- $setup->getConnection()
- ->createTable($table);
-
- $setup->endSetup();
- }
-}
diff --git a/Setup/Uninstall.php b/Setup/Uninstall.php
deleted file mode 100644
index 8a8b384..0000000
--- a/Setup/Uninstall.php
+++ /dev/null
@@ -1,55 +0,0 @@
-startSetup();
-
- foreach ($this->tablesToUninstall as $table) {
- if ($setup->tableExists($table)) {
- $setup->getConnection()->dropTable($setup->getTable($table));
- }
- }
-
- $setup->endSetup();
- }
-}
diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php
deleted file mode 100644
index da9f9f0..0000000
--- a/Setup/UpgradeSchema.php
+++ /dev/null
@@ -1,79 +0,0 @@
-startSetup();
-
- if (version_compare($context->getVersion(), '1.0.3', '<')) {
- if (!$installer->tableExists(UsageSetup::ENTITY_TYPE_CODE . '_customer')) {
- $table = $installer->getConnection()->newTable(
- $installer->getTable(UsageSetup::ENTITY_TYPE_CODE . '_customer')
- )->addColumn(
- 'entity_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- [
- 'identity' => true,
- 'nullable' => false,
- 'primary' => true,
- 'unsigned' => true,
- ],
- 'ID'
- )
- ->addColumn(
- 'usage_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- [
- 'nullable' => false,
- 'unsigned' => true,
- ],
- 'Usage ID'
- )
- ->addColumn(
- 'customer_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- [
- 'nullable' => false,
- 'unsigned' => true,
- ],
- 'Customer ID'
- )
- ->addColumn(
- 'created_at',
- \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
- null,
- ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
- 'Created At'
- )->addColumn(
- 'updated_at',
- \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
- null,
- ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE],
- 'Updated At'
- )->setComment('Devstone Custom License Customer Table');
- $installer->getConnection()->createTable($table);
- }
- }
- $installer->endSetup();
- }
-}
diff --git a/Ui/Component/Form/Usage/DataProvider.php b/Ui/Component/Form/Usage/DataProvider.php
index 82743bc..1aa2b25 100644
--- a/Ui/Component/Form/Usage/DataProvider.php
+++ b/Ui/Component/Form/Usage/DataProvider.php
@@ -90,6 +90,7 @@ public function __construct(
* Get data
*
* @return array
+ * @throws \Magento\Framework\Exception\LocalizedException
*/
public function getData()
{
@@ -107,6 +108,9 @@ public function getData()
}
$this->loadedData = $this->usageOptions->modifydata($this->loadedData);
+ foreach ($this->pool->getModifiersInstances() as $modifier) {
+ $this->loadedData = $modifier->modifyData($this->loadedData);
+ }
}
return $this->loadedData;
}
diff --git a/Ui/Component/Form/Usage/Modifier/CustomLicense.php b/Ui/Component/Form/Usage/Modifier/CustomLicense.php
index 42b3a8b..91f98df 100644
--- a/Ui/Component/Form/Usage/Modifier/CustomLicense.php
+++ b/Ui/Component/Form/Usage/Modifier/CustomLicense.php
@@ -2,35 +2,40 @@
namespace DevStone\UsageCalculator\Ui\Component\Form\Usage\Modifier;
+use DevStone\UsageCalculator\Api\Data\UsageCustomerInterface;
+use DevStone\UsageCalculator\Api\UsageRepositoryInterface;
+use DevStone\UsageCalculator\Model\ResourceModel\UsageCustomer\CollectionFactory;
+use DevStone\UsageCalculator\Model\Usage\CatagoriesOptionsProvider;
+use Magento\Framework\App\RequestInterface;
+use Magento\Framework\Exception\LocalizedException;
+use Magento\Ui\Component\Form\Element\DataType\Number;
+use Magento\Ui\Component\Form\Element\Input;
+use Magento\Ui\Component\Form\Field;
+use Magento\Ui\DataProvider\Modifier\ModifierInterface;
+
/**
* Class CustomLicense
* @package DevStone\UsageCalculator\Ui\Component\Form\Usage\Modifier
*/
-class CustomLicense implements \Magento\Ui\DataProvider\Modifier\ModifierInterface
+class CustomLicense implements ModifierInterface
{
const FIELD_NAME = 'max_usage';
- /**
- * @var \Magento\Framework\App\RequestInterface
- */
- protected $request;
-
- /**
- * @var \DevStone\UsageCalculator\Model\Usage\CatagoriesOptionsProvider
- */
- protected $catagoriesOptionsProvider;
+ protected RequestInterface $request;
+ protected CatagoriesOptionsProvider $categoriesOptionsProvider;
+ protected UsageRepositoryInterface $usageRepository;
+ protected CollectionFactory $usageCustomerCollectionFactory;
- /**
- * CustomLicense constructor.
- * @param \Magento\Framework\App\RequestInterface $request
- * @param \DevStone\UsageCalculator\Model\Usage\CatagoriesOptionsProvider $catagoriesOptionsProvider
- */
public function __construct(
- \Magento\Framework\App\RequestInterface $request,
- \DevStone\UsageCalculator\Model\Usage\CatagoriesOptionsProvider $catagoriesOptionsProvider
+ RequestInterface $request,
+ CatagoriesOptionsProvider $categoriesOptionsProvider,
+ UsageRepositoryInterface $usageRepository,
+ CollectionFactory $usageCustomerCollectionFactory
) {
$this->request = $request;
- $this->catagoriesOptionsProvider = $catagoriesOptionsProvider;
+ $this->categoriesOptionsProvider = $categoriesOptionsProvider;
+ $this->usageRepository = $usageRepository;
+ $this->usageCustomerCollectionFactory = $usageCustomerCollectionFactory;
}
/**
@@ -40,6 +45,30 @@ public function __construct(
*/
public function modifyData(array $data)
{
+ foreach ($data as &$item) {
+ $customLicense = $this->request->getParam('custom_license');
+ if (isset($item['entity_id']) && isset($customLicense) && $customLicense) {
+ try {
+ $usage = $this->usageRepository->getById($item['entity_id']);
+ if ($usage->getId()) {
+ $usageCustomers = $this->usageCustomerCollectionFactory->create()
+ ->addFieldToFilter('usage_id', ['eq' => $usage->getId()]);
+ if ($usageCustomers->getSize()) {
+ /** @var UsageCustomerInterface $usageCustomer */
+ foreach ($usageCustomers->getItems() as $usageCustomer) {
+ if ($usageCustomer->getPendingCustomerEmail() !== "" && !$usageCustomer->getCustomerId()) {
+ $item['pending_customer_emails'][] = [
+ 'email' => $usageCustomer->getPendingCustomerEmail()
+ ];
+ }
+ }
+ }
+ }
+ } catch (LocalizedException $e) {
+
+ }
+ }
+ }
return $data;
}
@@ -62,7 +91,7 @@ public function modifyMeta(array $meta)
'arguments' => [
'data' => [
'config' => [
- 'options' => $this->catagoriesOptionsProvider->customLicenseOption()
+ 'options' => $this->categoriesOptionsProvider->customLicenseOption()
]
]
]
@@ -83,7 +112,7 @@ public function modifyMeta(array $meta)
'arguments' => [
'data' => [
'config' => [
- 'options' => $this->catagoriesOptionsProvider->allOptionsExcludingCustomLicense()
+ 'options' => $this->categoriesOptionsProvider->allOptionsExcludingCustomLicense()
]
]
]
@@ -106,10 +135,10 @@ protected function getMaxUsage()
'data' => [
'config' => [
'label' => __('Max Usage'),
- 'formElement' => \Magento\Ui\Component\Form\Field::NAME,
- 'componentType' => \Magento\Ui\Component\Form\Element\Input::NAME,
+ 'formElement' => Field::NAME,
+ 'componentType' => Input::NAME,
'dataScope' => static::FIELD_NAME,
- 'dataType' => \Magento\Ui\Component\Form\Element\DataType\Number::NAME,
+ 'dataType' => Number::NAME,
'sortOrder' => 50,
],
],
diff --git a/Ui/Component/Form/Usage/UsageOptions.php b/Ui/Component/Form/Usage/UsageOptions.php
index 66be057..f277882 100644
--- a/Ui/Component/Form/Usage/UsageOptions.php
+++ b/Ui/Component/Form/Usage/UsageOptions.php
@@ -2,23 +2,27 @@
namespace DevStone\UsageCalculator\Ui\Component\Form\Usage;
-use Magento\Catalog\Model\Locator\LocatorInterface;
-use Magento\Store\Model\StoreManagerInterface;
+use DevStone\UsageCalculator\Api\UsageCustomOptionRepositoryInterface;
+use DevStone\UsageCalculator\Model\Usage\SizesOptionsProvider;
use Magento\Catalog\Model\Config\Source\Product\Options\Price as ProductOptionsPrice;
-use Magento\Framework\UrlInterface;
+use Magento\Catalog\Model\Locator\LocatorInterface;
+use Magento\Catalog\Model\Product\Option;
+use Magento\Framework\App\ObjectManager;
+use Magento\Framework\Currency;
+use Magento\Framework\Locale\CurrencyInterface;
use Magento\Framework\Stdlib\ArrayManager;
-use Magento\Ui\Component\Modal;
+use Magento\Framework\UrlInterface;
+use Magento\Store\Model\StoreManagerInterface;
use Magento\Ui\Component\Container;
use Magento\Ui\Component\DynamicRows;
-use Magento\Ui\Component\Form\Fieldset;
-use Magento\Ui\Component\Form\Field;
-use Magento\Ui\Component\Form\Element\Input;
-use Magento\Ui\Component\Form\Element\Select;
-use Magento\Ui\Component\Form\Element\Checkbox;
use Magento\Ui\Component\Form\Element\ActionDelete;
-use Magento\Ui\Component\Form\Element\DataType\Text;
+use Magento\Ui\Component\Form\Element\Checkbox;
use Magento\Ui\Component\Form\Element\DataType\Number;
-use Magento\Framework\Locale\CurrencyInterface;
+use Magento\Ui\Component\Form\Element\DataType\Text;
+use Magento\Ui\Component\Form\Element\Input;
+use Magento\Ui\Component\Form\Element\Select;
+use Magento\Ui\Component\Form\Field;
+use Magento\Ui\Component\Form\Fieldset;
/**
* Data provider for "Usage Options" panel
@@ -69,7 +73,7 @@ class UsageOptions extends \Magento\Catalog\Ui\DataProvider\Product\Form\Modifie
const FIELD_ENABLE = 'affect_usage_custom_options';
const FIELD_OPTION_ID = 'option_id';
const FIELD_TITLE_NAME = 'title';
- const FIELD_HELP_NAME = 'help';
+ const FIELD_HELP_NAME = 'help';
const FIELD_STORE_TITLE_NAME = 'store_title';
const FIELD_TYPE_NAME = 'type';
const FIELD_IS_REQUIRE_NAME = 'is_require';
@@ -88,67 +92,24 @@ class UsageOptions extends \Magento\Catalog\Ui\DataProvider\Product\Form\Modifie
const CUSTOM_OPTIONS_LISTING = 'product_custom_options_listing';
/**#@-*/
- /**
- * @var LocatorInterface
- */
- protected $locator;
-
- /**
- * @var \Magento\Store\Model\StoreManagerInterface
- */
- protected $storeManager;
-
- /**
- * @var \Magento\Catalog\Model\Config\Source\Product\Options\Price
- */
- protected $productOptionsPrice;
-
- /**
- * @var UrlInterface
- */
- protected $urlBuilder;
-
- /**
- * @var ArrayManager
- */
- protected $arrayManager;
-
- /**
- * @var array
- */
- protected $meta = [];
-
- /**
- * @var CurrencyInterface
- */
- private $localeCurrency;
+ protected LocatorInterface $locator;
+ protected StoreManagerInterface $storeManager;
+ protected ProductOptionsPrice $productOptionsPrice;
+ protected UrlInterface $urlBuilder;
+ protected ArrayManager $arrayManager;
+ protected array $meta = [];
+ private CurrencyInterface $localeCurrency;
+ protected UsageCustomOptionRepositoryInterface $optionRepository;
+ protected SizesOptionsProvider $sizesOptionsProvider;
-
- /**
- * @var \DevStone\UsageCalculator\Api\UsageCustomOptionRepositoryInterface
- */
- protected $optionRepository;
-
- /**
- * @var \DevStone\UsageCalculator\Model\Usage\SizesOptionsProvider
- */
- protected $sizesOptionsProvider;
-
- /**
- * @param LocatorInterface $locator
- * @param StoreManagerInterface $storeManager
- * @param ProductOptionsPrice $productOptionsPrice
- * @param UrlInterface $urlBuilder
- * @param ArrayManager $arrayManager
- */
public function __construct(
LocatorInterface $locator,
StoreManagerInterface $storeManager,
ProductOptionsPrice $productOptionsPrice,
UrlInterface $urlBuilder,
ArrayManager $arrayManager,
- \DevStone\UsageCalculator\Api\UsageCustomOptionRepositoryInterface $optionRepo,
- \DevStone\UsageCalculator\Model\Usage\SizesOptionsProvider $sizesOptionsProvider
+ UsageCustomOptionRepositoryInterface $optionRepo,
+ SizesOptionsProvider $sizesOptionsProvider
) {
$this->locator = $locator;
$this->storeManager = $storeManager;
@@ -156,7 +117,7 @@ public function __construct(
$this->urlBuilder = $urlBuilder;
$this->arrayManager = $arrayManager;
$this->optionRepository = $optionRepo;
- $this->sizesOptionsProvider = $sizesOptionsProvider;
+ $this->sizesOptionsProvider = $sizesOptionsProvider;
}
/**
@@ -164,7 +125,7 @@ public function __construct(
*/
public function modifyData(array $data)
{
- foreach($data as $id => &$usage) {
+ foreach ($data as $id => &$usage) {
$options = [];
$productOptions = $this->optionRepository->getList($id);
/** @var \DevStone\UsageCalculator\Model\Usage\Option $option */
@@ -177,7 +138,7 @@ public function modifyData(array $data)
foreach ($values as $value) {
$value->setData(static::FIELD_IS_USE_DEFAULT, !$value->getData(static::FIELD_STORE_TITLE_NAME));
}
- /** @var \Magento\Catalog\Model\Product\Option $value */
+ /** @var Option $value */
foreach ($values as $value) {
$options[$index][static::GRID_TYPE_SELECT_NAME][] = $this->formatPriceByPath(
static::FIELD_PRICE_NAME,
@@ -262,7 +223,6 @@ protected function createCustomOptionsPanel()
]
);
-
return $this;
}
@@ -452,28 +412,28 @@ protected function getCommonContainerConfig($sortOrder)
],
]
),
- static::FIELD_HELP_NAME => [
- 'arguments' => [
- 'data' => [
- 'config' => [
- 'label' => __('Help Text'),
- 'component' => 'Magento_Catalog/component/static-type-input',
- 'componentType' => Field::NAME,
- 'formElement' => Input::NAME,
- 'dataScope' => static::FIELD_HELP_NAME,
- 'dataType' => Text::NAME,
- 'sortOrder' => 21,
- 'validation' => [
- 'required-entry' => true
- ],
- 'imports' => [
- 'optionId' => '${ $.provider }:${ $.parentScope }.option_id',
- 'isUseDefault' => '${ $.provider }:${ $.parentScope }.is_use_default'
- ]
- ],
- ],
- ],
- ],
+ static::FIELD_HELP_NAME => [
+ 'arguments' => [
+ 'data' => [
+ 'config' => [
+ 'label' => __('Help Text'),
+ 'component' => 'Magento_Catalog/component/static-type-input',
+ 'componentType' => Field::NAME,
+ 'formElement' => Input::NAME,
+ 'dataScope' => static::FIELD_HELP_NAME,
+ 'dataType' => Text::NAME,
+ 'sortOrder' => 21,
+ 'validation' => [
+ 'required-entry' => true
+ ],
+ 'imports' => [
+ 'optionId' => '${ $.provider }:${ $.parentScope }.option_id',
+ 'isUseDefault' => '${ $.provider }:${ $.parentScope }.is_use_default'
+ ]
+ ],
+ ],
+ ],
+ ],
static::FIELD_TYPE_NAME => $this->getTypeFieldConfig(30),
static::FIELD_IS_REQUIRE_NAME => $this->getIsRequireFieldConfig(40)
]
@@ -575,7 +535,7 @@ protected function getSelectTypeGridConfig($sortOrder)
),
static::FIELD_PRICE_NAME => $this->getPriceFieldConfigForSelectType(20),
static::FIELD_PRICE_TYPE_NAME => $this->getPriceTypeFieldConfig(30, ['fit' => true]),
- static::FIELD_IMAGE_SIZE => $this->getImageSizeFieldConfig(40),
+ static::FIELD_IMAGE_SIZE => $this->getImageSizeFieldConfig(40),
static::FIELD_SORT_ORDER_NAME => $this->getPositionFieldConfig(50),
static::FIELD_IS_DELETE => $this->getIsDeleteFieldConfig(60)
]
@@ -849,9 +809,9 @@ protected function getPriceTypeFieldConfig($sortOrder, array $config = [])
);
}
- protected function getImageSizeFieldConfig($sortOrder)
- {
- return [
+ protected function getImageSizeFieldConfig($sortOrder)
+ {
+ return [
'arguments' => [
'data' => [
'config' => [
@@ -866,7 +826,7 @@ protected function getImageSizeFieldConfig($sortOrder)
],
],
];
- }
+ }
/**
* Get options for drop-down control with product option types
@@ -876,48 +836,45 @@ protected function getImageSizeFieldConfig($sortOrder)
*/
protected function getProductOptionTypes()
{
-
- return array(
- array(
+ return [
+ [
'value' => 0,
'label' => 'Text',
- 'optgroup' =>
- array(
- array(
+ 'optgroup' => [
+ [
'label' => 'Field',
'value' => 'field',
- ),
- array(
+ ],
+ [
'label' => 'Area',
'value' => 'area',
- ),
- ),
- ),
- array(
+ ],
+ ],
+ ],
+ [
'value' => 2,
'label' => 'Select',
- 'optgroup' =>
- array(
- array(
+ 'optgroup' => [
+ [
'label' => 'Drop-down',
'value' => 'drop_down',
- ),
- array(
+ ],
+ [
'label' => 'Radio Buttons',
'value' => 'radio',
- ),
- array(
+ ],
+ [
'label' => 'Checkbox',
'value' => 'checkbox',
- ),
- array(
+ ],
+ [
'label' => 'Multiple Select',
'value' => 'multiple',
- ),
- ),
- ),
+ ],
+ ],
+ ],
- );
+ ];
}
/**
@@ -934,14 +891,14 @@ protected function getCurrencySymbol()
/**
* The getter function to get the locale currency for real application code
*
- * @return \Magento\Framework\Locale\CurrencyInterface
+ * @return CurrencyInterface
*
* @deprecated 101.0.0
*/
private function getLocaleCurrency()
{
if ($this->localeCurrency === null) {
- $this->localeCurrency = \Magento\Framework\App\ObjectManager::getInstance()->get(CurrencyInterface::class);
+ $this->localeCurrency = ObjectManager::getInstance()->get(CurrencyInterface::class);
}
return $this->localeCurrency;
}
@@ -961,7 +918,7 @@ protected function formatPrice($value)
$store = $this->storeManager->getStore();
$currency = $this->getLocaleCurrency()->getCurrency($store->getBaseCurrencyCode());
- $value = $currency->toCurrency($value, ['display' => \Magento\Framework\Currency::NO_SYMBOL]);
+ $value = $currency->toCurrency($value, ['display' => Currency::NO_SYMBOL]);
return $value;
}
diff --git a/Ui/Component/Listing/Column/UsageActions.php b/Ui/Component/Listing/Column/UsageActions.php
index fac1de7..1d8dd38 100644
--- a/Ui/Component/Listing/Column/UsageActions.php
+++ b/Ui/Component/Listing/Column/UsageActions.php
@@ -9,9 +9,13 @@
namespace DevStone\UsageCalculator\Ui\Component\Listing\Column;
+use DevStone\UsageCalculator\Helper\Data;
+use DevStone\UsageCalculator\Model\ResourceModel\Category\CollectionFactory;
+use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
+use Magento\Store\Model\ScopeInterface;
use Magento\Ui\Component\Listing\Columns\Column;
class UsageActions extends Column
@@ -20,29 +24,18 @@ class UsageActions extends Column
* Url path
*/
const URL_PATH_EDIT = 'devstone_usagecalculator/usage/edit';
-
- /**
- * @var UrlInterface
- */
- protected $urlBuilder;
-
- /**
- * @var \DevStone\UsageCalculator\Model\ResourceModel\Category\CollectionFactory
- */
- protected $collectionFactory;
-
- /**
- * @var \Magento\Framework\App\Config\ScopeConfigInterface
- */
- protected $scopeConfig;
+ protected UrlInterface $urlBuilder;
+ protected CollectionFactory $collectionFactory;
+ protected ScopeConfigInterface $scopeConfig;
+ private Data $config;
/**
* UsageActions constructor.
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param UrlInterface $urlBuilder
- * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
- * @param \DevStone\UsageCalculator\Model\ResourceModel\Category\CollectionFactory $collectionFactory
+ * @param ScopeConfigInterface $scopeConfig
+ * @param CollectionFactory $collectionFactory
* @param array $components
* @param array $data
*/
@@ -50,8 +43,9 @@ public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
UrlInterface $urlBuilder,
- \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
- \DevStone\UsageCalculator\Model\ResourceModel\Category\CollectionFactory $collectionFactory,
+ ScopeConfigInterface $scopeConfig,
+ CollectionFactory $collectionFactory,
+ Data $config,
array $components = [],
array $data = []
) {
@@ -59,6 +53,7 @@ public function __construct(
$this->collectionFactory = $collectionFactory;
$this->scopeConfig = $scopeConfig;
parent::__construct($context, $uiComponentFactory, $components, $data);
+ $this->config = $config;
}
/**
@@ -74,7 +69,7 @@ public function prepareDataSource(array $dataSource)
foreach ($dataSource['data']['items'] as &$item) {
if (isset($item['entity_id'])) {
- if ($item['category_id'] == $this->getCustomLicenseId()) {
+ if ($item['category_id'] == $this->config->getCustomLicenseId()) {
$item[$this->getData('name')]['edit'] = [
'href' => $this->urlBuilder->getUrl(
self::URL_PATH_EDIT,
@@ -99,15 +94,4 @@ public function prepareDataSource(array $dataSource)
return $dataSource;
}
-
- /**
- * @return mixed
- */
- public function getCustomLicenseId()
- {
- return $this->scopeConfig->getValue(
- 'usage_cal/general/category_id',
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE
- );
- }
}
diff --git a/composer.json b/composer.json
index e9e5c8a..4d79f98 100644
--- a/composer.json
+++ b/composer.json
@@ -1,19 +1,20 @@
{
- "name": "devstone/magento2-module-usagecalculator",
- "description": "Usage calculator for purchasing images or artwork at various resolutions.",
- "type": "magento2-module",
- "license": [
- "GPL-3.0"
- ],
- "require": {
- "devstone/module-imageproducts": "*"
- },
- "autoload": {
- "files": [
- "registration.php"
+ "name": "devstone/magento2-module-usagecalculator",
+ "description": "Usage calculator for purchasing images or artwork at various resolutions.",
+ "type": "magento2-module",
+ "license": [
+ "GPL-3.0"
],
- "psr-4": {
- "DevStone\\UsageCalculator\\": ""
+ "require": {
+ "devstone/module-imageproducts": "*",
+ "php": "~8.0.0"
+ },
+ "autoload": {
+ "files": [
+ "registration.php"
+ ],
+ "psr-4": {
+ "DevStone\\UsageCalculator\\": ""
+ }
}
- }
}
diff --git a/etc/db_schema.xml b/etc/db_schema.xml
new file mode 100644
index 0000000..646f784
--- /dev/null
+++ b/etc/db_schema.xml
@@ -0,0 +1,476 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/etc/db_schema_whitelist.json b/etc/db_schema_whitelist.json
new file mode 100644
index 0000000..26c265e
--- /dev/null
+++ b/etc/db_schema_whitelist.json
@@ -0,0 +1,300 @@
+{
+ "devstone_usage_category": {
+ "column": {
+ "entity_id": true,
+ "name": true,
+ "terms": true,
+ "created_at": true,
+ "updated_at": true
+ },
+ "constraint": {
+ "PRIMARY": true
+ }
+ },
+ "devstone_downloadable_image_size": {
+ "column": {
+ "entity_id": true,
+ "is_active": true,
+ "max_width": true,
+ "max_height": true,
+ "code": true,
+ "created_at": true,
+ "updated_at": true
+ },
+ "constraint": {
+ "PRIMARY": true
+ }
+ },
+ "devstone_usage_entity": {
+ "column": {
+ "entity_id": true,
+ "category_id": true,
+ "is_active": true,
+ "size_id": true,
+ "created_at": true,
+ "updated_at": true
+ },
+ "index": {
+ "DEVSTONE_USAGE_ENTITY_CATEGORY_ID": true,
+ "DEVSTONE_USAGE_ENTITY_SIZE_ID": true
+ },
+ "constraint": {
+ "PRIMARY": true,
+ "DEVSTONE_USAGE_ENTT_CTGR_ID_DEVSTONE_USAGE_CTGR_ENTT_ID": true,
+ "DEVSTONE_USAGE_ENTT_SIZE_ID_DEVSTONE_DL_IMAGE_SIZE_ENTT_ID": true
+ }
+ },
+ "devstone_usage_eav_attribute": {
+ "column": {
+ "attribute_id": true,
+ "is_global": true,
+ "is_filterable": true,
+ "is_visible": true,
+ "validate_rules": true,
+ "is_system": true,
+ "sort_order": true,
+ "data_model": true
+ },
+ "constraint": {
+ "PRIMARY": true,
+ "DEVSTONE_USAGE_EAV_ATTR_ATTR_ID_EAV_ATTR_ATTR_ID": true
+ }
+ },
+ "devstone_usage_entity_datetime": {
+ "column": {
+ "value_id": true,
+ "attribute_id": true,
+ "store_id": true,
+ "entity_id": true,
+ "value": true
+ },
+ "index": {
+ "DEVSTONE_USAGE_ENTITY_DATETIME_ENTITY_ID": true,
+ "DEVSTONE_USAGE_ENTITY_DATETIME_ATTRIBUTE_ID": true,
+ "DEVSTONE_USAGE_ENTITY_DATETIME_STORE_ID": true
+ },
+ "constraint": {
+ "PRIMARY": true,
+ "DEVSTONE_USAGE_ENTT_DTIME_ATTR_ID_EAV_ATTR_ATTR_ID": true,
+ "DEVSTONE_USAGE_ENTT_DTIME_ENTT_ID_DEVSTONE_USAGE_ENTT_ENTT_ID": true,
+ "DEVSTONE_USAGE_ENTITY_DATETIME_STORE_ID_STORE_STORE_ID": true,
+ "DEVSTONE_USAGE_ENTITY_DATETIME_ENTITY_ID_ATTRIBUTE_ID_STORE_ID": true
+ }
+ },
+ "devstone_usage_entity_decimal": {
+ "column": {
+ "value_id": true,
+ "attribute_id": true,
+ "store_id": true,
+ "entity_id": true,
+ "value": true
+ },
+ "index": {
+ "DEVSTONE_USAGE_ENTITY_DECIMAL_ENTITY_ID": true,
+ "DEVSTONE_USAGE_ENTITY_DECIMAL_ATTRIBUTE_ID": true,
+ "DEVSTONE_USAGE_ENTITY_DECIMAL_STORE_ID": true
+ },
+ "constraint": {
+ "PRIMARY": true,
+ "DEVSTONE_USAGE_ENTT_DEC_ATTR_ID_EAV_ATTR_ATTR_ID": true,
+ "DEVSTONE_USAGE_ENTT_DEC_ENTT_ID_DEVSTONE_USAGE_ENTT_ENTT_ID": true,
+ "DEVSTONE_USAGE_ENTITY_DECIMAL_STORE_ID_STORE_STORE_ID": true,
+ "DEVSTONE_USAGE_ENTITY_DECIMAL_ENTITY_ID_ATTRIBUTE_ID_STORE_ID": true
+ }
+ },
+ "devstone_usage_entity_int": {
+ "column": {
+ "value_id": true,
+ "attribute_id": true,
+ "store_id": true,
+ "entity_id": true,
+ "value": true
+ },
+ "index": {
+ "DEVSTONE_USAGE_ENTITY_INT_ENTITY_ID": true,
+ "DEVSTONE_USAGE_ENTITY_INT_ATTRIBUTE_ID": true,
+ "DEVSTONE_USAGE_ENTITY_INT_STORE_ID": true
+ },
+ "constraint": {
+ "PRIMARY": true,
+ "DEVSTONE_USAGE_ENTT_INT_ATTR_ID_EAV_ATTR_ATTR_ID": true,
+ "DEVSTONE_USAGE_ENTT_INT_ENTT_ID_DEVSTONE_USAGE_ENTT_ENTT_ID": true,
+ "DEVSTONE_USAGE_ENTITY_INT_STORE_ID_STORE_STORE_ID": true,
+ "DEVSTONE_USAGE_ENTITY_INT_ENTITY_ID_ATTRIBUTE_ID_STORE_ID": true
+ }
+ },
+ "devstone_usage_entity_text": {
+ "column": {
+ "value_id": true,
+ "attribute_id": true,
+ "store_id": true,
+ "entity_id": true,
+ "value": true
+ },
+ "index": {
+ "DEVSTONE_USAGE_ENTITY_TEXT_ENTITY_ID": true,
+ "DEVSTONE_USAGE_ENTITY_TEXT_ATTRIBUTE_ID": true,
+ "DEVSTONE_USAGE_ENTITY_TEXT_STORE_ID": true
+ },
+ "constraint": {
+ "PRIMARY": true,
+ "DEVSTONE_USAGE_ENTT_TEXT_ATTR_ID_EAV_ATTR_ATTR_ID": true,
+ "DEVSTONE_USAGE_ENTT_TEXT_ENTT_ID_DEVSTONE_USAGE_ENTT_ENTT_ID": true,
+ "DEVSTONE_USAGE_ENTITY_TEXT_STORE_ID_STORE_STORE_ID": true,
+ "DEVSTONE_USAGE_ENTITY_TEXT_ENTITY_ID_ATTRIBUTE_ID_STORE_ID": true
+ }
+ },
+ "devstone_usage_entity_varchar": {
+ "column": {
+ "value_id": true,
+ "attribute_id": true,
+ "store_id": true,
+ "entity_id": true,
+ "value": true
+ },
+ "index": {
+ "DEVSTONE_USAGE_ENTITY_VARCHAR_ENTITY_ID": true,
+ "DEVSTONE_USAGE_ENTITY_VARCHAR_ATTRIBUTE_ID": true,
+ "DEVSTONE_USAGE_ENTITY_VARCHAR_STORE_ID": true
+ },
+ "constraint": {
+ "PRIMARY": true,
+ "DEVSTONE_USAGE_ENTT_VCHR_ATTR_ID_EAV_ATTR_ATTR_ID": true,
+ "DEVSTONE_USAGE_ENTT_VCHR_ENTT_ID_DEVSTONE_USAGE_ENTT_ENTT_ID": true,
+ "DEVSTONE_USAGE_ENTITY_VARCHAR_STORE_ID_STORE_STORE_ID": true,
+ "DEVSTONE_USAGE_ENTITY_VARCHAR_ENTITY_ID_ATTRIBUTE_ID_STORE_ID": true
+ }
+ },
+ "devstone_usage_option": {
+ "column": {
+ "option_id": true,
+ "usage_id": true,
+ "type": true,
+ "is_require": true,
+ "sort_order": true
+ },
+ "index": {
+ "DEVSTONE_USAGE_OPTION_USAGE_ID": true
+ },
+ "constraint": {
+ "PRIMARY": true,
+ "DEVSTONE_USAGE_OPTION_USAGE_ID_DEVSTONE_USAGE_ENTITY_ENTITY_ID": true
+ }
+ },
+ "devstone_usage_option_price": {
+ "column": {
+ "option_price_id": true,
+ "option_id": true,
+ "store_id": true,
+ "price": true,
+ "price_type": true
+ },
+ "index": {
+ "DEVSTONE_USAGE_OPTION_PRICE_STORE_ID": true
+ },
+ "constraint": {
+ "PRIMARY": true,
+ "DEVSTONE_USAGE_OPT_PRICE_OPT_ID_DEVSTONE_USAGE_OPT_OPT_ID": true,
+ "DEVSTONE_USAGE_OPTION_PRICE_STORE_ID_STORE_STORE_ID": true,
+ "DEVSTONE_USAGE_OPTION_PRICE_OPTION_ID_STORE_ID": true
+ }
+ },
+ "devstone_usage_option_title": {
+ "column": {
+ "option_title_id": true,
+ "option_id": true,
+ "store_id": true,
+ "title": true
+ },
+ "index": {
+ "DEVSTONE_USAGE_OPTION_TITLE_STORE_ID": true
+ },
+ "constraint": {
+ "PRIMARY": true,
+ "DEVSTONE_USAGE_OPT_TTL_OPT_ID_DEVSTONE_USAGE_OPT_OPT_ID": true,
+ "DEVSTONE_USAGE_OPTION_TITLE_STORE_ID_STORE_STORE_ID": true,
+ "DEVSTONE_USAGE_OPTION_TITLE_OPTION_ID_STORE_ID": true
+ }
+ },
+ "devstone_usage_option_help": {
+ "column": {
+ "option_help_id": true,
+ "option_id": true,
+ "store_id": true,
+ "help": true
+ },
+ "index": {
+ "DEVSTONE_USAGE_OPTION_HELP_STORE_ID": true
+ },
+ "constraint": {
+ "PRIMARY": true,
+ "DEVSTONE_USAGE_OPT_HELP_OPT_ID_DEVSTONE_USAGE_OPT_OPT_ID": true,
+ "DEVSTONE_USAGE_OPTION_HELP_STORE_ID_STORE_STORE_ID": true,
+ "DEVSTONE_USAGE_OPTION_HELP_OPTION_ID_STORE_ID": true
+ }
+ },
+ "devstone_usage_option_type_value": {
+ "column": {
+ "option_type_id": true,
+ "option_id": true,
+ "size_id": true,
+ "sort_order": true
+ },
+ "index": {
+ "DEVSTONE_USAGE_OPTION_TYPE_VALUE_SIZE_ID": true,
+ "DEVSTONE_USAGE_OPTION_TYPE_VALUE_OPTION_ID": true
+ },
+ "constraint": {
+ "PRIMARY": true,
+ "FK_36592948FEE5D4FAE274B4B429B6F776": true,
+ "DEVSTONE_USAGE_OPT_TYPE_VAL_OPT_ID_DEVSTONE_USAGE_OPT_OPT_ID": true
+ }
+ },
+ "devstone_usage_option_type_price": {
+ "column": {
+ "option_type_price_id": true,
+ "option_type_id": true,
+ "store_id": true,
+ "price": true,
+ "price_type": true
+ },
+ "index": {
+ "DEVSTONE_USAGE_OPTION_TYPE_PRICE_STORE_ID": true
+ },
+ "constraint": {
+ "PRIMARY": true,
+ "FK_03A91A1BE55AA854EC693DA378AAF056": true,
+ "DEVSTONE_USAGE_OPTION_TYPE_PRICE_STORE_ID_STORE_STORE_ID": true,
+ "DEVSTONE_USAGE_OPTION_TYPE_PRICE_OPTION_TYPE_ID_STORE_ID": true
+ }
+ },
+ "devstone_usage_option_type_title": {
+ "column": {
+ "option_type_title_id": true,
+ "option_type_id": true,
+ "store_id": true,
+ "title": true
+ },
+ "index": {
+ "DEVSTONE_USAGE_OPTION_TYPE_TITLE_STORE_ID": true
+ },
+ "constraint": {
+ "PRIMARY": true,
+ "FK_9396C715CEAB358C376F62DF49527264": true,
+ "DEVSTONE_USAGE_OPTION_TYPE_TITLE_STORE_ID_STORE_STORE_ID": true,
+ "DEVSTONE_USAGE_OPTION_TYPE_TITLE_OPTION_TYPE_ID_STORE_ID": true
+ }
+ },
+ "devstone_usage_customer": {
+ "column": {
+ "entity_id": true,
+ "usage_id": true,
+ "customer_id": true,
+ "created_at": true,
+ "updated_at": true
+ },
+ "constraint": {
+ "PRIMARY": true
+ }
+ }
+}
\ No newline at end of file
diff --git a/etc/di.xml b/etc/di.xml
index b98a152..f858ac4 100644
--- a/etc/di.xml
+++ b/etc/di.xml
@@ -58,7 +58,7 @@
-
+
DevStone\UsageCalculator\Model\ResourceModel\Category\Collection
@@ -73,7 +73,7 @@
-
+
@@ -90,7 +90,7 @@
DevStone\UsageCalculator\Model\ResourceModel\Size
-
+
devstone_usage_category
@@ -99,19 +99,19 @@
DevStone\UsageCalculator\Model\ResourceModel\Category
-
+
-
+
-
+
-
+
@@ -135,13 +135,13 @@
-
+
-
-
-
-
+
@@ -198,4 +198,8 @@
+
+
+
+
diff --git a/etc/events.xml b/etc/events.xml
index 69c691b..662153e 100644
--- a/etc/events.xml
+++ b/etc/events.xml
@@ -3,4 +3,7 @@
+
+
+
diff --git a/view/adminhtml/ui_component/devstone_usagecalculator_usage_form.xml b/view/adminhtml/ui_component/devstone_usagecalculator_usage_form.xml
index 5075467..bd48487 100644
--- a/view/adminhtml/ui_component/devstone_usagecalculator_usage_form.xml
+++ b/view/adminhtml/ui_component/devstone_usagecalculator_usage_form.xml
@@ -6,11 +6,16 @@
* @author david@nnucomputerwhiz.com
*/
-->
-