0

I started in Magento 2 a week ago and don't know much about it, I created a Cart Price Rule named "10% billet discount" that is applied in a few items, with specific attributes.

I want to display this Rule on specific products page that the rule is applied. There is a way that I can do that?

  • Welcome, to Magento StackExchange. I think you need to create a catalog price rule for that. – Emipro Technologies Pvt. Ltd. Apr 20 '18 at 11:31
  • i thought that too, but i can't set one condition for payment method (billet) in catalog price rule. – João Victor Apr 20 '18 at 11:45
  • Has anybody any ideas how to achieve that? – Samuel Barr Jul 27 '18 at 13:56
0

Wreite on code product listing page or product details page.

                                  $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
                                  $rules = $objectManager->create('Magento\SalesRule\Model\RuleFactory')->create();
                                  $rules=$rules->getCollection();
                                  $objDate = $objectManager->create('Magento\Framework\Stdlib\DateTime\DateTime');
                                  $_currentTime = strtotime($objDate->date());
                                  foreach ($rules as $rule) {
                                        $fromDate = $rule->getFromDate();
                                        $toDate = $rule->getToDate();
                                        if (isset($fromDate) && $_currentTime >= strtotime($fromDate)) {
                                            if (isset($toDate)) {
                                                if (strtotime($toDate) >= $_currentTime) {



                                                $product = $objectManager->get('Magento\Catalog\Model\Product')->load($_product->getId());
                                                $item = $objectManager->create('Magento\Catalog\Model\Product');
                                                $item->setProduct($product);
                                                if ($rule->getActions()->validate($item)) {
                                                    $product_label=$rule->getName();
                                                    break;
                                                }

                                                }
                                            }
                                        }
                                    }

                        if($product_label)
                            echo '<div class="product-labels">'.$product_label.'</div>';

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.