Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
module-sales-rule
Model
ResourceModel
Coupon
Usage.php
Go to the documentation of this file.
1
<?php
6
namespace
Magento\SalesRule\Model\ResourceModel\Coupon
;
7
13
class
Usage
extends
\Magento\Framework\Model\ResourceModel\Db\AbstractDb
14
{
20
protected
function
_construct
()
21
{
22
$this->
_init
(
'salesrule_coupon_usage'
,
'coupon_id'
);
23
}
24
32
public
function
updateCustomerCouponTimesUsed
(
$customerId
, $couponId)
33
{
34
$connection
= $this->
getConnection
();
35
$select
=
$connection
->select();
36
$select
->from(
37
$this->
getMainTable
(),
38
[
'times_used'
]
39
)->where(
40
'coupon_id = :coupon_id'
41
)->where(
42
'customer_id = :customer_id'
43
);
44
45
$timesUsed =
$connection
->fetchOne(
$select
, [
':coupon_id'
=> $couponId,
':customer_id'
=>
$customerId
]);
46
47
if
($timesUsed > 0) {
48
$this->
getConnection
()->update(
49
$this->
getMainTable
(),
50
[
'times_used'
=> $timesUsed + 1],
51
[
'coupon_id = ?'
=> $couponId,
'customer_id = ?'
=>
$customerId
]
52
);
53
}
else
{
54
$this->
getConnection
()->insert(
55
$this->
getMainTable
(),
56
[
'coupon_id'
=> $couponId,
'customer_id'
=>
$customerId
,
'times_used'
=> 1]
57
);
58
}
59
}
60
69
public
function
loadByCustomerCoupon
(\
Magento
\Framework\
DataObject
$object,
$customerId
, $couponId)
70
{
71
$connection
= $this->
getConnection
();
72
if
(
$connection
&& $couponId &&
$customerId
) {
73
$select
=
$connection
->select()->from(
74
$this->
getMainTable
()
75
)->where(
76
'customer_id =:customet_id'
77
)->where(
78
'coupon_id = :coupon_id'
79
);
80
$data
=
$connection
->fetchRow(
$select
, [
':coupon_id'
=> $couponId,
':customet_id'
=>
$customerId
]);
81
if
(
$data
) {
82
$object->setData(
$data
);
83
}
84
}
85
if
($object instanceof \
Magento
\Framework\Model\
AbstractModel
) {
86
$this->
_afterLoad
($object);
87
}
88
return
$this;
89
}
90
}
Magento\Framework\Model\ResourceModel\Db\AbstractDb\getMainTable
getMainTable()
Definition:
AbstractDb.php:264
Magento\Framework\Model\AbstractModel
Definition:
AbstractModel.php:19
Magento\SalesRule\Model\ResourceModel\Coupon\Usage\loadByCustomerCoupon
loadByCustomerCoupon(\Magento\Framework\DataObject $object, $customerId, $couponId)
Definition:
Usage.php:69
Magento\SalesRule\Model\ResourceModel\Coupon\Usage\updateCustomerCouponTimesUsed
updateCustomerCouponTimesUsed($customerId, $couponId)
Definition:
Usage.php:32
Magento\Framework\Model\ResourceModel\Db\AbstractDb\_init
_init($mainTable, $idFieldName)
Definition:
AbstractDb.php:186
Magento\Framework\DataObject
Definition:
DataObject.php:15
Magento\SalesRule\Model\ResourceModel\Coupon\Usage\_construct
_construct()
Definition:
Usage.php:20
Magento\SalesRule\Model\ResourceModel\Coupon\Usage
Definition:
Usage.php:13
$select
$select
Definition:
catalog_rule_10_off_not_logged_rollback.php:14
$data
$data
Definition:
attribute_set_with_image_attribute.php:16
$customerId
$customerId
Definition:
quote_with_customer.php:16
Magento
Magento\SalesRule\Model\ResourceModel\Coupon
Definition:
Collection.php:6
Magento\Framework\Model\ResourceModel\Db\AbstractDb
Definition:
AbstractDb.php:24
$connection
$connection
Definition:
bulk.php:13
Magento\Framework\Model\ResourceModel\Db\AbstractDb\_afterLoad
_afterLoad(\Magento\Framework\Model\AbstractModel $object)
Definition:
AbstractDb.php:641
Magento\Framework\Model\ResourceModel\Db\AbstractDb\getConnection
getConnection()
Definition:
AbstractDb.php:325