Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/1.11.0 #31

Merged
merged 5 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 8 additions & 30 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,22 @@ name: Lint PHP files
on: [push, pull_request]

jobs:
php-71:
runs-on: ubuntu-latest
steps:
- uses: StephaneBour/[email protected]
with:
dir: './'

php-72:
runs-on: ubuntu-latest
steps:
- uses: StephaneBour/[email protected]
with:
dir: './'

php-73:
php-74:
runs-on: ubuntu-latest
steps:
- uses: StephaneBour/[email protected]
with:
dir: './'
- uses: prestashop/github-action-php-lint/[email protected]

php-74:
php-81:
runs-on: ubuntu-latest
steps:
- uses: StephaneBour/[email protected]
with:
dir: './'
- uses: prestashop/github-action-php-lint/[email protected]

php-80:
php-82:
runs-on: ubuntu-latest
steps:
- uses: StephaneBour/[email protected]
with:
dir: './'
- uses: prestashop/github-action-php-lint/[email protected]

php-81:
php-83:
runs-on: ubuntu-latest
steps:
- uses: StephaneBour/[email protected]
with:
dir: './'
- uses: prestashop/github-action-php-lint/[email protected]
6 changes: 2 additions & 4 deletions .github/workflows/setup-di-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ jobs:
strategy:
matrix:
include:
- PHP_VERSION: php73-fpm
MAGENTO_VERSION: 2.3.7
- PHP_VERSION: php74-fpm
MAGENTO_VERSION: 2.4.0
- PHP_VERSION: php81-fpm
MAGENTO_VERSION: 2.4.4
- PHP_VERSION: php82-fpm
MAGENTO_VERSION: 2.4.6
- PHP_VERSION: php83-fpm
MAGENTO_VERSION: 2.4.7
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
Expand Down
8 changes: 8 additions & 0 deletions Api/Config/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface RepositoryInterface
public const XML_PATH_SKU = '%s/attributes/sku';
public const XML_PATH_BRAND = '%s/attributes/brand';
public const XML_PATH_DESCRIPTION = '%s/attributes/description';
public const XPATH_EXTRA_FIELDS = '%s/attributes/extra_fields';

/**
* Get extension version
Expand Down Expand Up @@ -113,6 +114,13 @@ public function getBrand(int $storeId = null): string;
*/
public function getDescription(int $storeId = null): string;

/**
* Get extra fields
*
* @return array
*/
public function getExtraFields(): array;

/**
* Get current store
*
Expand Down
87 changes: 87 additions & 0 deletions Block/Adminhtml/System/Config/Form/Field/ExtraFields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/**
* Copyright © Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magmodules\Reloadify\Block\Adminhtml\System\Config\Form\Field;

use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;
use Magento\Framework\DataObject;
use Magento\Framework\Exception\LocalizedException;

/**
* Class ExtraFields
* System config field renderer for Extra Fields (feed)
*/
class ExtraFields extends AbstractFieldArray
{

/**
* @var Renderer\Attributes
*/
private $attributeRenderer;

/**
* Prepare to render method
*
* @throws LocalizedException
*/
public function _prepareToRender()
{
$this->addColumn(
'name',
[
'label' => __('Field name'),
]
);
$this->addColumn(
'attribute',
[
'label' => __('Attribute'),
'renderer' => $this->getAttributeRenderer()
]
);
$this->_addAfter = false;
$this->_addButtonLabel = __('Add');
}

/**
* Retrieve attribute column renderer
*
* @return Renderer\Attributes
* @throws LocalizedException
*/
public function getAttributeRenderer(): Renderer\Attributes
{
if (!$this->attributeRenderer) {
$this->attributeRenderer = $this->getLayout()->createBlock(
Renderer\Attributes::class,
'',
['data' => ['is_render_to_js_template' => true]]
);
}

return $this->attributeRenderer;
}

/**
* Prepare existing row data object
*
* @param DataObject $row
* @throws LocalizedException
*/
public function _prepareArrayRow(DataObject $row)
{
$options = [];
if ($attribute = $row->getData('attribute')) {
$options['option_' . $this->getAttributeRenderer()->calcOptionHash($attribute)] = 'selected="selected"';
}

$row->setData(
'option_extra_attrs',
$options
);
}
}
110 changes: 110 additions & 0 deletions Block/Adminhtml/System/Config/Form/Field/Renderer/Attributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/**
* Copyright © Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magmodules\Reloadify\Block\Adminhtml\System\Config\Form\Field\Renderer;

use Magento\Framework\View\Element\Context;
use Magento\Framework\View\Element\Html\Select;
use Magmodules\Reloadify\Model\System\Config\Source\Attributes as AttributesSource;

class Attributes extends Select
{

/**
* @var array
*/
private $attribute = [];
/**
* @var AttributesSource
*/
private $attributes;

/**
* Attributes constructor.
*
* @param Context $context
* @param AttributesSource $attributes
* @param array $data
*/
public function __construct(
Context $context,
AttributesSource $attributes,
array $data = []
) {
parent::__construct($context, $data);
$this->attributes = $attributes;
}

/**
* Render block HTML
*
* @return string
*/
public function _toHtml()
{
if (!$this->getOptions()) {
foreach ($this->getAttributeSource() as $attribute) {
$this->addOption($attribute['value'], $attribute['label']);
}
}

return parent::_toHtml();
}

/**
* Get all attributes
*
* @return array
*/
public function getAttributeSource(): array
{
if (!$this->attribute) {
$this->attribute = $this->attributes->toOptionArray();
$this->attribute[] = $this->getPriceAttributeSource();
}

return $this->attribute;
}

/**
* @return array
*/
private function getPriceAttributeSource(): array
{
$optionArray = [];
$optionArray[] = [
'label' => __('Price with base currency'),
'value' => 'rendered_price__price'
];
$optionArray[] = [
'label' => __('Min. price with base currency'),
'value' => 'rendered_price__min_price'
];
$optionArray[] = [
'label' => __('Max. price with base currency'),
'value' => 'rendered_price__max_price'
];

return [
'label' => __('Price Attributes'),
'value' => $optionArray,
'optgroup-name' => __('Price Attributes')
];
}

/**
* Sets name for input element
*
* @param $value
*
* @return Attributes
*/
public function setInputName($value)
{
return $this->setData('name', $value);
}
}
35 changes: 35 additions & 0 deletions Model/Config/Backend/Serialized/ExtraFields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Copyright © Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magmodules\Reloadify\Model\Config\Backend\Serialized;

use Magento\Config\Model\Config\Backend\Serialized\ArraySerialized;

/**
* Class ExtraFields
*/
class ExtraFields extends ArraySerialized
{

/**
* @return \Magento\Config\Model\Config\Backend\Serialized\ArraySerialized
*/
public function beforeSave()
{
$data = $this->getValue();
if (is_array($data)) {
foreach ($data as $key => $row) {
if (empty($row['name']) || empty($row['attribute'])) {
unset($data[$key]);
continue;
}
}
}
$this->setValue($data);
return parent::beforeSave();
}
}
Loading
Loading