Here I Create custom rule condition for custom module in magento 2 now i need to check that all rule at order place time I create event "sales_order_place_after"
in that the rule condition not validate properly
so how can I validate the custom rule condition
here is code for generate custom rule condition in cutom module
LINK:: Magento 2 Can't get the sales rules conditions in my ui form at edit time Magento 2?
<?php
namespace Vednor\Module\Observer;
class OrderPlace implements \Magento\Framework\Event\ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$order = $observer->getEvent()->getOrder();
$order->getId();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$model=$objectManager->create('Vednor\Module\Model\Rule');
$quoteId = $order->getQuoteId();
$quote = $objectManager->create('Magento\Quote\Model\Quote')->load($quoteId);
$datacollection=$model->getCollection()->addFieldToFilter('entity',['eq' => 1])->addFieldToFilter('status',['eq' => 1]);
$ruleData = $datacollection->getData();
echo "<pre>";
echo json_encode($order->getData());
print_r($ruleData);
foreach($ruleData as $data) {
$unserialized_conditions = $data;
var_dump($unserialized_conditions);
if(isset($unserialized_conditions->conditions_serialized[0]->conditions[0]->value)){
$explode_array = explode(",", $unserialized_conditions->conditions_serialized[0]->conditions[0]->value);
$code="";
for($j=0;$j<count($explode_array);$j++)
{
if(trim($explode_array[$j])==$productsku)
{
echo $code.= $rule->getCode();
echo $rulesApplied .= "<strong>".$code."</strong>"."</br>";
}
}
}
// print_r($data['conditions_serialized']);
// echo json_decode($data['conditions_serialized']);
// var_dump($model->getConditions()->validate($quote));
// var_dump($model->getConditions()->validate());
}
// echo json_encode($model->getConditions()->validate());
// print_r(get_class($model));
// $model->getConditions()->validate()
// var_dump($model->getConditions()->validate($model->getConditions()));
// echo json_encode($ruleData[0]['conditions_serialized']);
// $datacollection->getConnection()->validate();
exit;
$statuscode = $observer->getEvent()->getOrder()->getStatus();
$statuslabel = $observer->getEvent()->getOrder()->getStatusLabel();
}
}