Skip to content
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Version 1.0.0-beta10

## Bugfixes

* None

## Features

* Refactor to optimize DI integration

# Version 1.0.0-beta9

## Bugfixes
Expand Down
52 changes: 47 additions & 5 deletions src/Observers/PreLoadAttributeIdObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace TechDivision\Import\Attribute\Observers;

use TechDivision\Import\Attribute\Utils\ColumnKeys;
use TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface;

/**
* Observer that pre-loads the attribute ID of the EAV attribute with the code found in the CSV file.
Expand All @@ -34,6 +35,33 @@
class PreLoadAttributeIdObserver extends AbstractAttributeImportObserver
{

/**
* The attribute processor instance.
*
* @var \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface
*/
protected $attributeBunchProcessor;

/**
* Initializes the observer with the passed subject instance.
*
* @param \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface $attributeBunchProcessor The attribute bunch processor instance
*/
public function __construct(AttributeBunchProcessorInterface $attributeBunchProcessor)
{
$this->attributeBunchProcessor = $attributeBunchProcessor;
}

/**
* Return's the attribute bunch processor instance.
*
* @return \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface The attribute bunch processor instance
*/
protected function getAttributeBunchProcessor()
{
return $this->attributeBunchProcessor;
}

/**
* Process the observer's business logic.
*
Expand All @@ -48,7 +76,9 @@ protected function process()
}

// preserve the attribute ID for the EAV attribute with the passed code
$this->preLoadAttributeId($attributeCode);
if ($attribute = $this->loadAttributeByAttributeCode($attributeCode)) {
$this->preLoadAttributeId($attribute);
}
}

/**
Expand All @@ -64,14 +94,26 @@ protected function hasBeenProcessed($attributeCode)
}

/**
* Pre-load the attribute ID for the EAV attribute with the passed code.
* Pre-load and temporary persist the attribute ID for the passed EAV attribute.
*
* @param string $attributeCode The code of the EAV attribute to pre-load
* @param array $attribute The EAV attribute to pre-load
*
* @return void
*/
protected function preLoadAttributeId($attributeCode)
protected function preLoadAttributeId(array $attribute)
{
return $this->getSubject()->preLoadAttributeId($attribute);
}

/**
* Load's and return's the EAV attribute with the passed code.
*
* @param string $attributeCode The code of the EAV attribute to load
*
* @return array The EAV attribute
*/
protected function loadAttributeByAttributeCode($attributeCode)
{
return $this->getSubject()->preLoadAttributeId($attributeCode);
return $this->getAttributeBunchProcessor()->loadAttributeByAttributeCode($attributeCode);
}
}
55 changes: 47 additions & 8 deletions src/Observers/PreLoadAttributeOptionIdObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

namespace TechDivision\Import\Attribute\Observers;

use TechDivision\Import\Utils\StoreViewCodes;
use TechDivision\Import\Attribute\Utils\ColumnKeys;
use TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface;

/**
* Observer that pre-loads the option ID of the EAV attribute option with the attribute code/value found in the CSV file.
Expand All @@ -34,6 +36,33 @@
class PreLoadAttributeOptionIdObserver extends AbstractAttributeImportObserver
{

/**
* The attribute processor instance.
*
* @var \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface
*/
protected $attributeBunchProcessor;

/**
* Initializes the observer with the passed subject instance.
*
* @param \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface $attributeBunchProcessor The attribute bunch processor instance
*/
public function __construct(AttributeBunchProcessorInterface $attributeBunchProcessor)
{
$this->attributeBunchProcessor = $attributeBunchProcessor;
}

/**
* Return's the attribute bunch processor instance.
*
* @return \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface The attribute bunch processor instance
*/
protected function getAttributeBunchProcessor()
{
return $this->attributeBunchProcessor;
}

/**
* Process the observer's business logic.
*
Expand All @@ -42,13 +71,24 @@ class PreLoadAttributeOptionIdObserver extends AbstractAttributeImportObserver
protected function process()
{

// load the store value and the attribute code
$value = $this->getValue(ColumnKeys::ADMIN_STORE_VALUE);
$attributeCode = $this->getValue(ColumnKeys::ATTRIBUTE_CODE);

// query whether or not, we've found a new attribute code => means we've found a new EAV attribute
if ($this->hasBeenProcessed($attributeCode = $this->getValue(ColumnKeys::ATTRIBUTE_CODE), $value = $this->getValue(ColumnKeys::ADMIN_STORE_VALUE))) {
if ($this->hasBeenProcessed($attributeCode, $value)) {
return;
}

// preserve the attribute ID for the EAV attribute with the passed code
$this->preLoadOptionId($attributeCode, $value);
// load the ID of the admin store
$storeId = $this->getStoreId(StoreViewCodes::ADMIN);

// load the EAV attribute option with the passed value
$attributeOption = $this->getAttributeBunchProcessor()
->loadAttributeOptionByAttributeCodeAndStoreIdAndValue($attributeCode, $storeId, $value);

// preserve the attribute ID for the passed EAV attribute option
$this->preLoadOptionId($attributeOption);
}

/**
Expand All @@ -65,15 +105,14 @@ protected function hasBeenProcessed($attributeCode, $value)
}

/**
* Pre-load the option ID for the EAV attribute option with the passed attribute code/value.
* Pre-load the option ID for the passed EAV attribute option.
*
* @param string $attributeCode The code of the EAV attribute to pre-load
* @param string $value The option admin store view value of the EAV attribute option to pre-load
* @param array $attributeOption The EAV attribute option with the ID that has to be pre-loaded
*
* @return void
*/
protected function preLoadOptionId($attributeCode, $value)
protected function preLoadOptionId(array $attributeOption)
{
return $this->getSubject()->preLoadOptionId($attributeCode, $value);
return $this->getSubject()->preLoadOptionId($attributeOption);
}
}
67 changes: 4 additions & 63 deletions src/Subjects/BunchSubject.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
use TechDivision\Import\Attribute\Utils\MemberNames;
use TechDivision\Import\Attribute\Utils\RegistryKeys;
use TechDivision\Import\Subjects\ExportableSubjectInterface;
use TechDivision\Import\Utils\Generators\GeneratorInterface;
use TechDivision\Import\Services\RegistryProcessorInterface;
use TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface;

/**
* The subject implementation that handles the business logic to persist attributes.
Expand All @@ -47,13 +44,6 @@ class BunchSubject extends AbstractAttributeSubject implements ExportableSubject
*/
use ExportableTrait;

/**
* The attribute processor instance.
*
* @var \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface
*/
protected $attributeBunchProcessor;

/**
* The ID of the attribute that has been created recently.
*
Expand Down Expand Up @@ -89,28 +79,6 @@ class BunchSubject extends AbstractAttributeSubject implements ExportableSubject
*/
protected $attributeCodeIdMapping = array();

/**
* Initialize the subject instance.
*
* @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance
* @param \TechDivision\Import\Utils\Generators\GeneratorInterface $coreConfigDataUidGenerator The UID generator for the core config data
* @param array $systemLoggers The array with the system loggers instances
* @param \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface $attributeBunchProcessor The attribute bunch processor instance
*/
public function __construct(
RegistryProcessorInterface $registryProcessor,
GeneratorInterface $coreConfigDataUidGenerator,
array $systemLoggers,
AttributeBunchProcessorInterface $attributeBunchProcessor
) {

// pass the parameters to the parent constructor
parent::__construct($registryProcessor, $coreConfigDataUidGenerator, $systemLoggers);

// initialize the attribute bunch processor
$this->attributeBunchProcessor = $attributeBunchProcessor;
}

/**
* Intializes the previously loaded global data for exactly one bunch.
*
Expand Down Expand Up @@ -227,20 +195,15 @@ public function getAttributeGroupByEntityTypeCodeAndAttributeSetNameAndAttribute
}

/**
* Pre-load the attribute ID for the EAV attribute with the passed code.
* Pre-load and temporary persist the attribute ID for the passed EAV attribute.
*
* @param string $attributeCode The code of the EAV attribute to pre-load
* @param array $attribute The EAV attribute to pre-load
*
* @return void
*/
public function preLoadAttributeId($attributeCode)
public function preLoadAttributeId(array $attribute)
{

// load the EAV attribute by the passed code
$attribute = $this->loadAttributeByAttributeCode($attributeCode);

// temporary persist the pre-loaded attribute code => ID mapping
$this->preLoadedAttributeIds[$attributeCode]= $attribute[MemberNames::ATTRIBUTE_ID];
$this->preLoadedAttributeIds[$attribute[MemberNames::ATTRIBUTE_CODE]]= $attribute[MemberNames::ATTRIBUTE_ID];
}

/**
Expand Down Expand Up @@ -298,26 +261,4 @@ public function getLastAttributeId()
{
return $this->lastAttributeId;
}

/**
* Return's the attribute bunch processor instance.
*
* @return \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface The attribute bunch processor instance
*/
protected function getAttributeBunchProcessor()
{
return $this->attributeBunchProcessor;
}

/**
* Load's and return's the EAV attribute with the passed code.
*
* @param string $attributeCode The code of the EAV attribute to load
*
* @return array The EAV attribute
*/
protected function loadAttributeByAttributeCode($attributeCode)
{
return $this->getAttributeBunchProcessor()->loadAttributeByAttributeCode($attributeCode);
}
}
58 changes: 3 additions & 55 deletions src/Subjects/OptionSubject.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@

namespace TechDivision\Import\Attribute\Subjects;

use TechDivision\Import\Utils\StoreViewCodes;
use TechDivision\Import\Attribute\Utils\MemberNames;
use TechDivision\Import\Utils\Generators\GeneratorInterface;
use TechDivision\Import\Services\RegistryProcessorInterface;
use TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface;

/**
* The subject implementation that handles the business logic to persist attribute options.
Expand All @@ -38,13 +34,6 @@
class OptionSubject extends AbstractAttributeSubject
{

/**
* The attribute processor instance.
*
* @var \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface
*/
protected $attributeBunchProcessor;

/**
* The ID of the option that has been created recently.
*
Expand All @@ -59,38 +48,6 @@ class OptionSubject extends AbstractAttributeSubject
*/
protected $attributeCodeValueOptionIdMapping = array();

/**
* Initialize the subject instance.
*
* @param \TechDivision\Import\Services\RegistryProcessorInterface $registryProcessor The registry processor instance
* @param \TechDivision\Import\Utils\Generators\GeneratorInterface $coreConfigDataUidGenerator The UID generator for the core config data
* @param array $systemLoggers The array with the system loggers instances
* @param \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface $attributeBunchProcessor The attribute bunch processor instance
*/
public function __construct(
RegistryProcessorInterface $registryProcessor,
GeneratorInterface $coreConfigDataUidGenerator,
array $systemLoggers,
AttributeBunchProcessorInterface $attributeBunchProcessor
) {

// pass the parameters to the parent constructor
parent::__construct($registryProcessor, $coreConfigDataUidGenerator, $systemLoggers);

// initialize the attribute bunch processor
$this->attributeBunchProcessor = $attributeBunchProcessor;
}

/**
* Return's the attribute bunch processor instance.
*
* @return \TechDivision\Import\Attribute\Services\AttributeBunchProcessorInterface The attribute bunch processor instance
*/
protected function getAttributeBunchProcessor()
{
return $this->attributeBunchProcessor;
}

/**
* Map's the passed attribue code and value to the option ID that has been created recently.
*
Expand Down Expand Up @@ -150,23 +107,14 @@ public function getLastOptionId()
}

/**
* Pre-load the option ID for the EAV attribute option with the passed attribute code/value.
* Pre-load the option ID for the passed EAV attribute option.
*
* @param string $attributeCode The code of the EAV attribute to pre-load
* @param string $value The option admin store view value of the EAV attribute option to pre-load
* @param array $attributeOption The EAV attribute option with the ID that has to be pre-loaded
*
* @return void
*/
public function preLoadOptionId($attributeCode, $value)
public function preLoadOptionId(array $attributeOption)
{

// load the ID of the admin store
$storeId = $this->stores[StoreViewCodes::ADMIN][MemberNames::STORE_ID];

// load the EAV attribute option with the passed value
$attributeOption = $this->getAttributeBunchProcessor()->loadAttributeOptionByAttributeCodeAndStoreIdAndValue($attributeCode, $storeId, $value);

// set the EAV attribute option ID
$this->setLastOptionId($attributeOption[MemberNames::OPTION_ID]);
}
}
Loading