1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
6
|
|
|
* |
7
|
|
|
* http://www.lockon.co.jp/ |
8
|
|
|
* |
9
|
|
|
* This program is free software; you can redistribute it and/or |
10
|
|
|
* modify it under the terms of the GNU General Public License |
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
12
|
|
|
* of the License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with this program; if not, write to the Free Software |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
namespace Eccube\Repository; |
26
|
|
|
|
27
|
|
|
use Doctrine\ORM\QueryBuilder; |
28
|
|
|
use Eccube\Annotation\Repository; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* CustomerFavoriteProductRepository |
32
|
|
|
* |
33
|
|
|
* This class was generated by the Doctrine ORM. Add your own custom |
34
|
|
|
* repository methods below. |
35
|
|
|
* |
36
|
|
|
* @Repository |
37
|
|
|
*/ |
38
|
|
|
class CustomerFavoriteProductRepository extends AbstractRepository |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* @param \Eccube\Entity\Customer $Customer |
42
|
|
|
* @param \Eccube\Entity\Product $Product |
43
|
|
|
*/ |
44
|
2 |
|
public function addFavorite(\Eccube\Entity\Customer $Customer, \Eccube\Entity\Product $Product) |
45
|
|
|
{ |
46
|
2 |
|
if ($this->isFavorite($Customer, $Product)) { |
47
|
|
|
return; |
48
|
|
|
} else { |
49
|
2 |
|
$CustomerFavoriteProduct = new \Eccube\Entity\CustomerFavoriteProduct(); |
50
|
2 |
|
$CustomerFavoriteProduct->setCustomer($Customer); |
51
|
2 |
|
$CustomerFavoriteProduct->setProduct($Product); |
52
|
2 |
|
$CustomerFavoriteProduct->setCreateDate(new \DateTime()); |
53
|
2 |
|
$CustomerFavoriteProduct->setUpdateDate(new \DateTime()); |
54
|
|
|
|
55
|
2 |
|
$em = $this->getEntityManager(); |
56
|
2 |
|
$em->persist($CustomerFavoriteProduct); |
57
|
2 |
|
$em->flush(); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param \Eccube\Entity\Customer $Customer |
63
|
|
|
* @param \Eccube\Entity\Product $Product |
64
|
|
|
* @return bool |
65
|
|
|
*/ |
66
|
2 |
|
public function isFavorite(\Eccube\Entity\Customer $Customer, \Eccube\Entity\Product $Product) |
67
|
|
|
{ |
68
|
2 |
|
$qb = $this->createQueryBuilder('cf') |
69
|
2 |
|
->select('COUNT(cf.Product)') |
70
|
2 |
|
->andWhere('cf.Customer = :Customer AND cf.Product = :Product') |
71
|
2 |
|
->setParameters(array( |
72
|
2 |
|
'Customer' => $Customer, |
73
|
2 |
|
'Product' => $Product, |
74
|
|
|
)); |
75
|
|
|
$count = $qb |
76
|
2 |
|
->getQuery() |
77
|
2 |
|
->getSingleScalarResult(); |
78
|
|
|
|
79
|
2 |
|
return $count > 0; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param \Eccube\Entity\Customer $Customer |
84
|
|
|
* @return QueryBuilder |
85
|
|
|
*/ |
86
|
2 |
|
public function getQueryBuilderByCustomer(\Eccube\Entity\Customer $Customer) |
87
|
|
|
{ |
88
|
2 |
|
$qb = $this->createQueryBuilder('cfp') |
89
|
2 |
|
->select('cfp, p') |
90
|
2 |
|
->innerJoin('cfp.Product', 'p') |
91
|
2 |
|
->where('cfp.Customer = :Customer AND p.Status = 1') |
92
|
2 |
|
->setParameter('Customer', $Customer); |
93
|
|
|
|
94
|
|
|
// Order By |
95
|
2 |
|
$qb->addOrderBy('cfp.create_date', 'DESC'); |
96
|
|
|
|
97
|
2 |
|
return $qb; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* お気に入りを削除します. |
102
|
|
|
* |
103
|
|
|
* @param \Eccube\Entity\CustomerFavoriteProduct $CustomerFavoriteProduct |
104
|
|
|
*/ |
105
|
1 |
|
public function delete($CustomerFavoriteProduct) |
106
|
|
|
{ |
107
|
1 |
|
$em = $this->getEntityManager(); |
108
|
1 |
|
$em->remove($CustomerFavoriteProduct); |
109
|
1 |
|
$em->flush($CustomerFavoriteProduct); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|