Skip to content

Commit

Permalink
1.62.0 (FINAL RELEASE)
Browse files Browse the repository at this point in the history
  • Loading branch information
m2epro committed Jun 11, 2024
1 parent bdf055e commit 304c70e
Show file tree
Hide file tree
Showing 33 changed files with 540 additions and 106 deletions.
70 changes: 70 additions & 0 deletions Block/Adminhtml/Ebay/Grid/Column/Filter/Price.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);

namespace Ess\M2ePro\Block\Adminhtml\Ebay\Grid\Column\Filter;

class Price extends \Ess\M2ePro\Block\Adminhtml\Magento\Grid\Column\Filter\Range
{
public function getHtml(): string
{
$filterValue = (string)$this->getValue('on_promotion');

$options = [
['value' => '', 'label' => __('Any')],
['value' => 0, 'label' => __('No')],
['value' => 1, 'label' => __('Yes')],
];

$optionsHtml = '';
foreach ($options as $option) {
$optionsHtml .= sprintf(
'<option %s value="%s">%s</option>',
$filterValue == $option['value'] ? 'selected="selected"' : '',
$option['value'],
$option['label']
);
}

$textOnPromotion = __('On Promotion');

$html = <<<HTML
<div class="range">
<div class="range-line" style="padding-top: 5px; display: flex; align-items: center">
<label for="{$this->_getHtmlName()}"
style="cursor: pointer;vertical-align: text-bottom; white-space: nowrap;"
class="admin__field-label">
{$textOnPromotion}
</label>
<select id="{$this->_getHtmlName()}"
class="admin__control-select"
style="margin-left:6px; float:none;"
name="{$this->_getHtmlName()}[on_promotion]"
>
$optionsHtml
</select>
<label style="vertical-align: text-bottom;" class="admin__field-label"></label>
</div>
</div>
HTML;

return parent::getHtml() . $html;
}

public function getValue($index = null)
{
if ($index) {
return $this->getData('value', $index);
}
$value = $this->getData('value');
if (
(isset($value['from']) && $value['from'] !== '')
|| (isset($value['to']) && $value['to'] !== '')
|| (isset($value['on_promotion']) && $value['on_promotion'] !== '')
) {
return $value;
}

return null;
}
}
22 changes: 19 additions & 3 deletions Block/Adminhtml/Ebay/Grid/Column/Renderer/CurrentPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,27 @@ private function renderGeneral(\Magento\Framework\DataObject $row, bool $isExpor
return __('N/A');
}

$promotionHtml = '';

if ($row->getData('has_promotion') !== null) {
$promotionHtml = <<<HTML
<div class="fix-magento-tooltip on-promotion" style="float:right; text-align: left; margin-left: 5px;">
<div class="m2epro-field-tooltip admin__field-tooltip">
<a class="admin__field-tooltip-action" href="javascript://"></a>
<div class="admin__field-tooltip-content">
This Product is added to a promotion.
</div>
</div>
</div>
HTML;
}

if ((float)$onlineCurrentPrice <= 0) {
if ($isExport) {
return 0;
}

return '<span style="color: #f00;">0</span>';
return '<span style="color: #f00;">0</span>' . $promotionHtml;
}

$currency = $row->getCurrency() ?? $row->getChildObject()->getCurrency();
Expand Down Expand Up @@ -135,7 +150,7 @@ private function renderGeneral(\Magento\Framework\DataObject $row, bool $isExpor
$resultHtml = $intervalHtml . '&nbsp;' . '<span class="product-price-value">' . $onlineStartStr . '</span>';
}

return $resultHtml;
return $resultHtml . $promotionHtml;
}

if ($isExport) {
Expand Down Expand Up @@ -164,6 +179,7 @@ private function renderGeneral(\Magento\Framework\DataObject $row, bool $isExpor
'<span class="product-price-value">' .
$this->localeCurrency->getCurrency($currency)->toCurrency($onlineCurrentPrice) .
'</span>' .
'</div>';
'</div>' .
$promotionHtml;
}
}
19 changes: 17 additions & 2 deletions Block/Adminhtml/Ebay/Grid/Column/Renderer/MinMaxPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,27 @@ public function renderGeneral(\Magento\Framework\DataObject $row, bool $isExport
return __('N/A');
}

$promotionHtml = '';

if ($row->getData('has_promotion') !== null) {
$promotionHtml = <<<HTML
<div class="fix-magento-tooltip on-promotion" style="float:right; text-align: left; margin-left: 5px;">
<div class="m2epro-field-tooltip admin__field-tooltip">
<a class="admin__field-tooltip-action" href="javascript://"></a>
<div class="admin__field-tooltip-content">
This Product is added to a promotion.
</div>
</div>
</div>
HTML;
}

if ((float)$onlineMinPrice <= 0) {
if ($isExport) {
return 0;
}

return '<span style="color: #f00;">0</span>';
return '<span style="color: #f00;">0</span>' . $promotionHtml;
}

if (!empty($onlineStartPrice)) {
Expand Down Expand Up @@ -185,6 +200,6 @@ public function renderGeneral(\Magento\Framework\DataObject $row, bool $isExport
}
}

return $resultHtml;
return $resultHtml . ' ' . $promotionHtml;
}
}
106 changes: 96 additions & 10 deletions Block/Adminhtml/Ebay/Listing/AllItems/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Ess\M2ePro\Block\Adminhtml\Ebay\Listing\AllItems;

use Ess\M2ePro\Block\Adminhtml\Ebay\Grid\Column\Renderer\Qty as OnlineQty;
use Ess\M2ePro\Model\ResourceModel\Ebay\Listing\Product\Promotion as EbayListingProductPromotionResource;
use Ess\M2ePro\Model\ResourceModel\Ebay\Promotion as EbayPromotionResource;
use Ess\M2ePro\Model\ResourceModel\Listing\Product\Variation\Option as ProductVariationOption;

class Grid extends \Ess\M2ePro\Block\Adminhtml\Magento\Grid\AbstractGrid
Expand Down Expand Up @@ -44,7 +46,12 @@ class Grid extends \Ess\M2ePro\Block\Adminhtml\Magento\Grid\AbstractGrid
/** @var \Ess\M2ePro\Model\ResourceModel\Ebay\Template\Category */
private $ebayCategoryResource;

private \Ess\M2ePro\Model\ResourceModel\Ebay\Promotion $promotionResource;
private \Ess\M2ePro\Model\ResourceModel\Ebay\Listing\Product\Promotion $listingProductPromotionResource;

public function __construct(
\Ess\M2ePro\Model\ResourceModel\Ebay\Promotion $promotionResource,
\Ess\M2ePro\Model\ResourceModel\Ebay\Listing\Product\Promotion $listingProductPromotionResource,
\Ess\M2ePro\Block\Adminhtml\Widget\Grid\AdvancedFilter\FilterFactory $advancedFilterFactory,
\Ess\M2ePro\Model\Ebay\AdvancedFilter\AllItemsOptions $advancedFilterAllItemsOptions,
\Ess\M2ePro\Model\ResourceModel\Ebay\Template\Category $ebayCategoryResource,
Expand Down Expand Up @@ -87,6 +94,8 @@ public function __construct(
$this->advancedFilterAllItemsOptions = $advancedFilterAllItemsOptions;
$this->advancedFilterFactory = $advancedFilterFactory;
$this->ebayCategoryResource = $ebayCategoryResource;
$this->promotionResource = $promotionResource;
$this->listingProductPromotionResource = $listingProductPromotionResource;
}

public function _construct()
Expand Down Expand Up @@ -177,6 +186,25 @@ protected function _prepareCollection()
'left'
);

$select = $this->listingProductPromotionResource->getConnection()->select();
$select->from(
$this->listingProductPromotionResource->getMainTable(),
[
'lp_id' => 'listing_product_id',
'has_promotion' => new \Zend_Db_Expr('COUNT(*) > 0'),
]
);
$select->group('listing_product_id');

$collection->getSelect()->joinLeft(
['promo' => $select],
sprintf(
'%s = promo.lp_id',
EbayListingProductPromotionResource::COLUMN_LISTING_PRODUCT_ID
),
['has_promotion']
);

$this->setCollection($collection);

return parent::_prepareCollection();
Expand Down Expand Up @@ -305,6 +333,8 @@ protected function _prepareAdvancedFilters()

$this->addErrorAdvancedFilter();

$this->addPromotionAdvancedFilter();

parent::_prepareAdvancedFilters();
}

Expand Down Expand Up @@ -832,11 +862,14 @@ private function addSellingPolicyAdvancedFilter(): void

$collection
->getSelect()
->where('IF (
->where(
'IF (
elp.template_selling_format_id IS NOT NULL,
elp.template_selling_format_id,
el.template_selling_format_id
) = ?', (int)$filterValue);
) = ?',
(int)$filterValue
);
};

$filter = $this->advancedFilterFactory->createDropDownFilter(
Expand Down Expand Up @@ -866,11 +899,14 @@ private function addSynchronizationPolicyAdvancedFilter()

$collection
->getSelect()
->where('IF (
->where(
'IF (
elp.template_synchronization_id IS NOT NULL,
elp.template_synchronization_id,
el.template_synchronization_id
) = ?', (int)$filterValue);
) = ?',
(int)$filterValue
);
};

$filter = $this->advancedFilterFactory->createDropDownFilter(
Expand Down Expand Up @@ -900,11 +936,14 @@ private function addDescriptionPolicyAdvancedFilter()

$collection
->getSelect()
->where('IF (
->where(
'IF (
elp.template_description_id IS NOT NULL,
elp.template_description_id,
el.template_description_id
) = ?', (int)$filterValue);
) = ?',
(int)$filterValue
);
};

$filter = $this->advancedFilterFactory->createDropDownFilter(
Expand Down Expand Up @@ -934,11 +973,14 @@ private function addShippingPolicyAdvancedFilter()

$collection
->getSelect()
->where('IF (
->where(
'IF (
elp.template_shipping_id IS NOT NULL,
elp.template_shipping_id,
el.template_shipping_id
) = ?', (int)$filterValue);
) = ?',
(int)$filterValue
);
};

$filter = $this->advancedFilterFactory->createDropDownFilter(
Expand Down Expand Up @@ -968,11 +1010,14 @@ private function addReturnPolicyAdvancedFilter()

$collection
->getSelect()
->where('IF (
->where(
'IF (
elp.template_return_policy_id IS NOT NULL,
elp.template_return_policy_id,
el.template_return_policy_id
) = ?', (int)$filterValue);
) = ?',
(int)$filterValue
);
};

$filter = $this->advancedFilterFactory->createDropDownFilter(
Expand Down Expand Up @@ -1052,4 +1097,45 @@ private function addErrorAdvancedFilter()

$this->addAdvancedFilter($filter);
}

private function addPromotionAdvancedFilter()
{
$options = $this->advancedFilterAllItemsOptions->getPromotionOptions();
if ($options->isEmpty()) {
return;
}

$filterCallback = function (
\Ess\M2ePro\Model\ResourceModel\Magento\Product\Collection $collection,
string $filterValue
): void {
if (empty($filterValue)) {
return;
}

$select = $this->listingProductPromotionResource->getConnection()->select();
$select->from(
['elpp' => $this->listingProductPromotionResource->getMainTable()],
[new \Zend_Db_Expr('1')]
)
->join(
['ep' => $this->promotionResource->getMainTable()],
'elpp.promotion_id = ep.id',
null
)
->where('elpp.listing_product_id = elp.listing_product_id')
->where('ep.id = ?', $filterValue);

$collection->getSelect()->where('EXISTS (?)', new \Zend_Db_Expr($select));
};

$filter = $this->advancedFilterFactory->createDropDownFilter(
'promotion',
__('Promotion'),
$options,
$filterCallback
);

$this->addAdvancedFilter($filter);
}
}
Loading

0 comments on commit 304c70e

Please sign in to comment.