-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from magefan/10790-release-2.4.0
10790 moved ui to basic
- Loading branch information
Showing
19 changed files
with
1,006 additions
and
584 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* Copyright © Magefan ([email protected]). All rights reserved. | ||
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement). | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magefan\AutoRelatedProduct\Block\Adminhtml\Rule; | ||
|
||
use Magefan\Community\Block\Adminhtml\Edit\GenericButton; | ||
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface; | ||
|
||
class DuplicateButton extends GenericButton implements ButtonProviderInterface | ||
{ | ||
/** | ||
* @return array|string | ||
*/ | ||
public function getButtonData() | ||
{ | ||
$data = []; | ||
|
||
if (!$this->authorization->isAllowed("Magefan_AutoRelatedProduct::rule")) { | ||
return $data; | ||
} | ||
|
||
if ($this->getObjectId()) { | ||
$data = [ | ||
'label' => __('Duplicate (Plus)'), | ||
'class' => 'duplicate', | ||
'on_click' => '(typeof versionsManager !== "undefined" && versionsManager._currentPlan == "Basic") ? versionsManager.showAlert("Plus or Extra") : window.location=\'' . $this->getDuplicateUrl() . '\'', | ||
'sort_order' => 40, | ||
]; | ||
} | ||
return $data; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDuplicateUrl() | ||
{ | ||
return $this->getUrl('mfautorp/*/duplicate', ['id' => $this->getObjectId()]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
/** | ||
* Copyright © Magefan ([email protected]). All rights reserved. | ||
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement). | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magefan\AutoRelatedProduct\Block\Adminhtml; | ||
|
||
use Magento\Backend\Block\Template\Context; | ||
use Magefan\AutoRelatedProduct\Api\ConfigInterface; | ||
use Magefan\Community\Api\GetModuleVersionInterface; | ||
use Magefan\AutoRelatedProduct\Api\RelatedCollectionInterfaceFactory; | ||
use Magento\Framework\Session\SessionManagerInterface; | ||
use Magefan\AutoRelatedProduct\Model\Config\Source\SortBy; | ||
|
||
class TmpInfo extends \Magento\Backend\Block\Template | ||
{ | ||
/** | ||
* @var \Magefan\AutoRelatedProduct\Model\Config | ||
*/ | ||
protected $config; | ||
|
||
/** | ||
* @var GetModuleVersionInterface | ||
*/ | ||
protected $getModuleVersion; | ||
|
||
/** | ||
* @var RelatedCollectionInterfaceFactory | ||
*/ | ||
protected $ruleCollection; | ||
|
||
/** | ||
* @param Context $context | ||
* @param ConfigInterface $config | ||
* @param GetModuleVersionInterface $getModuleVersion | ||
* @param RelatedCollectionInterfaceFactory $ruleCollection | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
ConfigInterface $config, | ||
GetModuleVersionInterface $getModuleVersion, | ||
RelatedCollectionInterfaceFactory $ruleCollection, | ||
SessionManagerInterface $session, | ||
array $data = [] | ||
) { | ||
$this->config = $config; | ||
$this->getModuleVersion = $getModuleVersion; | ||
$this->ruleCollection = $ruleCollection; | ||
$this->session = $session; | ||
parent::__construct($context, $data); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isSomeFeaturesRestricted(): bool | ||
{ | ||
if ($this->getModuleVersion->execute('Magefan_AutoRelatedProductExtra') || $this->getModuleVersion->execute('Magefan_AutoRelatedProductPlus')) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getAffectedRulesByDisplayModes(): string | ||
{ | ||
$rules = $this->ruleCollection->create() | ||
->addFieldToFilter('status', 1); | ||
|
||
$connection = $rules->getConnection(); | ||
$tableName = $rules->getMainTable(); | ||
|
||
$conditions = []; | ||
|
||
if ($connection->tableColumnExists($tableName, 'from_one_category_only')) { | ||
$conditions[] = 'from_one_category_only = 1'; | ||
} | ||
|
||
if ($connection->tableColumnExists($tableName, 'only_with_higher_price')) { | ||
$conditions[] = 'only_with_higher_price = 1'; | ||
} | ||
|
||
if ($connection->tableColumnExists($tableName, 'only_with_lower_price')) { | ||
$conditions[] = 'only_with_lower_price = 1'; | ||
} | ||
|
||
if (!empty($conditions)) { | ||
$rules->getSelect()->where(implode(' OR ', $conditions)); | ||
} | ||
|
||
return implode(',', $rules->getAllIds()); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getAffectedRulesBySortBy(): string | ||
{ | ||
$restrictedSortByOptionsIds = [ | ||
SortBy::NAME, | ||
SortBy::NEWEST, | ||
SortBy::PRICE_DESC, | ||
SortBy::PRICE_ASC | ||
]; | ||
|
||
$rules = $this->ruleCollection->create() | ||
->addFieldToFilter('status', 1) | ||
->addFieldToFilter('sort_by', ['in' => $restrictedSortByOptionsIds]); | ||
|
||
return implode(',', $rules->getAllIds()); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function toHtml() | ||
{ | ||
if (!$this->config->isEnabled() || $this->session->getIsNeedToShowAlert() === false) { | ||
return ''; | ||
} | ||
|
||
$this->session->setIsNeedToShowAlert( | ||
!$this->isSomeFeaturesRestricted() && ($this->getAffectedRulesByDisplayModes() || $this->getAffectedRulesBySortBy()) | ||
); | ||
|
||
return parent::_toHtml(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* Copyright © Magefan ([email protected]). All rights reserved. | ||
* Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement). | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magefan\AutoRelatedProduct\Model\Config\Source; | ||
|
||
class RelatedTemplate implements \Magento\Framework\Option\ArrayInterface | ||
{ | ||
/** | ||
* @const string | ||
*/ | ||
const DEFAULT = 'Magento_Catalog::product/list/items.phtml'; | ||
|
||
/** | ||
* @const string | ||
*/ | ||
const COMPARE = 'Magefan_AutoRelatedProductExtra::product/list/compare.phtml'; | ||
|
||
/** | ||
* @const string | ||
*/ | ||
const FBT = 'Magefan_AutoRelatedProductExtra::product/list/frequently-bought-together.phtml'; | ||
|
||
const CUSTOM = 'custom'; | ||
|
||
const DEFAULT_TEMPLATES = [ | ||
self::DEFAULT, | ||
self::COMPARE, | ||
self::FBT | ||
]; | ||
|
||
/** | ||
* Options | ||
* | ||
* @return array | ||
*/ | ||
public function toOptionArray() | ||
{ | ||
return [ | ||
['value' => self::DEFAULT, 'label' => __('Default Related Template')], | ||
['value' => self::COMPARE, 'label' => __('Compare Template (Extra)')], | ||
['value' => self::FBT, 'label' => __('Frequently Bought Together Template (Extra)')], | ||
['value' => self::CUSTOM, 'label' => __(' - Set Custom Template (Plus) - ')], | ||
]; | ||
} | ||
|
||
/** | ||
* Get options in "key-value" format | ||
* | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
$array = []; | ||
foreach ($this->toOptionArray() as $item) { | ||
$array[$item['value']] = $item['label']; | ||
} | ||
return $array; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.