Ich habe den folgenden Code verwendet, um die Katalogpreisregel programmgesteuert zu erstellen. Es erstellt die Regel, aber die Bedingungen werden nicht gespeichert.
$catalogPriceRule = $this->_objectManager->create('Magento\CatalogRule\Model\Rule');
$catalogPriceRule
->setName('name')
->setDescription('description')
->setIsActive(1)
->setCustomerGroupIds(array(1))
->setWebsiteIds(array(1))
->setFromDate('')
->setToDate('')
->setSimpleAction('by_fixed')
->setDiscountAmount(10)
->setStopRulesProcessing(0);
$conditions = array();
$conditions[1] = array(
'type' => 'catalogrule/rule_condition_combine',
'aggregator' => 'any',
'value' => "1",
'new_child' => ''
);
$i = 1;
$conditions['1--1'] = array(
'type' => 'catalogrule/rule_condition_product_found',
'value' => 1,
'aggregator' => 'all',
'new_child' => '',
);
$conditions['1--1--1'] = array(
'type' => 'catalogrule/rule_condition_product',
'attribute' => 'sku',
'operator' => '==',
'value' => '24-UB02',
);
$catalogPriceRule->setData('conditions',$conditions);
$catalogPriceRule->loadPost($catalogPriceRule->getData());
$catalogPriceRule->save();
$catalogPriceRule->applyAll();