3

I have a problem with tier prices and configurable products in magento2. In our solution the customer puts everything in their cart and then in the checkout they qualify for a customer group and through that also for a tier price.

This works very well with simple products. After they have qualified for the price i can make a get request for the rest api and get the totals with these prices updated from the backend. However, configurable products does not seem to update.

The code sets the customer group for the checkout/customer session and then runs collecttotals:

$this->_customerSession->setCustomerGroupId($level->getCustomerGroup());
$this->_checkoutSession->setCustomerData($customerInterface);
$quote->collectTotals()->save(); 

customerInterface object is initalized and has the same group id as mentioned in the code.

I find it very weird that the code acts so differently on a configured product as opposed to a simple one.

Any help would be appreciated.

3
  • Did you find a solution for your issue?
    – Simon
    Commented Sep 25, 2017 at 10:57
  • I do not have the solution, but I may invite you to upgrade to the fresh Magento 2.2 release to see it solves your issue. Commented Oct 2, 2017 at 10:10
  • Can you not simply retrieve the simple products based on the configurable? In the sales_order_item you can find all the information to retrieve the Simple objects.
    – Merijn
    Commented Oct 2, 2017 at 13:47

1 Answer 1

4
+50

I have a little different type of issue with a configurable product. The total of configurable product counted double time.

So I dig into code in Magento 2.2 and found that in Magento 2.2 they change collect function.

vendor/magento/module-quote/Model/Quote/Address/Total/Grand.php

In Magento 2.1

public function collect(
    \Magento\Quote\Model\Quote $quote,
    \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment,
    \Magento\Quote\Model\Quote\Address\Total $total
) {
    $totals = array_sum($total->getAllTotalAmounts());
    $baseTotals = array_sum($total->getAllBaseTotalAmounts());

    $total->setGrandTotal($totals);
    $total->setBaseGrandTotal($baseTotals);
    return $this;
}

In Magento 2.2

public function collect(
    \Magento\Quote\Model\Quoet $quote,
    \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment,
    \Magento\Quote\Model\Quote\Address\Total $total
) {
    $grandTotal = $total->getGrandTotal();
    $baseGrandTotal = $total->getBaseGrandTotal();
    $totals = array_sum($total->getAllTotalAmounts());
    $baseTotals = array_sum($total->getAllBaseTotalAmounts());

    $total->setGrandTotal($grandTotal + $totals);
    $total->setBaseGrandTotal(b$aseGrandTotal + $baseTotals);
    return $this;
}

As this code they first get totals and add into setGrandTotal() and setBaseGrandTotal(). So it makes double time count in products totals.

Also, they change other logic about totals in Magento 2.2. So compare both vendor/module-quote module and found the issue.

May this will helpful for you.

2
  • 1
    Nice explanation
    – Jarnail S
    Commented Oct 3, 2017 at 6:38
  • Nice explanation, so as I suggested to you, try to upgrade to the latest Magento version before debug old version. Commented Oct 3, 2017 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.