Skip to content

Commit

Permalink
Try to fix category duplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Dec 17, 2023
1 parent 0f67f1f commit 4236094
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/Discomp/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public function freshItems()
$errors = 0;
$freshItems = $this->getFreshItems();
foreach ($freshItems as $pos => $activeItemData) {
$this->sokoban->curlInit();
$this->sokoban->dataReset();
$discompItemCode = $activeItemData['CODE'];
$this->sokoban->setObjectName('(' . $pos . '/' . count($freshItems) . ') StoreItem:' . $discompItemCode);
Expand Down Expand Up @@ -264,6 +265,7 @@ public function freshItems()
$this->sokoban->addStatusMessage(RO::uncode($this->sokoban->getRecordCode()) . ' Img: ' . $activeItemData['IMAGES']['IMAGE'], $stdImg->lastResponseCode == 201 ? 'success' : 'error');
$this->images++;
}
unset($stdImg);
}
if ($this->sokoban->lastResponseCode == 201) {
$this->new++;
Expand All @@ -278,6 +280,7 @@ public function freshItems()
$this->discomper->addStatusMessage($progressInfo . ' already enlisted', 'info');
}
}
$this->removeItemFromTree($this->sokoban);
if (array_key_exists('CATEGORIES', $activeItemData)) {
foreach ($this->prepareCategories($activeItemData['CATEGORIES']['CATEGORY']) as $category) {
$this->category->insertToAbraFlexi(['idZaznamu' => \AbraFlexi\RO::code($activeItemData['PART_NUMBER']), 'uzel' => $this->treeCache[$category]]);
Expand All @@ -303,6 +306,7 @@ public function freshItems()
}

$this->updatePrice($activeItemData);
$this->sokoban->disconnect();
}
}

Expand Down Expand Up @@ -394,11 +398,11 @@ public function allTimeItems()

if (array_key_exists('ImgIs', $stoItem) && $stoItem['ImgIs'] == 1) {
$stdImg = \AbraFlexi\Priloha::addAttachment($this->sokoban, $discompItemCode . '.jpg', $this->discomper->getImage($baseImageUrl), $this->discomper->getResponseMime());
$this->sokoban->addStatusMessage($this->sokoban . ' ' . $baseImageUrl, $stdImg->lastResponseCode == 201 ? 'success' : 'error');
// $this->sokoban->addStatusMessage($this->sokoban . ' ' . $baseImageUrl, $stdImg->lastResponseCode == 201 ? 'success' : 'error');
}
if (array_key_exists('EnlargementIs', $stoItem) && $stoItem['EnlargementIs'] == 1) {
$largeImg = \AbraFlexi\Priloha::addAttachment($this->sokoban, $discompItemCode . '.jpg', $this->discomper->getImage($largeImageUrl), $this->discomper->getResponseMime());
$this->sokoban->addStatusMessage(\AbraFlexi\RO::uncode($this->sokoban) . ' ' . $largeImageUrl, $largeImg->lastResponseCode == 201 ? 'success' : 'error');
// $this->sokoban->addStatusMessage(\AbraFlexi\RO::uncode($this->sokoban) . ' ' . $largeImageUrl, $largeImg->lastResponseCode == 201 ? 'success' : 'error');
}

if ($this->sokoban->lastResponseCode == 201) {
Expand Down Expand Up @@ -553,22 +557,24 @@ public function categoryBranch(array $nodes)
{
$parent = '';
foreach ($nodes as $level => $node) {
$parent = $this->createBranchNode($node, $level, $parent);
$parent = $this->createBranchNode($node, $level, $parent, md5(implode('', array_slice($nodes, 0, $level + 1))));
}
return $parent;
}

/**
* Create Branch Node
*
* @param string $node
* @param int $level
* @param string $parent
* @param srting $kod focred code for branch
*
* @return string
*/
public function createBranchNode(string $node, int $level, string $parent)
public function createBranchNode(string $node, int $level, string $parent, string $kod)
{
$kod = RO::code(substr(\Ease\Functions::rip(substr(RO::uncode($parent), 0, 10) . str_replace(' ', '', $node)), 0, 30));
$kod = RO::code(substr($kod, 0, 30));
if (array_key_exists($level, $this->levels)) {
$this->levels[$level]++;
} else {
Expand Down Expand Up @@ -624,4 +630,21 @@ public function findManufacturerCode(string $manufacturerName)
}
return $manufacturer;
}

/**
* Remove Item from Pricelit Category Tree
*
* @param \AbraFlexi\Cenik $item
*/
public function removeItemFromTree($item)
{
$done = 0;
$current = $this->category->getColumnsFromAbraFlexi(['id'], ['idZaznamu' => $item->getRecordID()]);
foreach ($current as $assigned) {
if ($this->category->deleteFromAbraFlexi($assigned['id'])) {
$done++;
}
}
return $done;
}
}

0 comments on commit 4236094

Please sign in to comment.