Skip to content

Commit

Permalink
fixed duplicate option assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
FCStephanAltmann committed Mar 1, 2019
1 parent c3955b6 commit a01cbb8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Services/Helper/AbstractHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ public function createMediaImage($url, $albumName)

$path_info = pathinfo($url);
$filename = $this->filterNotAllowedCharactersFromURL($path_info['filename']);

if(!array_key_exists('extension', $path_info)) {
return null;
}

$path = 'media/image/' . $filename . '.' . $path_info['extension'];

if ( ! $contents = $this->grab_image($url)) {
Expand Down
19 changes: 16 additions & 3 deletions Services/Helper/ShopwareArticleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,17 @@ public function assignVariants(Article &$article, Detail $detail, array $variant
$this->addSetOptions($set, $options);
}

$detail->setConfiguratorOptions($options);
//TODO: check if already added
$definedOptions = $detail->getConfiguratorOptions();

foreach ($options as $addOption) {
if(!$definedOptions->contains($addOption)) {
$definedOptions->add($addOption);
}
}


//$detail->setConfiguratorOptions($options);
}
}

Expand All @@ -310,9 +320,11 @@ public function getAssignableConfiguratorOptions(Article &$article, array $varia

$options = [];

$this->configuratorOptions = array_change_key_case($this->configuratorOptions, CASE_LOWER);

foreach($variants as $variant) {
if(array_key_exists($variant["value"], $this->configuratorOptions)) {
$option = $this->configuratorOptions[$variant["value"]];
if(array_key_exists(strtolower($variant["value"]), $this->configuratorOptions)) {
$option = $this->configuratorOptions[strtolower($variant["value"])];
}
else {
$option = new Option();
Expand All @@ -327,6 +339,7 @@ public function getAssignableConfiguratorOptions(Article &$article, array $varia
$this->entityManager->flush($option);

$this->getConfiguratorOptions();
$this->configuratorOptions = array_change_key_case($this->configuratorOptions, CASE_LOWER);
}

array_push($options, $option);
Expand Down
3 changes: 2 additions & 1 deletion Services/ReadData/External/ReadProductsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public function transform(array $products)

$variants = [];

if (!array_key_exists('Attributes', $product) && array_key_exists('BaseProducts', $product) && $product["BaseProductFlag"] != "1") {
if (!array_key_exists('Attributes', $product) && array_key_exists('BaseProducts', $product) && $product["BaseProductFlag"] != "1"
&& array_key_exists('BaseProductID', $product['BaseProducts']['BaseProduct'])) {
$valueArticle->setMainArticleId($product['BaseProducts']['BaseProduct']['BaseProductID']);

$variants[] = array(
Expand Down

0 comments on commit a01cbb8

Please sign in to comment.