Skip to content

Commit

Permalink
Merge pull request #38 from FATCHIP-GmbH/0080173_customergroup_prices
Browse files Browse the repository at this point in the history
0080173: fixed handling of missing prices for customer groups
  • Loading branch information
FATCHIP-GmbH authored Nov 4, 2021
2 parents 608555a + 3d977f8 commit 9082da1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
36 changes: 27 additions & 9 deletions Services/Helper/ShopwareArticleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,18 @@ public function setSimpleArticleValues(ShopwareArticle $entity, ValueArticle &$a
$article->setLastStock(true);
}

/** @var Price $price */
$price = $detail->getPrices()->filter(function (Price $price) {
return $price->getCustomerGroup() === $this->customerGroup;
})->first();
$prices = $detail->getPrices();
foreach ($prices AS $detailPrice) {
$group = $detailPrice->getCustomerGroup();
if ($group === $this->customerGroup) {
$price = $detailPrice;
break;
}
}
// if no price is found for the default customer group, use first found price
if (empty($price)) {
$price = $detail->getPrices()->first();
}

$price = Helper::convertPrice($price->getPrice(), $entity->getTax()->getTax(), $netInput);
$article->setPrice($price);
Expand Down Expand Up @@ -201,9 +209,18 @@ public function setVariantValues(
$variant->setLastStock(true);
}

$price = $detail->getPrices()->filter(function (Price $price) {
return $price->getCustomerGroup() === $this->customerGroup;
})->first();
$prices = $detail->getPrices();
foreach ($prices AS $detailPrice) {
$group = $detailPrice->getCustomerGroup();
if ($group === $this->customerGroup) {
$price = $detailPrice;
break;
}
}
// if no price is found for the default customer group, use first found price
if (empty($price)) {
$price = $detail->getPrices()->first();
}

$options = [];

Expand Down Expand Up @@ -1018,7 +1035,7 @@ public function getUnexportedArticles($force = false, $exportAll = true)
if ( ! $force) {
$articles =
$articles->andWhere("(attributes.afterbuyId IS NULL OR attributes.afterbuyId = '') OR articles.changed >= :lastExport")
->setParameters(array('lastExport' => $lastExport));
->setParameter('lastExport',$lastExport);
}

$articles = $articles->getQuery()
Expand Down Expand Up @@ -1440,7 +1457,8 @@ private function associateVariantImage(
->from(ImageRule::class, 'rule')
->where('rule.mappingId = :mapping')
->andWhere('rule.optionId = :option')
->setParameters(array('mapping' => $imageMapping->getId(), 'option' => $option->getId()))
->setParameter('mapping', $imageMapping->getId())
->setParameter('option', $option->getId())
->setMaxResults(1)
->getQuery();

Expand Down
8 changes: 4 additions & 4 deletions Services/Helper/ShopwareOrderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public function getUnexportedOrders(array $config)
$minOrderDate = new DateTime($config["minOrderDate"]);

$query->andWhere('orders.orderTime > :minOrderDate')
->setParameters(array('minOrderDate' => $minOrderDate));
->setParameter('minOrderDate', $minOrderDate);
}

$orders = $query
Expand Down Expand Up @@ -433,7 +433,7 @@ public function getNewFullfilledOrders()
->having('history.changeDate >= :lastExport')
->andHaving('history.paymentStatusId = 12')
->andHaving('history.orderStatusId = 2 OR history.orderStatusId = 7')
->setParameters(array('lastExport' => $lastExport))
->setParameter('lastExport', $lastExport)
->getQuery()
->setMaxResults(145)
->getResult();
Expand Down Expand Up @@ -722,7 +722,7 @@ public function getPaymentStates()
->select('states')
->from(OrderStatus::class, 'states', 'states.name')
->where('states.group = :group')
->setParameters(array('group' => 'payment'))
->setParameter('group', 'payment')
->getQuery()
->getResult();

Expand All @@ -738,7 +738,7 @@ public function getShippingStates()
->select('states')
->from(OrderStatus::class, 'states', 'states.name')
->where('states.group = :group')
->setParameters(array('group' => 'state'))
->setParameter('group', 'state')
->getQuery()
->getResult();

Expand Down

0 comments on commit 9082da1

Please sign in to comment.