Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
5 changes: 5 additions & 0 deletions Api/Pimcore/PimcoreAttributeMapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ interface PimcoreAttributeMapperInterface
*/
const WYSIWYG= 'wysiwyg';

/**
* Pimcore quantityValue type
*/
const QVALUE= 'quantityValue';

/**
* Pimcore object type object
*/
Expand Down
23 changes: 22 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
1.0.8.1
=============
- add missing data transformator for a quantityValue type attribute

1.0.8
=============
- add quantity value strategy type

1.0.7
=============
* add price override configuration `configuration/prices/is_override_enabled`. If yes then price from Pimcore will override current price, otherwise price will be set only on the first one.

1.0.6.0
=============
* now it is possible to configure attribute data from a Pimcore. Additional informations kept in 'attr_conf' key in attribute will be merged and override default configuration of an attribute. `\Divante\PimcoreIntegration\Model\Catalog\Product\Attribute\Creator\Strategy\AbstractStrategy::getMergedConfig`

1.0.5.5
=============
* add .gitignore
* update console commands to be compatible with 2.3.x

1.0.5.4
=============
* GitHub PR:
Expand All @@ -19,4 +40,4 @@

1.0.4.13
=============
* Initial commit
* Initial commit
2 changes: 1 addition & 1 deletion Console/Command/AssetsImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
// fail gracefully
}

$this->registry->register('isSecureArea', true);
$this->registry->register('isSecureArea', true, true);

$start = $this->getCurrentMs();

Expand Down
2 changes: 1 addition & 1 deletion Console/Command/CategoryImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
// fail gracefully
}

$this->registry->register('isSecureArea', true);
$this->registry->register('isSecureArea', true, true);

$start = $this->getCurrentMs();

Expand Down
2 changes: 1 addition & 1 deletion Console/Command/ProductImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
// fail gracefully
}

$this->registry->register('isSecureArea', true);
$this->registry->register('isSecureArea', true, true);

$start = $this->getCurrentMs();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,6 @@ abstract class AbstractStrategy implements AttributeCreationStrategyInterface
*/
protected $code;

/**
* @var array
*/
protected static $defaultAttrConfig = [
'backend' => '',
'frontend' => '',
'input' => 'text',
'class' => '',
'source' => '',
'global' => ScopedAttributeInterface::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => true,
'searchable' => true,
'filterable' => true,
'comparable' => true,
'visible_on_front' => true,
'used_in_product_listing' => true,
'unique' => false,
];

/**
* AbstractStrategy constructor.
*
Expand All @@ -77,4 +56,43 @@ public function __construct(
$this->attrData = $attrData;
$this->code = $code;
}

/**
* @param array $base
*
* @return array
*/
public function getMergedConfig(array $base = []): array
{
return array_merge($this->getDefaultAttributeConfig(), $base, $this->attrData['attr_conf'] ?? []);
}

/**
* @return array
*/
abstract public function getBaseAttrConfig(): array;

/**
* @return array
*/
public function getDefaultAttributeConfig(): array
{
return [
'backend' => '',
'frontend' => '',
'input' => 'text',
'class' => '',
'source' => '',
'global' => ScopedAttributeInterface::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => true,
'searchable' => true,
'filterable' => true,
'comparable' => true,
'visible_on_front' => true,
'used_in_product_listing' => true,
'unique' => false,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,26 @@ class DatetimeStrategy extends AbstractStrategy
public function execute(): int
{
$eavSetup = $this->eavSetupFactory->create();

$eavSetup->addAttribute(
Product::ENTITY,
$this->code,
array_merge(self::$defaultAttrConfig, [
'type' => 'datetime',
'label' => $this->attrData['label'],
'input' => 'date',
'backend' => Datetime::class,
])
$this->getMergedConfig($this->getBaseAttrConfig())
);

return $eavSetup->getAttributeId(Product::ENTITY, $this->code);
}

/**
* @return array
*/
public function getBaseAttrConfig(): array
{
return [
'type' => 'datetime',
'label' => $this->attrData['label'],
'input' => 'date',
'backend' => Datetime::class,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,24 @@ protected function createNewAttribute(array $options)
{
$eavSetup = $this->eavSetupFactory->create();

$data = [
$eavSetup->addAttribute(
Product::ENTITY,
$this->code,
$this->getMergedConfig($this->getBaseAttrConfig())
);
}

/**
* @return array
*/
public function getBaseAttrConfig(): array
{
return [
'type' => 'varchar',
'label' => $this->attrData['label'],
'input' => 'multiselect',
'user_defined' => true,
'backend' => ArrayBackend::class,
];

$eavSetup->addAttribute(
Product::ENTITY,
$this->code,
array_merge(self::$defaultAttrConfig, $data)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* @package Divante\PimcoreIntegration
* @author Bartosz Herba <bherba@divante.pl>
* @copyright 2020 Divante Sp. z o.o.
* @license See LICENSE_DIVANTE.txt for license details.
*/

namespace Divante\PimcoreIntegration\Model\Catalog\Product\Attribute\Creator\Strategy;

use Magento\Catalog\Model\Product;
use Magento\Eav\Setup\EavSetup;

/**
* Class QuantityValueStrategy
*/
class QuantityValueStrategy extends AbstractStrategy
{
/**
* @return int
*/
public function execute(): int
{
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create();
$eavSetup->addAttribute(
Product::ENTITY,
$this->code,
$this->getMergedConfig($this->getBaseAttrConfig())
);

return $eavSetup->getAttributeId(Product::ENTITY, $this->code);
}

/**
* @return array
*/
public function getBaseAttrConfig(): array
{
return [
'type' => 'decimal',
'label' => $this->getLabel(),
'input' => 'text',
];
}

/**
* @return string
*/
private function getLabel(): string
{
return $this->attrData['label'] . ' (' . $this->attrData['unit'] . ')';
}
}
34 changes: 21 additions & 13 deletions Model/Catalog/Product/Attribute/Creator/Strategy/SelectStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ protected function createNewAttribute(array $options)
{
$eavSetup = $this->eavSetupFactory->create();

$eavSetup->addAttribute(
Product::ENTITY,
$this->code,
$this->getMergedConfig($this->getBaseAttrConfig())
);
}

/**
* @return bool
*/
private function isConfigurable(): bool
{
return (!empty($this->attrData['is_configurable']) && true === $this->attrData['is_configurable']);
}

/**
* @return array
*/
public function getBaseAttrConfig(): array
{
$data = [
'type' => 'int',
'label' => $this->attrData['label'],
Expand All @@ -93,18 +113,6 @@ protected function createNewAttribute(array $options)
]);
}

$eavSetup->addAttribute(
Product::ENTITY,
$this->code,
array_merge(self::$defaultAttrConfig, $data)
);
}

/**
* @return bool
*/
private function isConfigurable(): bool
{
return (!empty($this->attrData['is_configurable']) && true === $this->attrData['is_configurable']);
return $data;
}
}
18 changes: 13 additions & 5 deletions Model/Catalog/Product/Attribute/Creator/Strategy/TextStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,21 @@ public function execute(): int
$eavSetup->addAttribute(
Product::ENTITY,
$this->code,
array_merge(self::$defaultAttrConfig, [
'type' => 'varchar',
'label' => $this->attrData['label'],
'input' => 'text',
])
$this->getMergedConfig($this->getBaseAttrConfig())
);

return $eavSetup->getAttributeId(Product::ENTITY, $this->code);
}

/**
* @return array
*/
public function getBaseAttrConfig(): array
{
return [
'type' => 'varchar',
'label' => $this->attrData['label'],
'input' => 'text',
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,23 @@ public function execute(): int
$eavSetup->addAttribute(
Product::ENTITY,
$this->code,
array_merge(self::$defaultAttrConfig, [
'type' => 'text',
'label' => $this->attrData['label'],
'input' => 'textarea',
'wysiwyg_enabled' => false,
'is_html_allowed_on_front' => false,
])
$this->getMergedConfig($this->getBaseAttrConfig())
);

return $eavSetup->getAttributeId(Product::ENTITY, $this->code);
}

/**
* @return array
*/
public function getBaseAttrConfig(): array
{
return [
'type' => 'text',
'label' => $this->attrData['label'],
'input' => 'textarea',
'wysiwyg_enabled' => false,
'is_html_allowed_on_front' => false,
];
}
}
Loading