Shopware6: fix extended Prices

This commit is contained in:
Andreas Palm 2023-10-13 22:55:06 +02:00
parent d39f9bb2fe
commit 10c077006d
3 changed files with 40 additions and 9 deletions

View File

@ -129,6 +129,8 @@ final class Shopware6Client
],
],
];
if ($priceData->getEndingQuantity() > 0)
$data['quantityEnd'] = $priceData->getEndingQuantity();
return $this->request(
'POST',

View File

@ -8,6 +8,8 @@ class PriceData
{
/** @var int */
protected $startingQuantity;
/** @var int|null */
protected $endingQuantity;
/** @var float */
protected $net;
/** @var float */
@ -26,13 +28,14 @@ class PriceData
* @param $currency
* @param $groupName
*/
public function __construct(int $startingQuantity, float $net, float $gross, string $currency, string $groupName)
public function __construct(int $startingQuantity, float $net, float $gross, string $currency, string $groupName, int $endingQuantity = null)
{
$this->startingQuantity = $startingQuantity;
$this->net = $net;
$this->gross = $gross;
$this->currency = $currency;
$this->groupName = $groupName;
$this->endingQuantity = $endingQuantity;
}
/**
@ -95,6 +98,25 @@ class PriceData
return $this;
}
/**
* @return int|null
*/
public function getEndingQuantity(): int|null
{
return $this->endingQuantity;
}
/**
* @param int $endingQuantity
* @return PriceData
*/
public function setEndingQuantity(int $endingQuantity): PriceData
{
$this->endingQuantity = $endingQuantity;
return $this;
}
/**
* @return float
*/

View File

@ -2972,14 +2972,21 @@ class Shopimporter_Shopware6 extends ShopimporterBase
* @return PriceData[]
*/
protected function getPricesFromArray($priceArray): array{
return array_map(static function($price){
return new PriceData(
(int)$price['ab_menge'],
(float)$price['preis'],
(float)$price['bruttopreis'],
$price['waehrung'],
$price['gruppeextern'] ?? '') ;
},$priceArray);
$c = count($priceArray);
$result = [];
for ($i = 0; $i < $c; $i++) {
$end = null;
if ($i+1 < $c && ($priceArray[$i+1]['gruppeextern'] ?? '') == ($priceArray[$i]['gruppeextern'] ?? ''))
$end = (int)$priceArray[$i+1]['ab_menge'] - 1;
$result[] = new PriceData(
(int)$priceArray[$i]['ab_menge'],
(float)$priceArray[$i]['preis'],
(float)$priceArray[$i]['bruttopreis'],
$priceArray[$i]['waehrung'],
$priceArray[$i]['gruppeextern'] ?? '',
$end);
}
return $result;
}
/**