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

PAC-344: eval clean up #27

Closed
wants to merge 1 commit into from
Closed
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
127 changes: 127 additions & 0 deletions src/Observers/CleanUpBundleProductRelationsObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php
/**
* Copyright (c) 2023 TechDivision GmbH
* All rights reserved
*
* This product includes proprietary software developed at TechDivision GmbH, Germany
* For more information see https://www.techdivision.com/
*
* To obtain a valid license for using this software please contact us at
* [email protected]
*/
declare(strict_types=1);

namespace TechDivision\Import\Product\Bundle\Observers;

use Exception;
use TechDivision\Import\Observers\StateDetectorInterface;
use TechDivision\Import\Product\Bundle\Services\ProductBundleProcessorInterface;
use TechDivision\Import\Product\Observers\AbstractProductImportObserver;
use TechDivision\Import\Product\Bundle\Observers\ProductBundleObserver;
use TechDivision\Import\Product\Bundle\Utils\ColumnKeys;
use TechDivision\Import\Product\Bundle\Utils\ConfigurationKeys;
use TechDivision\Import\Utils\ProductTypes;

/**
* @copyright Copyright (c) 2024 TechDivision GmbH <[email protected]> - TechDivision GmbH
* @link https://www.techdivision.com/
* @author MET <[email protected]>
*/
class CleanUpBundleProductRelationsObserver extends AbstractProductImportObserver
{
/**
* @var ProductBundleProcessorInterface
*/
protected $productBundleProcessor;

/**
* @param ProductBundleProcessorInterface $productBundleProcessor
* @param StateDetectorInterface|null $stateDetector
*/
public function __construct(
ProductBundleProcessorInterface $productBundleProcessor,
StateDetectorInterface $stateDetector = null
) {
parent::__construct($stateDetector);
$this->productBundleProcessor = $productBundleProcessor;
}

/**
* @return ProductBundleProcessorInterface
*/
protected function getProductBundleProcessor()
{
return $this->productBundleProcessor;
}

/**
* @return void
* @throws Exception
*/
protected function process()
{

// query whether we've found a configurable product or not
if ($this->getValue(ColumnKeys::PRODUCT_TYPE) !== ProductTypes::BUNDLE) {
return;
}

// query whether the media gallery has to be cleaned up or not
if ($this->getSubject()->getConfiguration()->hasParam(ConfigurationKeys::CLEAN_UP_BUNDLE) &&
$this->getSubject()->getConfiguration()->getParam(ConfigurationKeys::CLEAN_UP_BUNDLE)
) {

$this->cleanUpBundles();

$this->getSubject()
->getSystemLogger()
->debug(
$this->getSubject()->appendExceptionSuffix(
sprintf(
'Successfully clean up variants for product with SKU "%s"',
$this->getValue(ColumnKeys::SKU)
)
)
);
}
}

/**
* @return void
* @throws Exception Is thrown, if either the variant children und attributes can not be deleted
*/
protected function cleanUpBundles()
{
// TODO herausfinden wie
}

/**
* Delete not exists import variants from database.
*
* @param int $parentProductId The ID of the parent product
* @param array $childData The array of variants
*
* @return void
* @throws Exception
*/
protected function cleanUpVariantChildren($parentProductId, array $childData)
{
if (empty($childData)) {
return;
}

$parentSku = $this->getValue(ColumnKeys::SKU);

// TODO remove the old links
}

/**
* Return's the PK to create the product => variant relation.
*
* @return integer The PK to create the relation with
*/
protected function getLastPrimaryKey()
{
return $this->getLastEntityId();
}
}
27 changes: 27 additions & 0 deletions src/Utils/ConfigurationKeys.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Copyright (c) 2024 TechDivision GmbH
* All rights reserved
*
* This product includes proprietary software developed at TechDivision GmbH, Germany
* For more information see https://www.techdivision.com/
*
* To obtain a valid license for using this software please contact us at
* [email protected]
*/
declare(strict_types=1);

namespace TechDivision\Import\Product\Bundle\Utils;

/**
* @copyright Copyright (c) 2024 TechDivision GmbH <[email protected]> - TechDivision GmbH
* @link https://www.techdivision.com/
* @author MET <[email protected]>
*/
class ConfigurationKeys extends \TechDivision\Import\Utils\ConfigurationKeys
{
/**
* @var string
*/
const CLEAN_UP_BUNDLE = 'clean-up-bundle';
}
6 changes: 5 additions & 1 deletion symfony/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@
<argument type="service" id="import_product.processor.product.bunch"/>
<argument type="string">%import_product_bundle.param.sku.column.name%</argument>
</service>
<service id="import_product_bundle.observer.clean.up.product.bundle" class="TechDivision\Import\Product\Bundle\Observers\CleanUpBundleProductRelationsObserver">
<argument type="service" id="import_product_bundle.processor.product.bundle"/>
</service>


<!--
| The DI configuration for the composite observers of the replace operation.
Expand Down Expand Up @@ -261,4 +265,4 @@

</services>

</container>
</container>
Loading