-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
673 additions
and
220 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
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,25 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/** | ||
* @author Siteation (https://siteation.dev/) | ||
* @copyright Copyright 2021 Siteation (https://siteation.dev/) | ||
* @license MIT | ||
*/ | ||
|
||
namespace Siteation\StoreInfoUsps\Block\Adminhtml\Form\Field; | ||
|
||
use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray; | ||
|
||
class Usps extends AbstractFieldArray | ||
{ | ||
protected function _prepareToRender() | ||
{ | ||
$this->addColumn('content', [ | ||
'label' => __('Content'), | ||
'class' => 'required-entry' | ||
]); | ||
|
||
$this->_addAfter = false; | ||
$this->_addButtonLabel = __('Add'); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Siteation\StoreInfoUsps\ViewModel; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\View\Element\Block\ArgumentInterface; | ||
use Magento\Store\Model\ScopeInterface; | ||
|
||
class StoreInfoUsps implements ArgumentInterface | ||
{ | ||
protected $scopeConfig; | ||
|
||
public function __construct(ScopeConfigInterface $scopeConfig) | ||
{ | ||
$this->scopeConfig = $scopeConfig; | ||
} | ||
|
||
private function objectToArray(object $data): array | ||
{ | ||
$result = []; | ||
foreach ($data as $key => $value) { | ||
$result[$key] = (is_array($value) || is_object($value)) | ||
? $this->objectToArray($value) | ||
: $value; | ||
} | ||
return $result; | ||
} | ||
|
||
private function flattenArray(array $array): array | ||
{ | ||
$flatArray = array_map(function($item) { | ||
if (!is_array($item) || !array_key_exists('content', $item)) { | ||
throw new \InvalidArgumentException('Each item in the array should be an array with a "content" key.'); | ||
} | ||
return $item['content']; | ||
}, $array); | ||
|
||
return array_values($flatArray); | ||
} | ||
|
||
public function getStoreUsps(string $attribute): array | ||
{ | ||
$path = sprintf('siteation_storeinfo_usps/%s/usps', $attribute); | ||
$value = $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE); | ||
|
||
if (is_string($value)) { | ||
return (array) $this->objectToArray(json_decode($value)); | ||
} | ||
|
||
return (array) $value; | ||
} | ||
|
||
public function getHeaderUsps(): array | ||
{ | ||
$usps = $this->getStoreUsps('header'); | ||
return !empty($usps) ? $this->flattenArray($usps) : []; | ||
} | ||
|
||
public function getFooterUsps() | ||
{ | ||
$usps = $this->getStoreUsps('footer'); | ||
return !empty($usps) ? $this->flattenArray($usps) : []; | ||
} | ||
|
||
public function getCategoryUsps(): array | ||
{ | ||
$usps = $this->getStoreUsps('category'); | ||
return !empty($usps) ? $this->flattenArray($usps) : []; | ||
} | ||
|
||
public function getProductUsps(): array | ||
{ | ||
$usps = $this->getStoreUsps('product'); | ||
return !empty($usps) ? $this->flattenArray($usps) : []; | ||
} | ||
|
||
public function getCustom1Usps(): array | ||
{ | ||
$usps = $this->getStoreUsps('custom_1'); | ||
return !empty($usps) ? $this->flattenArray($usps) : []; | ||
} | ||
|
||
public function getCustom2Usps(): array | ||
{ | ||
$usps = $this->getStoreUsps('custom_2'); | ||
return !empty($usps) ? $this->flattenArray($usps) : []; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
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
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> | ||
<module name="Siteation_StoreUsps"> | ||
<module name="Siteation_StoreInfoUsps"> | ||
<sequence> | ||
<module name="Magento_Backend"/> | ||
<module name="Magento_Catalog"/> | ||
<module name="Magento_Store"/> | ||
<module name="Hyva_Theme"/> | ||
</sequence> | ||
</module> | ||
|
||
</config> |
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.