Skip to content

Commit

Permalink
1.73.0 (FINAL RELEASE)
Browse files Browse the repository at this point in the history
  • Loading branch information
m2epro committed Dec 13, 2024
1 parent f8ddf86 commit 736a766
Show file tree
Hide file tree
Showing 80 changed files with 2,764 additions and 151 deletions.
20 changes: 19 additions & 1 deletion Block/Adminhtml/Ebay/Settings/Tabs/AttributeMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,22 @@ class AttributeMapping extends \Ess\M2ePro\Block\Adminhtml\Magento\Form\Abstract
private AttributeMapping\BundleAttributesFieldsetFill $variationOptionFieldsetFill;
/** @var \Ess\M2ePro\Block\Adminhtml\Ebay\Settings\Tabs\AttributeMapping\GpsrAttributesFieldsetFill */
private AttributeMapping\GpsrAttributesFieldsetFill $gpsrAttributesFieldsetFill;
/** @var \Ess\M2ePro\Block\Adminhtml\Ebay\Settings\Tabs\AttributeMapping\GroupedAttributesFieldsetFill */
private AttributeMapping\GroupedAttributesFieldsetFill $groupedAttributesFieldsetFill;

public function __construct(
AttributeMapping\BundleAttributesFieldsetFill $variationOptionFieldsetFill,
AttributeMapping\GpsrAttributesFieldsetFill $gpsrAttributesFieldsetFill,
AttributeMapping\GroupedAttributesFieldsetFill $groupedAttributesFieldsetFill,
\Ess\M2ePro\Block\Adminhtml\Magento\Context\Template $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
array $data = []
) {
$this->variationOptionFieldsetFill = $variationOptionFieldsetFill;
$this->gpsrAttributesFieldsetFill = $gpsrAttributesFieldsetFill;
$this->groupedAttributesFieldsetFill = $groupedAttributesFieldsetFill;

parent::__construct($context, $registry, $formFactory, $data);
}

Expand All @@ -36,6 +41,7 @@ protected function _prepareForm()
// ----------------------------------------
$this->addGpsrAttributesFieldset($form);
$this->addBundleAttributesFieldset($form);
$this->addGroupedAttributesFieldset($form);
// ----------------------------------------

$form->setUseContainer(true);
Expand Down Expand Up @@ -72,10 +78,22 @@ private function addBundleAttributesFieldset(\Magento\Framework\Data\Form $form)
$fieldset = $form->addFieldset(
'bundle_attributes',
[
'legend' => __('Bundle Attributes'),
'legend' => __('Bundle Product Attributes'),
'collapsable' => true,
]
);
$this->variationOptionFieldsetFill->fill($fieldset);
}

private function addGroupedAttributesFieldset(\Magento\Framework\Data\Form $form): void
{
$fieldset = $form->addFieldset(
'grouped_attributes',
[
'legend' => __('Grouped Product Attributes'),
'collapsable' => true,
]
);
$this->groupedAttributesFieldsetFill->fill($fieldset);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Ess\M2ePro\Block\Adminhtml\Ebay\Settings\Tabs\AttributeMapping;

class GroupedAttributesFieldsetFill
{
private \Ess\M2ePro\Helper\Magento\Attribute $attributeHelper;
private \Ess\M2ePro\Model\Ebay\AttributeMapping\GroupedService $groupedProductService;

public function __construct(
\Ess\M2ePro\Helper\Magento\Attribute $attributeHelper,
\Ess\M2ePro\Model\Ebay\AttributeMapping\GroupedService $groupedProductService
) {
$this->attributeHelper = $attributeHelper;
$this->groupedProductService = $groupedProductService;
}

public function fill(\Magento\Framework\Data\Form\Element\Fieldset $fieldset): void
{
$attributesTextType = $this->attributeHelper->filterAllAttrByInputTypes(['text', 'select']);

$preparedAttributes = [];
foreach ($attributesTextType as $attribute) {
$preparedAttributes[] = [
'value' => $attribute['code'],
'label' => $attribute['label'],
];
}

foreach ($this->groupedProductService->getAll() as $pair) {
$config = [
'label' => $pair->channelAttributeTitle,
'title' => $pair->channelAttributeTitle,
'name' => sprintf('grouped_attributes[%s]', $pair->channelAttributeCode),
'values' => [
'' => __('None'),
[
'label' => __('Magento Attributes'),
'value' => $preparedAttributes,
],
],
'value' => $pair->value ?? '',
];

$fieldset->addField($pair->channelAttributeCode, 'select', $config);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@ public function getSavedComplianceDocuments()
{
$documents = $this->getData('saved_compliance_documents');
if (empty($documents)) {
return [
['document_type' => '', 'document_attribute' => ''],
];
return $this->getEmptyDocuments();
}

return $documents;
}

public function getEmptyDocuments(): array
{
return [
[
'document_type' => '',
'document_attribute' => '',
'document_languages' => [],
],
];
}

public function renderTypesDropdown(int $index, string $selectedType)
{
$values = [
Expand Down Expand Up @@ -103,6 +112,34 @@ public function renderAttributesDropdown(int $index, string $selectedAttribute)
return $select->toHtml();
}

public function renderLanguagesDropdown(int $index, array $selectedLanguages)
{
$languages = \Ess\M2ePro\Model\Ebay\ComplianceDocuments::getDocumentLanguages();

$values = [];
foreach ($languages as $language => $label) {
$values[] = ['label' => $label, 'value' => $language];
}

$select = $this->_factoryElement->create(
\Ess\M2ePro\Block\Adminhtml\Magento\Form\Element\Multiselect::class,
[
'data' => [
'name' => "description[compliance_documents][$index][document_languages]",
'values' => $values,
'value' => $selectedLanguages,
'size' => 3,
'class' => 'M2ePro-compliance-document-language-validator'
],
]
);

$select->setId('document-languages-' . $index);
$select->setForm($this->getForm());

return $select->toHtml();
}

public function renderRemoveRowButton(int $index): string
{
$style = '';
Expand All @@ -127,17 +164,15 @@ public function renderAddRowButton(): string
);
}

public function getTooltipHtml()
public function getTooltipHtml(string $text): string
{
//$directionToRightClass = $directionToRight ? 'm2epro-field-tooltip-right' : '';

$content = __('Choose an Attribute containing a valid URL for the selected Document Type');

return <<<HTML
<div class="m2epro-field-tooltip admin__field-tooltip">
<a class="admin__field-tooltip-action" href="javascript://"></a>
<div class="admin__field-tooltip-content">
{$content}
{$text}
</div>
</div>
HTML;
Expand Down
4 changes: 2 additions & 2 deletions Block/Adminhtml/Listing/Switcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(

public function getLabel(): string
{
return (string)__('View Listing:');
return (string)__('Switch Listing');
}

public function hasDefaultOption(): bool
Expand All @@ -55,7 +55,7 @@ protected function loadItems(): void
foreach ($listings as $listing) {
$listingTitle = $this->filterManager->truncate(
$listing->getTitle(),
['length' => 70]
['length' => 50]
);

$items[] = [
Expand Down
28 changes: 28 additions & 0 deletions Block/Adminhtml/Magento/Form/Element/Multiselect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Ess\M2ePro\Block\Adminhtml\Magento\Form\Element;

class Multiselect extends \Magento\Framework\Data\Form\Element\Multiselect
{
public function __construct(
\Magento\Framework\Data\Form\Element\Factory $factoryElement,
\Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection,
\Magento\Framework\Escaper $escaper,
$data = [],
?\Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer = null,
?\Magento\Framework\Math\Random $random = null
) {
parent::__construct(
$factoryElement,
$factoryCollection,
$escaper,
$data,
$secureRenderer,
$random
);

$this->setSize($data['size'] ?? 10);
}
}
14 changes: 14 additions & 0 deletions Block/Adminhtml/Walmart/Settings/Tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class Tabs extends \Ess\M2ePro\Block\Adminhtml\Settings\Tabs
{
public const TAB_ID_GENERAL = 'general';
public const TAB_ID_ATTRIBUTE_MAPPING = 'mapping';

//########################################

Expand Down Expand Up @@ -38,6 +39,19 @@ protected function _prepareLayout()

// ---------------------------------------

$attributeMappingTabContent = $this
->getLayout()
->createBlock(\Ess\M2ePro\Block\Adminhtml\Walmart\Settings\Tabs\AttributeMapping::class)
->toHtml();

$this->addTab(self::TAB_ID_ATTRIBUTE_MAPPING, [
'label' => __('Attribute Mapping'),
'title' => __('Attribute Mapping'),
'content' => $attributeMappingTabContent,
]);

// ----------------------------------------

return parent::_prepareLayout();
}

Expand Down
70 changes: 70 additions & 0 deletions Block/Adminhtml/Walmart/Settings/Tabs/AttributeMapping.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace Ess\M2ePro\Block\Adminhtml\Walmart\Settings\Tabs;

class AttributeMapping extends \Ess\M2ePro\Block\Adminhtml\Magento\Form\AbstractForm
{
private \Ess\M2ePro\Block\Adminhtml\Walmart\Settings\Tabs\AttributeMapping\VariationAttributesFieldsetFill $variationAttributesFieldsetFill;

public function __construct(
\Ess\M2ePro\Block\Adminhtml\Walmart\Settings\Tabs\AttributeMapping\VariationAttributesFieldsetFill $variationAttributesFieldsetFill,
\Ess\M2ePro\Block\Adminhtml\Magento\Context\Template $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
array $data = []
) {
parent::__construct($context, $registry, $formFactory, $data);
$this->variationAttributesFieldsetFill = $variationAttributesFieldsetFill;
}

protected function _prepareForm()
{
$form = $this->_formFactory->create([
'data' => [
'method' => 'post',
'action' => $this->getUrl('*/*/save'),
],
]);

// ----------------------------------------

$this->addVariationAttributesFieldset($form);

// ----------------------------------------

$form->setUseContainer(true);
$this->setForm($form);

return parent::_prepareForm();
}

protected function _beforeToHtml()
{
$this->jsUrl->add(
$this->getUrl('*/walmart_settings_attributeMapping/save'),
\Ess\M2ePro\Block\Adminhtml\Walmart\Settings\Tabs::TAB_ID_ATTRIBUTE_MAPPING
);

return parent::_beforeToHtml();
}

private function addVariationAttributesFieldset(\Magento\Framework\Data\Form $form): void
{
$tooltipMessage = __(
'In the Variation Attributes section of the Attribute Mapping settings, ' .
'you can set default mappings between your Magento variation attribute options and the valid ' .
'variation options on Walmart. For example, if your product has a variation attribute like "Color," ' .
'you can ensure that the specific variation options (e.g., "black," "white," "yellow," "blue") ' .
'in Magento are accurately matched to the corresponding options on Walmart. This helps to ' .
'streamline the listing and management of product variations across both platforms.'
);

$fieldset = $form->addFieldset('variation_attributes', [
'legend' => __('Variation Attributes'),
'tooltip' => $tooltipMessage,
'collapsable' => true,
]);

$this->variationAttributesFieldsetFill->fill($fieldset);
}
}
Loading

0 comments on commit 736a766

Please sign in to comment.