Skip to content

Commit a0d7a9f

Browse files
giftcards
1 parent 4ae583b commit a0d7a9f

File tree

27 files changed

+1353
-94
lines changed

27 files changed

+1353
-94
lines changed

app/base/abstracts/Controllers/AdminPage.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ abstract class AdminPage extends BaseHtmlPage
3939

4040
const BACK_BTN = 'back-btn';
4141

42-
/**
43-
* @var string page title
44-
*/
45-
protected ?string $page_title = null;
46-
4742
/**
4843
* {@inheritdoc}
4944
*

app/base/abstracts/Controllers/BaseHtmlPage.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ abstract class BaseHtmlPage extends BasePage implements HtmlPageInterface
4747
{
4848
use PageTrait;
4949

50+
/**
51+
* @var string page title
52+
*/
53+
protected ?string $page_title = null;
54+
5055
/**
5156
* @var Template|null template object
5257
*/
@@ -460,4 +465,9 @@ protected function refreshPage(array $urlParams = []) : RedirectResponse
460465
{
461466
return $this->doRedirect($this->getControllerUrl() . (!empty($urlParams) ? '?' . http_build_query($urlParams) : ''));
462467
}
468+
469+
public function getPageTitle(): ?string
470+
{
471+
return $this->page_title;
472+
}
463473
}

app/base/blocks/BreadCrumbs.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function ($id) use ($homepageid, $locale) {
181181
* @var FrontendPage $currentPage
182182
*/
183183
$currentPage = static::getControllerByRewrite($rewrite, App::getInstance());
184-
$title = $currentPage->getRouteName();
184+
$title = $currentPage->getPageTitle() ?? $currentPage->getRouteName();
185185
}
186186

187187
if ($rewrite->getRoute() == '/page/' . $homepageid) {
@@ -270,9 +270,9 @@ function ($id) use ($homepageid, $locale) {
270270
'attributes' => [
271271
'class' => 'breadcrumb-link',
272272
'href' => $current_page->getRewrite()->getUrl(),
273-
'title' => $current_page->getRouteName(),
273+
'title' => $current_page->getPageTitle() ?? $current_page->getRouteName(),
274274
],
275-
'text' => $current_page->getRouteName(),
275+
'text' => $current_page->getPageTitle() ?? $current_page->getRouteName(),
276276
]]
277277
);
278278
} else {
@@ -283,9 +283,9 @@ function ($id) use ($homepageid, $locale) {
283283
'attributes' => [
284284
'class' => 'breadcrumb-link',
285285
'href' => $current_page->getControllerUrl(),
286-
'title' => $current_page->getRouteName(),
286+
'title' => $current_page->getPageTitle() ?? $current_page->getRouteName(),
287287
],
288-
'text' => $current_page->getRouteName(),
288+
'text' => $current_page->getPageTitle() ?? $current_page->getRouteName(),
289289
]]
290290
);
291291
}

app/base/commands/Generate/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ protected function getModelFileContents($className): string
387387
namespace App\\Site\\Models;
388388
389389
use App\\Base\\Abstracts\\Models\\FrontendModel;
390-
use ".str_replace('\\','\\\\', $this->interface).";
390+
use ".$this->interface.";
391391
use ".implode(";\nuse ", $this->traits).";
392392
use App\Base\GraphQl\GraphQLExport;
393393

app/base/commands/Search/Indexer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
6969
return Command::FAILURE;
7070
}
7171

72-
$classes = array_filter(ClassFinder::getClassesInNamespace(App::MODELS_NAMESPACE, ClassFinder::RECURSIVE_MODE), function($className) {
72+
$classes = array_merge(
73+
ClassFinder::getClassesInNamespace(App::MODELS_NAMESPACE, ClassFinder::RECURSIVE_MODE),
74+
ClassFinder::getClassesInNamespace(App::BASE_MODELS_NAMESPACE, ClassFinder::RECURSIVE_MODE)
75+
);
76+
77+
$classes = array_filter($classes, function($className) {
7378
return is_subclass_of($className, FrontendModel::class) && $this->containerCall([$className, 'isIndexable']);
7479
});
7580

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
<?php
2+
3+
/**
4+
* SiteBase
5+
* PHP Version 8.3
6+
*
7+
* @category CMS / Framework
8+
* @package Degami\Sitebase
9+
* @author Mirko De Grandis <degami@github.com>
10+
* @license MIT https://opensource.org/licenses/mit-license.php
11+
* @link https://github.com/degami/sitebase
12+
*/
13+
14+
namespace App\Base\Controllers\Admin\Commerce;
15+
16+
use Degami\Basics\Exceptions\BasicException;
17+
use DI\DependencyException;
18+
use DI\NotFoundException;
19+
use App\Base\Abstracts\Controllers\AdminManageProductsPage;
20+
use App\Base\Models\GiftCard;
21+
use Degami\PHPFormsApi as FAPI;
22+
use Phpfastcache\Exceptions\PhpfastcacheSimpleCacheException;
23+
use App\Site\Models\MediaElement;
24+
use App\Base\Models\TaxClass;
25+
use App\Site\Models\MediaElement as Media;
26+
27+
/**
28+
* "Gift Cards" Admin Page
29+
*/
30+
class GiftCards extends AdminManageProductsPage
31+
{
32+
/**
33+
* @var string page title
34+
*/
35+
protected ?string $page_title = 'Gift Cards';
36+
37+
/**
38+
* {@inheritdoc}
39+
*
40+
* @return string
41+
*/
42+
public static function getObjectClass(): string
43+
{
44+
return GiftCard::class;
45+
}
46+
47+
48+
/**
49+
* {@inheritdoc}
50+
*
51+
* @return array|null
52+
*/
53+
public static function getAdminPageLink() : array|null
54+
{
55+
return [
56+
'permission_name' => static::getAccessPermission(),
57+
'route_name' => static::getPageRouteName(),
58+
'icon' => 'gift',
59+
'text' => 'Gift Cards',
60+
'section' => 'commerce',
61+
'order' => 70,
62+
];
63+
}
64+
65+
/**
66+
* {@inheritdoc}
67+
*
68+
* @param FAPI\Form $form
69+
* @param array &$form_state
70+
* @return FAPI\Form
71+
* @throws BasicException
72+
* @throws DependencyException
73+
* @throws NotFoundException
74+
* @throws PhpfastcacheSimpleCacheException
75+
*/
76+
public function getFormDefinition(FAPI\Form $form, array &$form_state): FAPI\Form
77+
{
78+
$type = $this->getRequest()->query->get('action') ?? 'list';
79+
80+
/**
81+
* @var GiftCard $product
82+
*/
83+
$product = $this->getObject();
84+
85+
$form->addField('action', [
86+
'type' => 'value',
87+
'value' => $type,
88+
]);
89+
90+
switch ($type) {
91+
case 'edit':
92+
$this->addActionLink(
93+
'media-btn',
94+
'media-btn',
95+
$this->getHtmlRenderer()->getIcon('image') . ' ' . $this->getUtils()->translate('Media', locale: $this->getCurrentLocale()),
96+
$this->getUrl('crud.app.site.controllers.admin.json.downloadablemedia', ['id' => $this->getRequest()->query->get('product_id')]) . '?product_id=' . $this->getRequest()->query->get('product_id') . '&action=new',
97+
'btn btn-sm btn-light inToolSidePanel'
98+
);
99+
100+
case 'new':
101+
102+
$product_title = $product_content = $product_media = '';
103+
$product_price = 0.0;
104+
if ($product->isLoaded()) {
105+
$product_title = $product->title;
106+
$product_content = $product->content;
107+
$product_media = $product->media_id;
108+
$product_price = $product->price;
109+
}
110+
111+
$medias = ['' => ''];
112+
foreach (MediaElement::getCollection() as $media) {
113+
/** @var MediaElement $media */
114+
if ($media->isDirectory()) {
115+
comtinue:
116+
}
117+
$medias[$media->getId()] = $media->getFilename();
118+
}
119+
$tax_classes = ['' => '-- Select --'];
120+
foreach(TaxClass::getCollection() as $tax_class) {
121+
/** @var TaxClass $tax_class */
122+
$tax_classes[$tax_class->getId()] = $tax_class->getClassName();
123+
}
124+
125+
$form->addField('title', [
126+
'type' => 'textfield',
127+
'title' => 'Title',
128+
'default_value' => $product_title,
129+
'validate' => ['required'],
130+
])->addField('content', [
131+
'type' => 'tinymce',
132+
'title' => 'Content',
133+
'tinymce_options' => DEFAULT_TINYMCE_OPTIONS,
134+
'default_value' => $product_content,
135+
'rows' => 20,
136+
])->addField('media_id', [
137+
'type' => 'select',
138+
'title' => 'Media',
139+
'default_value' => $product_media,
140+
'options' => $medias,
141+
'validate' => ['required'],
142+
])->addField('price', [
143+
'type' => 'number',
144+
'title' => 'Price',
145+
'default_value' => $product_price,
146+
'min' => '0.00',
147+
'max' => '1000000.00',
148+
'step' => '0.01',
149+
'validate' => ['required'],
150+
])->addField('tax_class_id', [
151+
'type' => 'select',
152+
'title' => 'Tax Class',
153+
'default_value' => $product->getTaxClassId(),
154+
'options' => $tax_classes,
155+
'validate' => ['required'],
156+
]);
157+
158+
$this->addFrontendFormElements($form, $form_state);
159+
$this->addSeoFormElements($form, $form_state);
160+
161+
$this->addSubmitButton($form);
162+
163+
break;
164+
165+
case 'delete':
166+
$this->fillConfirmationForm('Do you confirm the deletion of the selected element?', $form);
167+
break;
168+
169+
case 'media_deassoc':
170+
$media = $this->containerCall([Media::class, 'load'], ['id' => $this->getRequest()->query->get('media_id')]);
171+
$form->addField('product_id', [
172+
'type' => 'hidden',
173+
'default_value' => $product->id,
174+
])->addField('media_id', [
175+
'type' => 'hidden',
176+
'default_value' => $media->id,
177+
])->addField('confirm', [
178+
'type' => 'markup',
179+
'value' => 'Do you confirm the disassociation of the "' . $product->title . '" product from the media ID: ' . $media->id . '?',
180+
'suffix' => '<br /><br />',
181+
])->addMarkup('<a class="btn btn-danger btn-sm" href="' . $this->getUrl('crud.app.site.controllers.admin.json.mediadownloadableproducts', ['id' => $media->id]) . '?media_id=' . $media->id . '&action=downloadable_product_deassoc">Cancel</a>');
182+
183+
$this->addSubmitButton($form, true);
184+
break;
185+
186+
}
187+
188+
return $form;
189+
}
190+
191+
/**
192+
* {@inheritdoc}
193+
*
194+
* @param FAPI\Form $form
195+
* @param array &$form_state
196+
* @return bool|string
197+
*/
198+
public function formValidate(FAPI\Form $form, &$form_state): bool|string
199+
{
200+
//$values = $form->values();
201+
// @todo : check if page language is in page website languages?
202+
return true;
203+
}
204+
205+
/**
206+
* {@inheritdoc}
207+
*
208+
* @param FAPI\Form $form
209+
* @param array &$form_state
210+
* @return mixed
211+
* @throws BasicException
212+
* @throws DependencyException
213+
* @throws NotFoundException
214+
*/
215+
public function formSubmitted(FAPI\Form $form, &$form_state): mixed
216+
{
217+
/**
218+
* @var GiftCard $product
219+
*/
220+
$product = $this->getObject();
221+
222+
$values = $form->values();
223+
224+
switch ($values['action']) {
225+
case 'new':
226+
227+
// intentional fall trough
228+
// no break
229+
case 'edit':
230+
231+
$product->setUrl($values['frontend']['url']);
232+
$product->setTitle($values['title']);
233+
$product->setLocale($values['frontend']['locale']);
234+
$product->setContent($values['content']);
235+
$product->setWebsiteId($values['frontend']['website_id']);
236+
$product->setMediaId($values['media_id']);
237+
$product->setPrice((float)$values['price']);
238+
$product->setTaxClassId($values['tax_class_id']);
239+
240+
$this->setAdminActionLogData($product->getChangedData());
241+
242+
$product->persist();
243+
244+
$this->addSuccessFlashMessage($this->getUtils()->translate("Product Saved."));
245+
break;
246+
case 'delete':
247+
$product->delete();
248+
249+
$this->setAdminActionLogData('Deleted product ' . $product->getId());
250+
251+
$this->addInfoFlashMessage($this->getUtils()->translate("Product Deleted."));
252+
253+
break;
254+
case 'media_deassoc':
255+
if ($values['media_id']) {
256+
$media = $this->containerCall([Media::class, 'load'], ['id' => $values['media_id']]);
257+
$product->removeMedia($media);
258+
}
259+
break;
260+
}
261+
262+
return $this->refreshPage();
263+
}
264+
}

app/base/controllers/Admin/Elasticsearch.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,12 @@ public function getTemplateData(): array
126126

127127
$tableContents = [];
128128

129-
$classes = array_filter(ClassFinder::getClassesInNamespace(App::MODELS_NAMESPACE, ClassFinder::RECURSIVE_MODE), fn($modelClass) => is_subclass_of($modelClass, FrontendModel::class));
129+
$classes = array_merge(
130+
ClassFinder::getClassesInNamespace(App::MODELS_NAMESPACE, ClassFinder::RECURSIVE_MODE),
131+
ClassFinder::getClassesInNamespace(App::BASE_MODELS_NAMESPACE, ClassFinder::RECURSIVE_MODE)
132+
);
133+
134+
$classes = array_filter($classes, fn($modelClass) => is_subclass_of($modelClass, FrontendModel::class));
130135
foreach ($classes as $className) {
131136
if (!$this->containerCall([$className, 'isIndexable'])) {
132137
continue;

0 commit comments

Comments
 (0)