-
Notifications
You must be signed in to change notification settings - Fork 5
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
68 changed files
with
4,402 additions
and
491 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
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,54 @@ | ||
<?php | ||
/** | ||
* @author Bloomreach | ||
* @copyright Copyright (c) Bloomreach (https://www.bloomreach.com/) | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Bloomreach\EngagementConnector\Model\Config\Backend; | ||
|
||
use Bloomreach\EngagementConnector\Model\InitialExport\Action\Configure\Catalog\FieldsMapper; | ||
use Magento\Framework\App\Config\Value; | ||
use Magento\Framework\Exception\LocalizedException; | ||
|
||
/** | ||
* Allows select up to 20 options | ||
*/ | ||
class ValidateSearchableFields extends Value | ||
{ | ||
/** | ||
* Checks for unique options. | ||
* | ||
* @return $this | ||
* @throws LocalizedException | ||
*/ | ||
public function beforeSave() | ||
{ | ||
if ($this->getFieldsetDataValue('enabled') !== '1') { | ||
return parent::beforeSave(); | ||
} | ||
|
||
$value = $this->getValue(); | ||
|
||
if (!$value) { | ||
throw new LocalizedException( | ||
__( | ||
'Searchable fields cannot be empty.', | ||
FieldsMapper::MAX_SEARCHABLE | ||
) | ||
); | ||
} | ||
|
||
if (count($value) <= FieldsMapper::MAX_SEARCHABLE) { | ||
return parent::beforeSave(); | ||
|
||
} | ||
|
||
throw new LocalizedException( | ||
__( | ||
'Maximum number of searchable fields exceeded. Max number: "%1"', | ||
FieldsMapper::MAX_SEARCHABLE | ||
) | ||
); | ||
} | ||
} |
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,67 @@ | ||
<?php | ||
/** | ||
* @author Bloomreach | ||
* @copyright Copyright (c) Bloomreach (https://www.bloomreach.com/) | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Bloomreach\EngagementConnector\Model\Config\Source; | ||
|
||
use Bloomreach\EngagementConnector\Model\DataMapping\ConfigResolver; | ||
use Bloomreach\EngagementConnector\Model\DataMapping\DataMapper\Product\DefaultType; | ||
use Bloomreach\EngagementConnector\Model\InitialExport\Action\Configure\Catalog\FieldsMapper; | ||
use Magento\Framework\Data\OptionSourceInterface; | ||
use Magento\Framework\Exception\NotFoundException; | ||
|
||
/** | ||
* 'catalog_product' fields source | ||
*/ | ||
class CatalogProductFields implements OptionSourceInterface | ||
{ | ||
/** | ||
* @var ConfigResolver | ||
*/ | ||
private $configResolver; | ||
|
||
/** | ||
* @param ConfigResolver $configResolver | ||
*/ | ||
public function __construct(ConfigResolver $configResolver) | ||
{ | ||
$this->configResolver = $configResolver; | ||
} | ||
|
||
/** | ||
* Get options | ||
* | ||
* @return array | ||
* @throws NotFoundException | ||
*/ | ||
public function toOptionArray() | ||
{ | ||
$options = []; | ||
|
||
foreach ($this->configResolver->getByEntityType($this->getEntityType()) as $item) { | ||
if ($item->getBloomreachCode() === FieldsMapper::PRIMARY_ID) { | ||
continue; | ||
} | ||
|
||
$options[] = [ | ||
'label' => $item->getBloomreachCode(), | ||
'value' => $item->getBloomreachCode() | ||
]; | ||
} | ||
|
||
return $options; | ||
} | ||
|
||
/** | ||
* Get entity type | ||
* | ||
* @return string | ||
*/ | ||
protected function getEntityType(): string | ||
{ | ||
return DefaultType::ENTITY_TYPE; | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
/** | ||
* @author Bloomreach | ||
* @copyright Copyright (c) Bloomreach (https://www.bloomreach.com/) | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Bloomreach\EngagementConnector\Model\Config\Source; | ||
|
||
use Bloomreach\EngagementConnector\Model\DataMapping\ConfigResolver; | ||
use Bloomreach\EngagementConnector\Model\DataMapping\DataMapper\Product\DefaultType; | ||
use Bloomreach\EngagementConnector\Model\DataMapping\DataMapper\Product\ProductVariantsType; | ||
use Magento\Framework\Data\OptionSourceInterface; | ||
use Magento\Framework\Exception\NotFoundException; | ||
|
||
/** | ||
* 'catalog_product_variants' fields source | ||
*/ | ||
class CatalogProductVariantsFields extends CatalogProductFields | ||
{ | ||
/** | ||
* Get entity type | ||
* | ||
* @return string | ||
*/ | ||
protected function getEntityType(): string | ||
{ | ||
return ProductVariantsType::ENTITY_TYPE; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
Model/DataMapping/FieldValueRenderer/DefaultFloatValueRenderer.php
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,30 @@ | ||
<?php | ||
/** | ||
* @author Bloomreach | ||
* @copyright Copyright (c) Bloomreach (https://www.bloomreach.com/) | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Bloomreach\EngagementConnector\Model\DataMapping\FieldValueRenderer; | ||
|
||
use Magento\Framework\Api\AbstractSimpleObject; | ||
use Magento\Framework\Model\AbstractModel; | ||
|
||
/** | ||
* The class is responsible for rendering float value field | ||
*/ | ||
class DefaultFloatValueRenderer implements RenderInterface | ||
{ | ||
/** | ||
* Render the value of float field | ||
* | ||
* @param AbstractSimpleObject|AbstractModel $entity | ||
* @param string $fieldCode | ||
* | ||
* @return float | ||
*/ | ||
public function render($entity, string $fieldCode) | ||
{ | ||
return round((float) $entity->getData($fieldCode), 2); | ||
} | ||
} |
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
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
30 changes: 30 additions & 0 deletions
30
Model/DataMapping/FieldValueRenderer/Product/FloatValue.php
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,30 @@ | ||
<?php | ||
/** | ||
* @author Bloomreach | ||
* @copyright Copyright (c) Bloomreach (https://www.bloomreach.com/) | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Bloomreach\EngagementConnector\Model\DataMapping\FieldValueRenderer\Product; | ||
|
||
use Magento\Framework\Api\AbstractSimpleObject; | ||
use Magento\Framework\Model\AbstractModel; | ||
|
||
/** | ||
* The class is responsible for rendering the value of product field | ||
*/ | ||
class FloatValue extends DefaultRenderer | ||
{ | ||
/** | ||
* Render the value of product field and convert to float | ||
* | ||
* @param AbstractSimpleObject|AbstractModel $entity | ||
* @param string $fieldCode | ||
* | ||
* @return float | ||
*/ | ||
public function render($entity, string $fieldCode) | ||
{ | ||
return (float) parent::render($entity, $fieldCode); | ||
} | ||
} |
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.