0

I don't want to load shipping method on City changed, if $valuePackage < $valueFreeShipping (because the shippinig cost in this case is zero)

How can I get these two values : $valuePackage(the total cart cost) and $valueFreeShipping (if total cart cost is greater than $valueFreeShipping , the shipping cost is zero) inside the file

vendor/..../romcity/view/frontend/web/js/model/shipping-rates-validation-rules.js ?

i need something like this

 if ($valuePackage < $valueFreeShipping) {
observableFields.push('city_id'); // Load shipping method on City_id changed
}

$valuePackage and $valueFreeShipping are not defined inside the file vendor/..../romcity/view/frontend/web/js/model/shipping-rates-validation-rules.js

Thank you!

0

in block:

public function getFreeShippingValue()
{
    return $this->scopeConfig->getValue('carriers/freeshipping/free_shipping_subtotal', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}

in template:

$freeShipping = $block->getFreeShippingValue();

       <script>
       freeShipping = <?= /* @escapeNotVerified */ $freeShipping ?>;
   </script>

totals cart: in block:

private $cartHelper;
/**
 * Pricing helper.
 *
 * @var \Magento\Framework\Pricing\Helper\Data
 */
private $pricingHelper;
    \Magento\Checkout\Helper\Cart $cartHelper,
    \Magento\Framework\Pricing\Helper\Data $pricingHelper,
public function getCartHelper()
{
    return $this->cartHelper;
}
/**
 * Get pricing helper.
 *
 * @return \Magento\Framework\Pricing\Helper\Data
 */
public function getPricingHelper()
{
    return $this->pricingHelper;
}

in template $quote = $block->getCartHelper()->getQuote();
$total = $quote->getSubtotal();

  • Thank you so much for your answer, but how do I get these values inside the js file: vendor/..../romcity/view/frontend/web/js/model/shipping-rates-validation-rules.js ? – Andreea Onica Sep 9 at 11:17
  • check my answer. add script tag in your template. – MichaelHa Sep 9 at 13:03

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.