Skip to content

Commit 93046c4

Browse files
committed
5.2.2
1 parent 5cf305b commit 93046c4

File tree

20 files changed

+208
-22
lines changed

20 files changed

+208
-22
lines changed

README.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Phoca Cart is e-commerce extension - powerful shopping cart for Joomla! CMS. Pho
132132

133133
## Version (Joomla! 5.x)
134134

135-
5.2.1
135+
5.2.2
136136

137137

138138

admin/install/sql/mysql/install.utf8.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ CREATE TABLE IF NOT EXISTS `#__phocacart_specifications` (
379379
`title` varchar(255) NOT NULL DEFAULT '',
380380
`alias` varchar(255) NOT NULL DEFAULT '',
381381
`value` text,
382-
`alias_value` varchar(255) NOT NULL DEFAULT '',
382+
`alias_value` text,
383383

384384
`image` varchar(255) NOT NULL DEFAULT '',
385385
`image_medium` varchar(255) NOT NULL DEFAULT '',
@@ -1455,7 +1455,7 @@ CREATE TABLE IF NOT EXISTS `#__phocacart_logs` (
14551455
`title` varchar(255) NOT NULL DEFAULT '',
14561456
`alias` varchar(255) NOT NULL DEFAULT '',
14571457
`ip` varchar(46) NOT NULL default '',
1458-
`incoming_page` varchar(255) NOT NULL,
1458+
`incoming_page` text,
14591459
`description` text,
14601460
`published` tinyint(1) NOT NULL DEFAULT '0',
14611461
`checked_out` int unsigned,

admin/language/en-GB/en-GB.com_phocacart.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ COM_PHOCACART_ORDER_PAYMENT_PROCESSED_ADDITIONAL_INFO=""
1616
COM_PHOCACART_ORDER_PAYMENT_PROCESSED_DOWNLOADABLE_ITEMS_ADDITIONAL_INFO=""
1717
COM_PHOCACART_ORDER_PAYMENT_CANCELED_ADDITIONAL_INFO=""
1818

19+
;[5.2.2]
20+
COM_PHOCACART_BATCH_RELATED="Related products"
21+
COM_PHOCACART_BATCH_RELATED_HEADING="Related products"
22+
COM_PHOCACART_BATCH_RELATED_ADD="Add %s"
23+
COM_PHOCACART_BATCH_RELATED_REMOVE="Remove %s"
24+
COM_PHOCACART_TYPE_OR_SELECT_SOME_PRODUCTS="Type or select some products"
25+
1926
;[5.1.5]
2027
COM_PHOCACART_ATTR_TYPE_TEXT_SELECT="Text (Select)"
2128

admin/layouts/phocacart/form/field/item.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
$attr2 = '';
7171
$attr2 .= !empty($class) ? ' class="' . $class . '"' : '';
72-
$attr2 .= ' placeholder="' . $this->escape($hint ?: Text::_('JGLOBAL_TYPE_OR_SELECT_SOME_TAGS')) . '" ';
72+
$attr2 .= ' placeholder="' . $this->escape($hint ?: Text::_('COM_PHOCACART_TYPE_OR_SELECT_SOME_PRODUCTS')) . '" ';
7373
$attr2 .= $dataAttribute;
7474

7575
$attr2 .= ' remote-search';

admin/libraries/phocacart/log/log.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public static function add( $type = 0, $title = '', $typeid = 0, $description =
6363
$db = Factory::getDBO();
6464
$ip = $_SERVER["REMOTE_ADDR"];
6565
$incoming_page = htmlspecialchars($uri->toString());
66+
$incoming_page = substr($incoming_page, 0, 2048);
67+
6668
$userid = 0;
6769
if (isset($user->id) && (int)$user->id > 0) {
6870
$userid = $user->id;

admin/libraries/phocacart/related/related.php

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
*/
1111
defined('_JEXEC') or die();
1212
use Joomla\CMS\Factory;
13+
use Joomla\CMS\Form\Form;
14+
use Joomla\CMS\Language\Text;
1315
use Joomla\Database\DatabaseInterface;
16+
use Joomla\Utilities\ArrayHelper;
17+
use Phoca\PhocaCart\Container\Container;
1418
use Phoca\PhocaCart\ContentType\ContentTypeHelper;
1519
use Phoca\PhocaCart\I18n\I18nHelper;
1620

@@ -19,7 +23,7 @@ class PhocacartRelated
1923
public static function storeRelatedItemsById($relatedString, $productId)
2024
{
2125
if ((int)$productId > 0) {
22-
$db =Factory::getDBO();
26+
$db = Container::getDbo();
2327
$query = ' DELETE '
2428
.' FROM #__phocacart_product_related'
2529
. ' WHERE product_a = '. (int)$productId;
@@ -50,8 +54,7 @@ public static function storeRelatedItemsById($relatedString, $productId)
5054

5155
public static function copyRelatedItems(int $sourceProductId, int $destProductId): void
5256
{
53-
/** @var DatabaseInterface $db */
54-
$db = Factory::getContainer()->get(DatabaseInterface::class);
57+
$db = Container::getDbo();
5558
$query = 'INSERT INTO #__phocacart_product_related(related_type, product_a, product_b)'
5659
. 'SELECT related_type, ' . $destProductId . ', product_b FROM #__phocacart_product_related WHERE product_a = ' . $sourceProductId;
5760
$db->setQuery($query);
@@ -64,8 +67,7 @@ public static function storeRelatedItems(int $productId, ?array $related): void
6467
return;
6568
}
6669

67-
/** @var DatabaseInterface $db */
68-
$db = Factory::getContainer()->get(DatabaseInterface::class);
70+
$db = Container::getDbo();
6971

7072
$query = 'DELETE FROM #__phocacart_product_related WHERE product_a = '. $productId;
7173
$db->setQuery($query);
@@ -77,6 +79,10 @@ public static function storeRelatedItems(int $productId, ?array $related): void
7779
$related = array_values($related);
7880
$related = array_unique($related, SORT_REGULAR);
7981
foreach ($related as $index => $relatedItem) {
82+
if ($relatedItem['id'] == $productId) {
83+
continue;
84+
}
85+
8086
$values[] = '(' . $productId . ', ' . $relatedItem['id'] . ', ' . $relatedItem['related_type'] . ', ' . $index . ')';
8187
}
8288

@@ -87,6 +93,58 @@ public static function storeRelatedItems(int $productId, ?array $related): void
8793
}
8894
}
8995

96+
public static function addRelatedItems(int $productId, int $relatedType, array $related): void
97+
{
98+
if (!$productId) {
99+
return;
100+
}
101+
102+
if (!$related) {
103+
return;
104+
}
105+
ArrayHelper::toInteger($related);
106+
$related = array_unique($related, SORT_REGULAR);
107+
108+
$db = Container::getDbo();
109+
110+
$newRelated = $db->setQuery('SELECT product_b AS id, related_type FROM #__phocacart_product_related WHERE product_a = ' . $productId . ' ORDER BY ordering')->loadAssocList('id');
111+
foreach ($related as $relatedItem) {
112+
if ($relatedItem == $productId) {
113+
continue;
114+
}
115+
116+
if (array_key_exists($relatedItem, $newRelated)) {
117+
$newRelated[$relatedItem]['related_type'] = $relatedType;
118+
} else {
119+
$newRelated[] = ['id' => $relatedItem, 'related_type' => $relatedType];
120+
}
121+
}
122+
123+
self::storeRelatedItems($productId, $newRelated);
124+
}
125+
126+
public static function removeRelatedItems(int $productId, int $relatedType, array $related): void
127+
{
128+
if (!$productId) {
129+
return;
130+
}
131+
132+
if (!$related) {
133+
return;
134+
}
135+
ArrayHelper::toInteger($related);
136+
137+
$db = Container::getDbo();
138+
139+
$related = array_unique($related, SORT_REGULAR);
140+
141+
$query = 'DELETE FROM #__phocacart_product_related WHERE product_a = ' . $productId .
142+
' AND related_type = ' . $relatedType .
143+
' AND product_b IN (' . implode(',', $related) . ')';
144+
$db->setQuery($query);
145+
$db->execute();
146+
}
147+
90148
/*
91149
* Try to find the best menu link so we search for category which we are located
92150
* if we find the category, we use this, if not we use another if accessible, etc.
@@ -276,4 +334,47 @@ public static function correctProductId($productIdChange) {
276334
}
277335
return true;
278336
}
337+
338+
public static function prepareBatchForm(Form $form)
339+
{
340+
$relatedTypes = ContentTypeHelper::getContentTypes(ContentTypeHelper::ProductRelated);
341+
342+
if (!$relatedTypes) {
343+
return true;
344+
}
345+
346+
// Creating the dom
347+
$xml = new \DOMDocument('1.0', 'UTF-8');
348+
$fieldsNode = $xml->appendChild(new \DOMElement('form'))->appendChild(new \DOMElement('fields'));
349+
$fieldsNode->setAttribute('name', 'batch');
350+
$fieldsNode = $fieldsNode->appendChild(new \DOMElement('fields'));
351+
$fieldsNode->setAttribute('name', 'related');
352+
$fieldset = $fieldsNode->appendChild(new \DOMElement('fieldset'));
353+
$fieldset->setAttribute('name', 'params');
354+
355+
foreach ($relatedTypes as $relatedType) {
356+
try {
357+
$node = $fieldset->appendChild(new \DOMElement('field'));
358+
$node->setAttribute('name', 'add_' . $relatedType->id);
359+
$node->setAttribute('type', 'PhocaCartItem');
360+
$node->setAttribute('label', Text::sprintf('COM_PHOCACART_BATCH_RELATED_ADD', Text::_($relatedType->title)));
361+
$node->setAttribute('showon', '_related:1');
362+
$node->setAttribute('multiple', 'true');
363+
364+
$node = $fieldset->appendChild(new \DOMElement('field'));
365+
$node->setAttribute('name', 'remove_' . $relatedType->id);
366+
$node->setAttribute('type', 'PhocaCartItem');
367+
$node->setAttribute('label', Text::sprintf('COM_PHOCACART_BATCH_RELATED_REMOVE', Text::_($relatedType->title)));
368+
$node->setAttribute('showon', '_related:1');
369+
$node->setAttribute('multiple', 'true');
370+
}
371+
catch (\Exception $e) {
372+
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
373+
}
374+
}
375+
376+
$form->load($xml->saveXML());
377+
378+
return true;
379+
}
279380
}

admin/models/forms/batch_item.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,19 @@
215215
</fieldset>
216216
</fields>
217217

218+
<fields name="related">
219+
<fieldset name="basic">
220+
<field name="_related" type="list" class="form-select-color-state" filter="unset" label="COM_PHOCACART_BATCH_RELATED">
221+
<option value="">COM_PHOCACART_BATCH_NOCHANGE</option>
222+
<option value="1">COM_PHOCACART_BATCH_CHANGE</option>
223+
</field>
224+
</fieldset>
225+
226+
<fieldset name="params" addfieldpath="/administrator/components/com_phocacart/models/fields">
227+
<field name="_related_heading" type="note" showon="_related:1" class="bg-primary text-white p-2 fw-bold w-100" description="COM_PHOCACART_BATCH_RELATED_HEADING" />
228+
</fieldset>
229+
</fields>
230+
218231
<fields name="com_fields">
219232
<fieldset name="basic">
220233
<field name="_custom_fields" type="list" class="form-select-color-state" filter="unset" label="COM_PHOCACART_BATCH_CUSTOM_FIELDS">

admin/models/forms/phocacartpayment.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414

1515
<fieldset name="general" label="COM_PHOCACART_GENERAL_OPTIONS">
1616

17-
<field name="code" type="text" label="COM_PHOCACART_FIELD_SHIPPING_CODE_LABEL" description="COM_PHOCACART_FIELD_SHIPPING_CODE_DESC" />
17+
<field name="code" type="text" label="COM_PHOCACART_FIELD_PAYMENT_CODE_LABEL" description="COM_PHOCACART_FIELD_PAYMENT_CODE_DESC" />
1818

1919
<field name="calculation_type" type="list" default="0" label="COM_PHOCACART_FIELD_CALCULATION_TYPE_LABEL" description="COM_PHOCACART_FIELD_CALCULATION_TYPE_DESC">
2020
<option value="1">COM_PHOCACART_PERCENTAGE</option>
2121
<option value="0">COM_PHOCACART_FIXED_AMOUNT</option>
2222
</field>
2323

24-
<field name="cost" type="text" label="COM_PHOCACART_FIELD_COST_LABEL" description="COM_PHOCACART_FIELD_SHIPPING_COST_DESC" />
24+
<field name="cost" type="text" label="COM_PHOCACART_FIELD_COST_LABEL" description="COM_PHOCACART_FIELD_PAYMENT_COST_DESC" />
2525

26-
<field name="cost_additional" type="text" label="COM_PHOCACART_FIELD_ADDITIONAL_COSTS_SHIPPING_METHOD_LABEL" description="COM_PHOCACART_FIELD_ADDITIONAL_COSTS_SHIPPING_METHOD_DESC" />
26+
<field name="cost_additional" type="text" label="COM_PHOCACART_FIELD_ADDITIONAL_COSTS_PAYMENT_METHOD_LABEL" description="COM_PHOCACART_FIELD_ADDITIONAL_COSTS_PAYMENT_METHOD_DESC" />
2727

2828
<field name="tax_id" type="phocatax" label="COM_PHOCACART_FIELD_TAX_LABEL" description="COM_PHOCACART_FIELD_TAX_DESC" />
2929

admin/models/phocacartitem.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class PhocaCartCpModelPhocaCartItem extends AdminModel
8484
'pcf' => 'batchFeedOptions',
8585
'com_fields' => 'batchCustomFields',
8686
'parameters' => 'batchParameters',
87+
'related' => 'batchRelated',
8788
];
8889

8990
// public function __construct($config = [], MVCFactoryInterface $factory = null, FormFactoryInterface $formFactory = null)
@@ -2334,5 +2335,53 @@ protected function batchParameters($newValues, $pks, $contexts): bool
23342335

23352336
return true;
23362337
}
2338+
2339+
protected function batchRelated($newValues, $pks, $contexts): bool
2340+
{
2341+
$this->initBatch();
2342+
2343+
foreach ($pks as $pk) {
2344+
if ($this->user->authorise('core.edit', $contexts[$pk])) {
2345+
$this->table->reset();
2346+
$this->table->load($pk);
2347+
2348+
$event = new BeforeBatchEvent(
2349+
$this->event_before_batch,
2350+
['src' => $this->table, 'type' => 'related']
2351+
);
2352+
$this->dispatchEvent($event);
2353+
2354+
// Check the row.
2355+
if (!$this->table->check()) {
2356+
$this->setError($this->table->getError());
2357+
2358+
return false;
2359+
}
2360+
2361+
foreach ($newValues as $name => $relatedProducts) {
2362+
if ($name == '_related') {
2363+
continue;
2364+
}
2365+
2366+
list($operation, $relatedType) = explode('_', $name);
2367+
if ($operation == 'add') {
2368+
PhocacartRelated::addRelatedItems($pk, $relatedType, $relatedProducts);
2369+
} else {
2370+
PhocacartRelated::removeRelatedItems($pk, $relatedType, $relatedProducts);
2371+
}
2372+
}
2373+
} else {
2374+
$this->setError(Text::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
2375+
2376+
return false;
2377+
}
2378+
}
2379+
2380+
// Clean the cache
2381+
$this->cleanCache();
2382+
2383+
return true;
2384+
}
2385+
23372386
}
23382387

admin/models/phocacartitems.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ public function getBatchForm(): Form
362362

363363
PhocacartFields::prepareBatchForm('com_phocacart.phocacartitem', $form);
364364
PhocacartParameter::prepareBatchForm($form);
365+
PhocacartRelated::prepareBatchForm($form);
365366

366367
Dispatcher::dispatch(new Event\Feed\BatchForm('com_phocacart.phocacartitem', $form));
367368

0 commit comments

Comments
 (0)