-
-
Notifications
You must be signed in to change notification settings - Fork 107
/
Frontend.php
829 lines (694 loc) · 28.4 KB
/
Frontend.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
<?php
/*
* Isotope eCommerce for Contao Open Source CMS
*
* Copyright (C) 2009 - 2019 terminal42 gmbh & Isotope eCommerce Workgroup
*
* @link https://isotopeecommerce.org
* @license https://opensource.org/licenses/lgpl-3.0.html
*/
namespace Isotope;
use Contao\Controller;
use Haste\Input\Input;
use Isotope\EventListener\ChangeLanguageListener;
use Isotope\Frontend\ProductAction\CartAction;
use Isotope\Frontend\ProductAction\FavoriteAction;
use Isotope\Interfaces\IsotopeAttributeWithOptions;
use Isotope\Interfaces\IsotopeOrderableCollection;
use Isotope\Interfaces\IsotopePrice;
use Isotope\Interfaces\IsotopeProduct;
use Isotope\Interfaces\IsotopeProductCollection;
use Isotope\Model\Attribute;
use Isotope\Model\AttributeOption;
use Isotope\Model\Product;
use Isotope\Model\Product\Standard;
use Isotope\Model\ProductCollection\Cart;
use Isotope\Model\ProductCollection\Order;
use Isotope\Model\ProductCollectionSurcharge;
use Isotope\Model\TaxClass;
/**
* Class Isotope\Frontend
*
* Provide methods to handle Isotope front end components.
* @copyright Isotope eCommerce Workgroup 2009-2012
* @author Andreas Schempp <andreas.schempp@terminal42.ch>
* @author Fred Bliss <fred.bliss@intelligentspark.com>
* @author Christian de la Haye <service@delahaye.de>
* @author Yanick Witschi <yanick.witschi@terminal42.ch>
*/
class Frontend extends \Frontend
{
/**
* Cached reader page id's
* @var array
*/
protected static $arrReaderPageIds = array();
/**
* Get shipping and payment surcharges for given collection
*
* @param IsotopeProductCollection $objCollection
*
* @return ProductCollectionSurcharge[]
*/
public function findShippingAndPaymentSurcharges(IsotopeProductCollection $objCollection)
{
if (!$objCollection instanceof IsotopeOrderableCollection) {
\System::log('Product collection ID "' . $objCollection->getId() . '" is not orderable', __METHOD__, TL_ERROR);
return false;
}
// Do not add shipping and payment surcharge to cart,
// they should only appear in the order review
if ($objCollection instanceof Cart) {
return array();
}
$arrSurcharges = array();
if (($objSurcharge = $objCollection->getShippingSurcharge()) !== null) {
$arrSurcharges[] = $objSurcharge;
}
if (($objSurcharge = $objCollection->getPaymentSurcharge()) !== null) {
$arrSurcharges[] = $objSurcharge;
}
return $arrSurcharges;
}
/**
* Replace the current page with a reader page if applicable
*
* @param array $arrFragments
*
* @return array
*/
public function loadReaderPageFromUrl($arrFragments)
{
$strKey = 'product';
$strAlias = '';
// Find products alias. Can't use Input because they're not yet initialized
if ($GLOBALS['TL_CONFIG']['useAutoItem'] && \in_array($strKey, $GLOBALS['TL_AUTO_ITEM'], true)) {
$strKey = 'auto_item';
}
for ($i = 1, $c = \count($arrFragments); $i < $c; $i += 2) {
if ($arrFragments[$i] == $strKey) {
$strAlias = $arrFragments[$i + 1];
}
}
global $objIsotopeListPage;
$objIsotopeListPage = null;
if ($strAlias != '' && ($objPage = \PageModel::findPublishedByIdOrAlias($arrFragments[0])) !== null) {
// Check the URL and language of each page if there are multiple results
// see Contao's index.php
if ($objPage !== null && $objPage->count() > 1) {
$objNewPage = null;
$arrPages = array();
// Order by domain and language
/** @var \PageModel $objCurrentPage */
foreach ($objPage as $objCurrentPage) {
$objCurrentPage->loadDetails();
$domain = $objCurrentPage->domain ? : '*';
$arrPages[$domain][$objCurrentPage->rootLanguage] = $objCurrentPage;
// Also store the fallback language
if ($objCurrentPage->rootIsFallback) {
$arrPages[$domain]['*'] = $objCurrentPage;
}
}
$strHost = \Environment::get('host');
// Look for a root page whose domain name matches the host name
if (isset($arrPages[$strHost])) {
$arrLangs = $arrPages[$strHost];
} else {
$arrLangs = $arrPages['*']; // Empty domain
}
// Use the first result (see #4872)
if (!$GLOBALS['TL_CONFIG']['addLanguageToUrl']) {
$objNewPage = current($arrLangs);
} // Try to find a page matching the language parameter
elseif (($lang = \Input::get('language')) != '' && isset($arrLangs[$lang])) {
$objNewPage = $arrLangs[$lang];
}
// Store the page object
if (\is_object($objNewPage)) {
$objPage = $objNewPage;
}
}
if ($objPage->iso_setReaderJumpTo && ($objReader = $objPage->getRelated('iso_readerJumpTo')) !== null) {
/** @var \PageModel $objIsotopeListPage */
$objIsotopeListPage = $objPage->current();
$objIsotopeListPage->loadDetails();
$arrFragments[0] = ($objReader->alias ?: $objReader->id);
}
}
return $arrFragments;
}
/**
* Overrides the reader page
*
* @param \PageModel $objPage
*/
public function overrideReaderPage($objPage)
{
/** @var \PageModel $objIsotopeListPage */
global $objIsotopeListPage;
if (null !== $objIsotopeListPage) {
$originalPageId = $objPage->id;
$arrTrail = $objIsotopeListPage->trail;
$arrTrail[] = $originalPageId;
$objPage->id = $objIsotopeListPage->id;
$objPage->pid = $objIsotopeListPage->pid;
$objPage->alias = $objIsotopeListPage->alias;
$objPage->trail = $arrTrail;
$objIsotopeListPage->pid = $originalPageId;
}
}
public function overrideArticles($pageId, $strColumn)
{
global $objPage;
global $objIsotopeListPage;
if (!$objIsotopeListPage || $pageId === $objIsotopeListPage->pid) {
return false;
}
$objPage->id = $objIsotopeListPage->pid;
$articles = Controller::getFrontendModule(0, $strColumn);
$objPage->id = $objIsotopeListPage->id;
return $articles;
}
/**
* Inject the necessary scripts here upon the "modifyFrontendPage" hook.
* We don't use the generatePage hook here anymore as modules added via
* InsertTags will not get those scripts added. We also don't use a combination
* of both (e.g. use generatePage hook by default and use the modifyFrontendPage
* hook only if there are still $GLOBALS['AJAX_PRODUCTS'] because a simple
* str_replace on </body> is really not a performance issue. So we chose
* simplicity here.
*
* @param string $buffer
*
* @return string
*/
public function injectScripts($buffer)
{
$messages = Message::generate();
$hasProducts = !empty($GLOBALS['AJAX_PRODUCTS']) && \is_array($GLOBALS['AJAX_PRODUCTS']);
if ($messages === '' && !$hasProducts) {
return $buffer;
}
$template = new \FrontendTemplate('iso_scripts');
if ($hasProducts) {
$template->hasProducts = true;
$template->loadMessage = specialchars($GLOBALS['TL_LANG']['MSC']['loadingProductData']);
$template->products = json_encode($GLOBALS['AJAX_PRODUCTS']);
}
if ($messages !== '') {
$template->hasMessages = true;
$template->messages = str_replace(array("\n", "\r", "'"), array('', '', '\''), $messages);
}
return str_replace('</body>', $template->parse() . '</body>', $buffer);
}
/**
* Format surcharge prices
*
* @param ProductCollectionSurcharge[] $arrSurcharges
* @param string|null $currencyCode
*
* @return array
*/
public static function formatSurcharges($arrSurcharges, $currencyCode = null)
{
$i = 0;
$arrReturn = array();
foreach ($arrSurcharges as $k => $objSurcharge) {
$arrReturn[$k] = $objSurcharge->row();
$arrReturn[$k]['price'] = Isotope::formatPriceWithCurrency($objSurcharge->price, true, $currencyCode, $objSurcharge->applyRoundingIncrement);
$arrReturn[$k]['total_price'] = Isotope::formatPriceWithCurrency($objSurcharge->total_price, true, $currencyCode, $objSurcharge->applyRoundingIncrement);
$arrReturn[$k]['tax_free_total_price'] = Isotope::formatPriceWithCurrency($objSurcharge->tax_free_total_price, true, $currencyCode, $objSurcharge->applyRoundingIncrement);
$arrReturn[$k]['rowClass'] = trim('foot_' . (++$i) . ' ' . $objSurcharge->rowClass);
$arrReturn[$k]['tax_id'] = $objSurcharge->getTaxNumbers();
$arrReturn[$k]['raw'] = $objSurcharge->row();
$arrReturn[$k]['surcharge'] = $objSurcharge;
}
return $arrReturn;
}
/**
* Adds the product urls to the array so they get indexed when search index is rebuilt in the maintenance module
*
* @param array $arrPages Absolute page urls
* @param int $intRoot Root page id
* @param bool $blnIsSitemap True if it's a sitemap module call (= treat differently when page is protected etc.)
*
* @return array Extended array of absolute page urls
*/
public function addProductsToSearchIndex($arrPages, $intRoot = 0, $blnIsSitemap = false)
{
$t = \PageModel::getTable();
$time = \Date::floorToMinute();
$arrValue = array();
$arrColumn = array(
"$t.type='root'",
"$t.published='1'",
"($t.start='' OR $t.start<'$time')",
"($t.stop='' OR $t.stop>'" . ($time + 60) . "')"
);
if ($intRoot > 0) {
$arrColumn[] = "$t.id=?";
$arrValue[] = $intRoot;
}
$objRoots = \PageModel::findBy($arrColumn, $arrValue);
if (null !== $objRoots) {
foreach ($objRoots as $objRoot) {
$arrPageIds = \Database::getInstance()->getChildRecords($objRoot->id, $t, false);
$arrPageIds[] = $intRoot;
$objProducts = Product::findPublishedByCategories($arrPageIds);
if (null !== $objProducts) {
foreach ($objProducts as $objProduct) {
// Find the categories in the current root
$arrCategories = array_intersect($objProduct->getCategories(), $arrPageIds);
$intRemaining = \count($arrCategories);
foreach ($arrCategories as $intPage) {
$objPage = \PageModel::findByPk($intPage);
--$intRemaining;
// The target page does not exist
if ($objPage === null) {
continue;
}
// The target page has not been published
if (!$objPage->published
|| ($objPage->start != '' && $objPage->start > $time)
|| ($objPage->stop != '' && $objPage->stop < ($time + 60))
) {
continue;
}
// The target page is exempt from the sitemap
if ($blnIsSitemap && 'map_never' === $objPage->sitemap) {
continue;
}
// Do not generate a reader for the index page, except if it is the only one
if ($intRemaining > 0 && 'index' === $objPage->alias) {
continue;
}
// Generate the domain
$strDomain = ($objRoot->useSSL ? 'https://' : 'http://');
$strDomain .= ($objRoot->dns ?: \Environment::get('host')) . TL_PATH . '/';
// Pass root language to page object
$objPage->language = $objRoot->language;
$arrPages[] = $strDomain . $objProduct->generateUrl($objPage);
// Only take the first category because this is our primary one
// Having multiple reader pages in the sitemap XML would mean duplicate content
break;
}
}
}
}
}
return array_unique($arrPages);
}
/**
* save_callback for upload widget to store $_FILES data into the product
*
* @param mixed $varValue
* @param IsotopeProduct $objProduct
* @param \Widget $objWidget
*
* @return mixed
*
* @deprecated Deprecated since Isotope 2.4, to be removed in Isotope 3.0.
*/
public function saveUpload($varValue, IsotopeProduct $objProduct, \Widget $objWidget)
{
if (\is_array($_SESSION['FILES'][$objWidget->name])
&& $_SESSION['FILES'][$objWidget->name]['uploaded'] == '1'
&& $_SESSION['FILES'][$objWidget->name]['error'] == 0
) {
return $_SESSION['FILES'][$objWidget->name]['name'];
}
return $varValue;
}
/**
* Get postal codes from CSV and ranges
*
* @param string $strPostalCodes
*
* @return array
*/
public static function parsePostalCodes($strPostalCodes)
{
$arrCodes = array();
foreach (trimsplit(',', $strPostalCodes) as $strCode) {
$arrCode = trimsplit('-', $strCode);
// Ignore codes with more than 1 range
switch (\count($arrCode)) {
case 1:
$arrCodes[] = $arrCode[0];
break;
case 2:
$arrCodes = array_merge($arrCodes, range($arrCode[0], $arrCode[1]));
break;
}
}
return $arrCodes;
}
/**
* Store the current article ID so we know it for the product list
*
* @param \Database\Result $objRow
*/
public function storeCurrentArticle($objRow)
{
$GLOBALS['ISO_CONFIG']['current_article']['id'] = $objRow->id;
$GLOBALS['ISO_CONFIG']['current_article']['pid'] = $objRow->pid;
}
/**
* Return pages in the current root available to the member
* Necessary to check if a product is allowed in the current site and cache the value
*
* @param array $arrPages
* @param \MemberModel|\FrontendUser $objMember
*
* @return array
*/
public static function getPagesInCurrentRoot(array $arrPages, $objMember = null)
{
if (0 === \count($arrPages)) {
return $arrPages;
}
/** @var \PageModel $objPage */
global $objPage;
// $objPage not available, we don't know if the page is allowed
if (null === $objPage || $objPage == 0) {
return $arrPages;
}
static $arrAvailable = array();
static $arrUnavailable = array();
$intMember = 0;
$arrGroups = [];
if (null !== $objMember) {
$intMember = $objMember->id;
$arrGroups = deserialize($objMember->groups, true);
}
if (!isset($arrAvailable[$intMember])) {
$arrAvailable[$intMember] = array();
}
if (!isset($arrUnavailable[$intMember])) {
$arrUnavailable[$intMember] = array();
}
// Load remaining (not cached) pages.
foreach (array_diff($arrPages, $arrAvailable[$intMember], $arrUnavailable[$intMember]) as $intPage) {
$objPageDetails = \PageModel::findWithDetails($intPage);
// Page is not in the current root
if ($objPageDetails->rootId != $objPage->rootId) {
continue;
}
// Page is for guests only but we have a member
if ($objPageDetails->guests && $intMember > 0 && !$objPageDetails->protected) {
$arrUnavailable[$intMember][] = $intPage;
continue;
} elseif ($objPageDetails->protected) {
// Page is protected but we have no member
if ($intMember == 0) {
$arrUnavailable[$intMember][] = $intPage;
continue;
}
$arrPGroups = deserialize($objPageDetails->groups);
// Page is protected but has no groups
if (!\is_array($arrPGroups)) {
$arrUnavailable[$intMember][] = $intPage;
continue;
}
// Page groups do not match with member groups
if (\count(array_intersect($arrGroups, $arrPGroups)) == 0) {
$arrUnavailable[$intMember][] = $intPage;
continue;
}
}
$arrAvailable[$intMember][] = $intPage;
}
return array_intersect($arrPages, $arrAvailable[$intMember]);
}
/**
* Show product name in breadcrumb
*
* @param array $arrItems
*
* @return array
*/
public function addProductToBreadcrumb($arrItems)
{
/** @var \PageModel $objPage */
global $objPage;
if ($objPage->type === 'error_404'
|| $objPage->type === 'error_403'
|| !($alias = Input::getAutoItem('product', false, true))
|| ($objProduct = Product::findAvailableByIdOrAlias($alias)) === null
) {
return $arrItems;
}
global $objIsotopeListPage;
$last = \count($arrItems) - 1;
// If we have a reader page that is a level below the list, rename the last item (the reader) to the product title
if (null !== $objIsotopeListPage && $objPage->pid == $objIsotopeListPage->id) {
$arrItems[$last]['title'] = $this->prepareMetaDescription($objProduct->meta_title ? : $objProduct->name);
$arrItems[$last]['link'] = $objProduct->name;
} else {
$listPage = $objIsotopeListPage ?: $objPage;
// Replace the current page (if breadcrumb is insert tag, it would already be the product name)
$arrItems[$last] = array(
'isRoot' => false,
'isActive' => false,
'href' => $listPage->getFrontendUrl(),
'title' => specialchars($listPage->pageTitle ?: $listPage->title),
'link' => $listPage->title,
'data' => $listPage->row(),
'class' => ''
);
// Add a new item for the current product
$arrItems[] = array(
'isRoot' => false,
'isActive' => true,
'href' => $objProduct->generateUrl($objPage),
'title' => specialchars($this->prepareMetaDescription($objProduct->meta_title ? : $objProduct->name)),
'link' => $objProduct->name,
'data' => $objPage->row(),
);
}
return $arrItems;
}
/**
* Initialize environment (language, objPage) for a given order
*
* @param Order $objOrder
* @param string $strLanguage
*/
public static function loadOrderEnvironment(Order $objOrder, $strLanguage = null)
{
global $objPage;
$strLanguage = $strLanguage ?: $objOrder->language;
// Load page configuration
if ($objOrder->pageId > 0 && (null === $objPage || $objPage->id != $objOrder->pageId)) {
$objPage = \PageModel::findWithDetails($objOrder->pageId);
$objPage = static::loadPageConfig($objPage);
}
// Set the current system to the language when the user placed the order.
// This will result in correct e-mails and payment description.
$GLOBALS['TL_LANGUAGE'] = $strLanguage;
\System::loadLanguageFile('default', $strLanguage, true);
Isotope::setConfig($objOrder->getRelated('config_id'));
if (($objCart = $objOrder->getRelated('source_collection_id')) !== null && $objCart instanceof Cart) {
Isotope::setCart($objCart);
}
}
/**
* Load system configuration into page object
*
* @param \Database\Result|\PageModel $objPage
*
* @return \Database\Result
*/
public static function loadPageConfig($objPage)
{
// Use the global date format if none is set
if ($objPage->dateFormat == '') {
$objPage->dateFormat = $GLOBALS['TL_CONFIG']['dateFormat'];
}
if ($objPage->timeFormat == '') {
$objPage->timeFormat = $GLOBALS['TL_CONFIG']['timeFormat'];
}
if ($objPage->datimFormat == '') {
$objPage->datimFormat = $GLOBALS['TL_CONFIG']['datimFormat'];
}
// Set the admin e-mail address
if ($objPage->adminEmail != '') {
list($GLOBALS['TL_ADMIN_NAME'], $GLOBALS['TL_ADMIN_EMAIL']) = \StringUtil::splitFriendlyEmail($objPage->adminEmail);
} else {
list($GLOBALS['TL_ADMIN_NAME'], $GLOBALS['TL_ADMIN_EMAIL']) = \StringUtil::splitFriendlyEmail($GLOBALS['TL_CONFIG']['adminEmail']);
}
// Define the static URL constants
\define('TL_FILES_URL', ($objPage->staticFiles != '' && !$GLOBALS['TL_CONFIG']['debugMode']) ? $objPage->staticFiles . TL_PATH . '/' : '');
\define('TL_ASSETS_URL', ($objPage->staticPlugins != '' && !$GLOBALS['TL_CONFIG']['debugMode']) ? $objPage->staticPlugins . TL_PATH . '/' : '');
\define('TL_SCRIPT_URL', TL_ASSETS_URL);
\define('TL_PLUGINS_URL', TL_ASSETS_URL);
$objLayout = \Database::getInstance()->prepare("
SELECT l.*, t.templates
FROM tl_layout l
LEFT JOIN tl_theme t ON l.pid=t.id
WHERE l.id=?
ORDER BY l.id=? DESC
")->limit(1)->execute($objPage->layout, $objPage->layout);
if ($objLayout->numRows) {
// Get the page layout
$objPage->template = \strlen($objLayout->template) ? $objLayout->template : 'fe_page';
$objPage->templateGroup = $objLayout->templates;
// Store the output format
list($strFormat, $strVariant) = explode('_', $objLayout->doctype);
$objPage->outputFormat = $strFormat;
$objPage->outputVariant = $strVariant;
}
$GLOBALS['TL_LANGUAGE'] = $objPage->language;
return $objPage;
}
/**
* Adjust module and module id for certain payment and/or shipping modules
*
* @param \Isotope\PostSale $objPostsale
*/
public function setPostsaleModuleSettings(PostSale $objPostsale)
{
// Payment method "Payone"
$strParam = \Input::post('param');
if (strpos($strParam, 'paymentMethodPayone') !== false) {
$intId = (int) str_replace('paymentMethodPayone', '', $strParam);
$objPostsale->setModule('pay');
$objPostsale->setModuleId($intId);
}
}
/**
* Calculate price surcharge for attribute options
*
* @param float $fltPrice
* @param object $objSource
* @param string $strField
* @param int $intTaxClass
* @param array $arrOptions
*
* @return float
* @throws \Exception
*/
public function addOptionsPrice($fltPrice, $objSource, $strField, $intTaxClass, array $arrOptions)
{
$fltAmount = $fltPrice;
if ($objSource instanceof IsotopePrice
&& ($objProduct = $objSource->getRelated('pid')) instanceof IsotopeProduct
&& $objProduct->getType() !== null) {
/** @var IsotopeProduct|Standard $objProduct */
$arrAttributes = array_intersect(
Attribute::getPricedFields(),
array_merge(
$objProduct->getType()->getAttributes(),
$objProduct->getType()->getVariantAttributes()
)
);
foreach ($arrAttributes as $field) {
if (($objAttribute = $GLOBALS['TL_DCA']['tl_iso_product']['attributes'][$field]) !== null
&& $objAttribute instanceof IsotopeAttributeWithOptions
&& $objAttribute->canHavePrices()
&& ($objOptions = $objAttribute->getOptionsFromManager($objProduct)) !== null
) {
$value = $objAttribute->isCustomerDefined() ? $arrOptions[$field] : $objProduct->$field;
$value = deserialize($value, true);
/** @var AttributeOption $objOption */
foreach ($objOptions as $objOption) {
if (\in_array($objOption->id, $value)) {
$amount = $objOption->getAmount($fltPrice, 0);
$objTax = $objSource->getRelated('tax_class');
if ($objOption->isPercentage() || !$objTax instanceof TaxClass) {
$fltAmount += $amount;
continue;
}
if ('net_price' === $strField) {
$fltAmount += $objTax->calculateNetPrice($amount);
} elseif ('gross_price' === $strField) {
$fltAmount += $objTax->calculateGrossPrice($amount);
} else {
$fltAmount += $amount;
}
}
}
}
}
}
return $fltAmount;
}
/**
* Callback for add_to_cart button
*
* @param IsotopeProduct $objProduct
* @param array $arrConfig
*
* @deprecated Deprecated since Isotope 2.5
*/
public function addToCart(IsotopeProduct $objProduct, array $arrConfig = array())
{
$action = new CartAction();
$action->handleSubmit($objProduct, $arrConfig);
}
/**
* Callback for add_to_cart button if a product is being edited.
*
* @param IsotopeProduct $objProduct
* @param array $arrConfig
*
* @deprecated Deprecated since Isotope 2.5
*/
public function updateCart(IsotopeProduct $objProduct, array $arrConfig = array())
{
$action = new CartAction();
$action->handleSubmit($objProduct, $arrConfig);
}
/**
* Callback for toggle_favorites button
*
* @param IsotopeProduct $objProduct
* @param array $arrConfig
*
* @deprecated Deprecated since Isotope 2.5
*/
public function toggleFavorites(IsotopeProduct $objProduct, array $arrConfig = array())
{
$action = new FavoriteAction();
$action->handleSubmit($objProduct, $arrConfig);
}
/**
* Replaces Isotope specific InsertTags in Frontend
*
* @param string $strTag
*
* @return mixed
*
* @deprecated Deprecated since version 2.3, to be removed in 3.0. Use \Isotope\InsertTag::replace() instead.
*/
public function replaceIsotopeTags($strTag)
{
$callback = new InsertTag();
return $callback->replace($strTag);
}
/**
* Hook callback for changelanguage extension to support language switching on product reader page
*
* @param array $arrGet
*
* @return array
*
* @deprecated Deprecated since Isotope 2.4. See Isotope\EventListener\ChangeLanguageListener
*/
public function translateProductUrls($arrGet)
{
$listener = new ChangeLanguageListener();
return $listener->onTranslateUrlParameters($arrGet);
}
/**
* Return all error, confirmation and info messages as HTML string
*
* @return string
*
* @deprecated use Isotope\Message::generate
*/
public static function getIsotopeMessages()
{
return Message::generate();
}
}