59 private $metadataPool;
80 $this->_resourceCoupon = $resourceCoupon;
84 $this->_associatedEntitiesMap = $associatedEntitiesMapInstance->getData();
97 $this->
_init(
'salesrule',
'rule_id');
107 if (!$this->customerGroupIds) {
110 $object->
setData(
'customer_group_ids', $this->customerGroupIds);
120 if (!$this->websiteIds) {
124 $object->
setData(
'website_ids', $this->websiteIds);
135 if (!$object->getDiscountQty()) {
139 parent::_beforeSave($object);
154 $this->getEntityManager()->load($object,
$value);
168 if ($object->hasStoreLabels()) {
173 $ruleProductAttributes = array_merge(
177 if (count($ruleProductAttributes)) {
182 if ($object->getUseAutoGeneration() && $object->
hasDataChanges()) {
183 $this->_resourceCoupon->updateSpecificCoupons($object);
185 return parent::_afterSave($object);
199 $this->
getTable(
'salesrule_customer'),
200 [
'cnt' =>
'count(*)']
204 'customer_id = :customer_id' 219 $deleteByStoreIds = [];
225 if ($this->string->strlen(
$label)) {
238 if (!empty($deleteByStoreIds)) {
260 [
'store_id',
'label']
282 'store_id IN(0, :store_id)' 298 [
'a' => $this->
getTable(
'salesrule_product_attribute')],
301 [
'ea' => $this->
getTable(
'eav_attribute')],
302 'ea.attribute_id = a.attribute_id',
318 $metadata = $this->metadataPool->getMetadata(RuleInterface::class);
320 $this->
getTable(
'salesrule_product_attribute'),
321 [$metadata->getLinkField() .
'=?' =>
$rule->getData($metadata->getLinkField())]
327 [
'a' => $this->
getTable(
'eav_attribute')],
330 'a.attribute_code IN (?)',
334 if ($attributesFound) {
340 foreach (
$rule->getCustomerGroupIds() as $customerGroupId) {
344 $metadata->getLinkField() =>
$rule->getData($metadata->getLinkField()),
346 'customer_group_id' => $customerGroupId,
368 '~"Magento\\\\\\\\SalesRule\\\\\\\\Model\\\\\\\\Rule\\\\\\\\Condition\\\\\\\\Product","attribute":"(.*?)"~',
373 return array_values($matches[1]);
382 $this->getEntityManager()->save($object);
394 $this->getEntityManager()->delete($object);
402 private function getEntityManager()
404 if (
null === $this->entityManager) {
loadWebsiteIds(AbstractModel $object)
_beforeSave(AbstractModel $object)
setData($key, $value=null)
_afterSave(AbstractModel $object)
saveStoreLabels($ruleId, $labels)
getStoreLabel($ruleId, $storeId)
load(AbstractModel $object, $value, $field=null)
getCustomerGroupIds($ruleId)
_init($mainTable, $idFieldName)
loadCustomerGroupIds(AbstractModel $object)
setActualProductAttributes($rule, $attributes)
getCustomerUses($rule, $customerId)
getProductAttributes($serializedString)
__construct(\Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Framework\Stdlib\StringUtils $string, \Magento\SalesRule\Model\ResourceModel\Coupon $resourceCoupon, $connectionName=null, \Magento\Framework\DataObject $associatedEntityMapInstance=null, Json $serializer=null, MetadataPool $metadataPool=null)
save(\Magento\Framework\Model\AbstractModel $object)