60 \
Magento\Framework\Stdlib\DateTime\TimezoneInterface $date,
63 Json $serializer =
null 68 $this->_associatedEntitiesMap = $this->getAssociatedEntitiesMap();
79 $this->_map[
'fields'][
'rule_id'] =
'main_table.rule_id';
96 $ruleIdField = $entityInfo[
'rule_id_field'];
100 $this->
getTable($entityInfo[
'associations_table'])
102 $ruleIdField .
' IN (?)',
108 array_map(
function ($associatedEntity) use ($entityInfo, $ruleIdField, $objectField) {
110 $itemAssociatedValue =
$item->getData($objectField) ===
null ? [] :
$item->getData($objectField);
111 $itemAssociatedValue[] = $associatedEntity[$entityInfo[
'entity_id_field']];
112 $item->setData($objectField, $itemAssociatedValue);
113 }, $associatedEntities);
126 $this->
setFlag(
'add_websites_to_result',
false);
127 return parent::_afterLoad();
151 if (!$this->
getFlag(
'validation_filter')) {
154 parent::_initSelect();
162 [
'rule_coupons' => $this->
getTable(
'salesrule_coupon')],
164 'main_table.rule_id = rule_coupons.rule_id AND main_table.coupon_type != ?',
171 'main_table.coupon_type = ? ',
175 $autoGeneratedCouponCondition = [
177 "main_table.coupon_type = ?",
181 "rule_coupons.type = ?",
182 \
Magento\SalesRule\Api\Data\CouponInterface::TYPE_GENERATED
186 $orWhereConditions = [
187 "(" . implode($autoGeneratedCouponCondition,
" AND ") .
")",
189 '(main_table.coupon_type = ? AND main_table.use_auto_generation = 1 AND rule_coupons.type = 1)',
193 '(main_table.coupon_type = ? AND main_table.use_auto_generation = 0 AND rule_coupons.type = 0)',
198 $andWhereConditions = [
200 'rule_coupons.code = ?',
204 '(rule_coupons.expiration_date IS NULL OR rule_coupons.expiration_date >= ?)',
205 $this->_date->date()->format(
'Y-m-d')
209 $orWhereCondition = implode(
' OR ', $orWhereConditions);
210 $andWhereCondition = implode(
' AND ', $andWhereConditions);
213 $noCouponWhereCondition .
' OR ((' . $orWhereCondition .
') AND ' . $andWhereCondition .
')',
219 'main_table.coupon_type',
223 $this->
setOrder(
'sort_order', self::SORT_ORDER_ASC);
224 $this->
setFlag(
'validation_filter',
true);
243 if (!$this->
getFlag(
'website_group_date_filter')) {
245 $now = $this->_date->date()->format(
'Y-m-d');
253 [
'customer_group_ids' => $this->
getTable($entityInfo[
'associations_table'])],
256 $entityInfo[
'rule_id_field'] .
257 ' = customer_group_ids.' .
258 $entityInfo[
'rule_id_field'] .
259 ' AND customer_group_ids.' .
260 $entityInfo[
'entity_id_field'] .
262 (
int)$customerGroupId
267 $this->getDateApplier()->applyDate($this->
getSelect(), $now);
271 $this->
setFlag(
'website_group_date_filter',
true);
284 parent::_initSelect();
286 [
'rule_coupons' => $this->
getTable(
'salesrule_coupon')],
287 'main_table.rule_id = rule_coupons.rule_id AND rule_coupons.is_primary = 1',
301 $match = sprintf(
'%%%s%%', substr($this->serializer->serialize([
'attribute' =>
$attributeCode]), 1, -1));
324 sprintf(
'(%s OR %s)', $cCond, $aCond),
354 if (!$this->
getFlag(
'is_customer_group_joined')) {
355 $this->
setFlag(
'is_customer_group_joined',
true);
357 [
'customer_group' => $this->
getTable($entityInfo[
'associations_table'])],
359 ->quoteInto(
'customer_group.' . $entityInfo[
'entity_id_field'] .
' = ?', $customerGroupId)
360 .
' AND main_table.' . $entityInfo[
'rule_id_field'] .
' = customer_group.' 361 . $entityInfo[
'rule_id_field'],
372 private function getAssociatedEntitiesMap()
374 if (!$this->_associatedEntitiesMap) {
386 private function getDateApplier()
388 if (
null === $this->dateApplier) {
const COUPON_TYPE_NO_COUPON
__construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $date, \Magento\Framework\DB\Adapter\AdapterInterface $connection=null, \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource=null, Json $serializer=null)
const COUPON_TYPE_SPECIFIC
getItemByColumnValue($column, $value)
_getAssociatedEntityInfo($entityType)
addIsActiveFilter($isActive=1)
mapAssociatedEntities($entityType, $objectField)
_getConditionSql($fieldName, $condition)
addAllowedSalesRulesFilter()
addWebsiteFilter($websiteId)
addWebsiteGroupDateFilter($websiteId, $customerGroupId, $now=null)
setValidationFilter( $websiteId, $customerGroupId, $couponCode='', $now=null, Address $address=null)
addFieldToFilter($field, $condition=null)
setOrder($field, $direction=self::SORT_ORDER_DESC)
setFlag($flag, $value=null)
_init($model, $resourceModel)
addAttributeInConditionFilter($attributeCode)
addCustomerGroupFilter($customerGroupId)
getColumnValues($colName)