2

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.

  • Did you find a solution for your issue? – Simon Sep 25 '17 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. – Franck Garnier Oct 2 '17 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 Oct 2 '17 at 13:47
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.

  • 1
    Nice explanation – Jai Oct 3 '17 at 6:38
  • Nice explanation, so as I suggested to you, try to upgrade to the latest Magento version before debug old version. – Franck Garnier Oct 3 '17 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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