#StackBounty: #magento2.3 #price #multistore #shipping-address Switch Magento store if country changes

Bounty: 100

I have a website i want to set the price of Product A as Rs 10 (fs shipping address is India) and Rs 15 (if the shipping address is outside India)

I want that during checkout if the user selects country price gets changed based on his country.

for that

1: I have created two stores Store India and STore Outside India 
2: price attribute scope changed to store level
3: I do not want to restrict country for store instead it should auto switch 

based on the shipping country

what should I do to achieve above please help


Get this bounty!!!

#StackBounty: #magento2 #price #vat How to calculate tax based on 4 decimals?

Bounty: 50

Magento 2 calculates the price Inc tax based on 2 decimals. I managed to save the price as 4 decimals. This get’s stored in the catalog_product_entity_decimal table.

The problem now is that the vat does not get calculated based on the 4 decimals but the 2.

Example:

  • Stored price: 41,275200
  • vat percentage: 9 %
  • expected price inc VAT: 44,989968 (displayed as 44,99)
  • actual price displayed 45,00 (41,28 x 1,09 = 44,9952)

How can I fix this, I want the calculations based on all the decimals (4 in my case), but still want to display prices with 2 decimals?


Get this bounty!!!

#StackBounty: #magento2 #price #addtocart #tax How to set custom tax price during add to cart in Magento 2

Bounty: 50

I am adding product to cart using ajax call.

Here is my controller code.

use MagentoFrameworkControllerResultFactory;
use MagentoFrameworkAppActionAction;
use MagentoFrameworkAppActionContext;
class AddItems extends MagentoFrameworkAppActionAction
{

 protected $formKey;   
 protected $cart;
 protected $product;
 protected $_resource;
 protected $checkoutSession;
 protected $_taxCalculationService;
 protected $quoteRepository;

public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkDataFormFormKey $formKey,
MagentoCheckoutModelCart $cart,
MagentoCatalogModelProductFactory $product,
MagentoFrameworkAppResourceConnection $resource,
MagentoCheckoutModelSession $checkoutSession,
MagentoTaxApiTaxCalculationInterface $taxCalculationService,
MagentoQuoteApiCartRepositoryInterface $quoteRepository,
  array $data = []
) {
   $this->formKey = $formKey;
   $this->cart = $cart;
   $this->product = $product;     
   $this->_resource = $resource;
   $this->checkoutSession = $checkoutSession;  
   $this->_taxCalculationService = $taxCalculationService; 
   $this->quoteRepository = $quoteRepository;
    parent::__construct($context);
 }

 public function execute()
{ 

 try{
   $productId = 10;
    $params = array(
        'form_key' => $this->formKey->getFormKey(),
        'product_id' => $productId, //product Id
        'qty'   =>1 //quantity of product                
    );
    $_product = $this->product->create()->load($productId);       
     $item = $this->cart->getQuote()->getItemByProduct($_product );
    if($item){          
        $quote = $this->cart->getQuote();                   
        $quote->updateItem($item->getId(), array( 'qty' => 1));
        $quote->save();
    }else{                  
        $this->cart->addProduct($_product , $params);
    }
  $customPrice = 1000;
  $grossAmt = 550;

  $productTaxClassId = $child_product->getTaxClassId();
  $customerId = $this->getCustomerId();
  $storeId = $this->_storeManager->getStore()->getId();
  $productRates = $this->_taxCalculationService->getCalculatedRate($productTaxClassId, $customerId, $storeId);

  $taxAmount = ((1 * $grossAmt * $productRates) / 100);

  $quote = $this->cart->getQuote();
  $quoteId = $quote->getId();   
  $productItem = $this->getProductQuote($_product );                
  $productItem->setCustomPrice($customPrice);
  $productItem->setOriginalCustomPrice($customPrice);
  $productItem->getProduct()->setIsSuperMode(true);   
  $this->cart->save(); 
   $productItem->setTaxAmount($taxAmount)->setBaseTaxAmount($taxAmount)->save(); 
    $quote = $this->checkoutSession->getQuote();
    $quote->collectTotals();
    //$quote->save(); 
    $this->quoteRepository->save($quote);
   }
 }

public function getProductQuote($product) {
    $quote = $this->checkoutSession->getQuote();        
    $cartItems = $quote->getItemByProduct($product);        
    return $cartItems;
}
}     

Using above code, i am able to add product to cart with custom price.

I need to add custom tax price also upon adding the product to cart. Right now tax is not getting applied.

How can i set custom tax price for the product added to cart.

Can anyone help me please, custom tax price i have got in variable, $taxAmount

This code save the data to “tax_amount” and “base_tax_amount” fields in quote_item table but when navigated to cart page, tax is showing as 0 and in table values are restored to 0.

$productItem->setTaxAmount($taxAmount)->setBaseTaxAmount($taxAmount)->save(); 
             $quote = $this->checkoutSession->getQuote();
             $quote->collectTotals();
             $this->quoteRepository->save($quote);
            // $quote->save();

Please share the ideas where i am doing wrong here. Thanks in advance


Get this bounty!!!

#StackBounty: #magento2 #price #currency Magento 2 Checkout Page, different price setup

Bounty: 50

Currently I’m on a magento project and somehow, I can’t understand the logic behind this last page.

The Currency that I’ve got is EURO, and in the /vendor/magento/zendframework1/library/Zend/Locale/Data/pt_PT.xml (for now it’s there, eventually I’ll find where to place it) I’ve setted the numbers to be grouped by “.” and decimal cases by “,”.

The screenshot below shows on the right side, how its supposed to be. However, the left side is on a completly different pattern and I can’t seem to find where to make this change.

Note:This has happened on another place but I’ve used the $this->helper to format the price on phtml files.

enter image description here


Get this bounty!!!