-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEshop.php
executable file
·100 lines (84 loc) · 2.79 KB
/
Eshop.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace WebCMS\EshopModule;
/**
* Description of Page
*
* @author Tomáš Voslař <tomas.voslar at webcook.cz>
*/
class Eshop extends \WebCMS\Module
{
protected $name = 'Eshop';
protected $author = 'Tomáš Voslař';
protected $presenters = array(
array(
'name' => 'Eshop',
'frontend' => true,
'parameters' => false,
),
array(
'name' => 'Categories',
'frontend' => true,
'parameters' => true,
),
array(
'name' => 'Products',
'frontend' => false,
),
array(
'name' => 'Cart',
'frontend' => true,
'parameters' => false,
),
array(
'name' => 'Settings',
'frontend' => false,
),
array(
'name' => 'Parameters',
'frontend' => false,
),
array(
'name' => 'RestApi',
'frontend' => true,
'parameters' => true,
),
);
protected $searchable = true;
protected $params = array(
);
public function __construct()
{
$this->addBox('Shopping cart', 'Cart', 'cartBox', 'Eshop');
$this->addBox('Categories list box', 'Categories', 'listBox', 'Eshop');
$this->addBox('Categories list box 2', 'Categories', 'listBox2', 'Eshop');
}
public function search(\Doctrine\ORM\EntityManager $em, $phrase, \WebCMS\Entity\Language $language)
{
$qb = $em->createQueryBuilder();
$query = $qb->select('p')
->from('WebCMS\EshopModule\Doctrine\Product', 'p')
->andwhere('p.title LIKE :word')
->andWhere('p.language = :language')
->setParameter('word', '%'.$phrase.'%')
->setParameter('language', $language)
->groupBy('p.id')
->getQuery();
$pages = $query->getResult();
$categoriesPage = $em->getRepository('WebCMS\Entity\Page')->findOneBy(array(
'moduleName' => 'Eshop',
'presenter' => 'Categories'
));
$results = array();
foreach ($pages as $r) {
$category = $r->getCategories()[0];
$url = ($language->getDefaultFrontend() ? '' : $language->getAbbr().'/').$categoriesPage->getSlug().'/'.$category->getSlug().'/'.$r->getSlug();
$result = new \WebCMS\SearchModule\SearchResult();
$result->setTitle($r->getTitle().' '.\WebCMS\Helpers\SystemHelper::price($r->getPriceWithVat()));
$result->setUrl($url);
$result->setPerex(substr(strip_tags($r->getDescription()), 0, 300));
$result->setRate($query->getHint($phrase));
$results[] = $result;
}
return $results;
}
}