Skip to content

Commit c56fd65

Browse files
author
Leonid Vakulenko
committed
Shop-Script v.11.5.0
1 parent 1f1d49c commit c56fd65

33 files changed

+400
-72
lines changed

css/backend/products/ui/ui.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/backend/products/main/main.list.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,8 +2063,9 @@
20632063
this.search_items = [];
20642064
}
20652065
}
2066-
this.debounceSearch(q);
2066+
this.debouncedSearch(q);
20672067
} else {
2068+
// clear search
20682069
this.states.is_fetching = false;
20692070
if (this.search_timer) {
20702071
clearTimeout(this.search_timer);
@@ -2090,6 +2091,9 @@
20902091
},
20912092
empty_search_result: function() {
20922093
return !this.states.is_fetching && !!this.search_string.trim() && !this.search_items.length;
2094+
},
2095+
selected_tags: function() {
2096+
return this.items.filter(t => (t.is_locked || t.states.enabled)).reduce((obj, t) => (obj[t.id]=true,obj), {});
20932097
}
20942098
},
20952099
mounted: function () {
@@ -2175,6 +2179,7 @@
21752179
const params = new URLSearchParams(this.fetch_params);
21762180
$.get(`${that.urls["tags_get"]}&${params}`, (r) => {
21772181
if (r.status === 'ok' && Array.isArray(r.data.tags)) {
2182+
r.data.tags = r.data.tags.filter(t => !this.selected_tags[t.id]);
21782183
dfd.resolve(r.data);
21792184
this.fetch_params = r.data.params;
21802185
this.states.is_fetching = false;
@@ -2183,7 +2188,7 @@
21832188

21842189
return dfd.promise();
21852190
},
2186-
debounceSearch: function(q) {
2191+
debouncedSearch: function(q) {
21872192
this.fetch_params = { q };
21882193
this.states.is_fetching = true;
21892194
if (this.search_timer) {

js/backend/products/product/product.general.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2495,7 +2495,7 @@
24952495
$textarea.redactor("code.set", $textarea.val());
24962496
}
24972497
};
2498-
$.wa_shop_products.useComponentExperimentalAIToolbar({
2498+
$.wa_shop_products.useComponentAIToolbar({
24992499
$toolbar: that.$wrapper.find('.js-ai-generate-wrapper'),
25002500
productId: that.product.id,
25012501
onUpdate: (prop, product) => {

js/backend/products/product/product.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,18 +322,16 @@
322322
return new Page(options);
323323
};
324324

325-
$.wa_shop_products._experimentalAIAction = function ({ productId, onUpdate }) {
325+
$.wa_shop_products._waAIAction = function ({ productId, onUpdate }) {
326326
const $btn = $(this);
327327
if ($btn.prop('disabled')) {
328328
return false;
329329
}
330330

331331
$btn.prop('disabled', true);
332-
$btn.find('.icon').hide();
333-
const $loading = $('<span class="js-loading"><i class="fas fa-spinner fa-spin"></i></span>').prependTo($btn);
332+
$btn.find('.webasyst-magic-wand-ai').addClass('shimmer');
334333
const hideLoading = () => {
335-
$loading.remove();
336-
$btn.find('.icon').show();
334+
$btn.find('.webasyst-magic-wand-ai').removeClass('shimmer');
337335
$btn.prop('disabled', false);
338336
};
339337
const handleError = (r) => {
@@ -393,9 +391,9 @@
393391
});
394392
}
395393
};
396-
$.wa_shop_products.useComponentExperimentalAIToolbar = ({ $toolbar, productId, onUpdate }) => {
394+
$.wa_shop_products.useComponentAIToolbar = ({ $toolbar, productId, onUpdate }) => {
397395
$toolbar.find('.js-ai-generate-description').click(function() {
398-
$.wa_shop_products._experimentalAIAction.call(this, { productId, onUpdate });
396+
$.wa_shop_products._waAIAction.call(this, { productId, onUpdate });
399397
});
400398
};
401399

js/backend/products/product/product.seo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
mounted: function() {
171171
this.$el.dataset.updateProp = this.updateProp;
172172

173-
$.wa_shop_products.useComponentExperimentalAIToolbar({
173+
$.wa_shop_products.useComponentAIToolbar({
174174
$toolbar: $(this.$el),
175175
productId: that.product.id,
176176
onUpdate: (prop, product) => {

lib/actions/frontend/order/shopFrontendOrder.actions.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,31 @@ public function createAction()
178178
}
179179
$confirmation->postConfirm($saved_order['contact_id'], $contact_id);
180180

181+
if (
182+
ifset($data, 'result', 'auth', 'service_agreement', false)
183+
&& ifempty($config, 'customer', 'service_agreement', false)
184+
) {
185+
webasystHelper::logAgreementAcceptance(
186+
'service_agreement',
187+
ifset($config, 'customer', 'service_agreement_hint', ''),
188+
ifset($config, 'customer', 'service_agreement', 'notice'),
189+
ifset($order, 'contact_id', null),
190+
'shop'
191+
);
192+
}
193+
if (
194+
ifset($data, 'result', 'confirm', 'terms', false)
195+
&& ifempty($config, 'confirmation', 'terms', false)
196+
) {
197+
webasystHelper::logAgreementAcceptance(
198+
'terms',
199+
ifset($config, 'confirmation', 'terms_text', ''),
200+
'checkbox',
201+
ifset($order, 'contact_id', null),
202+
'checkout'
203+
);
204+
}
205+
181206
// Clear cart and checkout data
182207
// Remove everything from cart
183208
(new shopCart())->clear();

lib/actions/frontend/shopFrontendProductReviewsAdd.controller.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ public function execute()
6767
'review_id' => $id,
6868
'product_id' => $data['product_id']
6969
];
70+
71+
if ($data['service_agreement']) {
72+
webasystHelper::logAgreementAcceptance(
73+
'service_agreement',
74+
wa('shop')->getSetting('review_service_agreement_hint'),
75+
ifset($data, 'service_agreement', 'notice'),
76+
ifset($data, 'contact_id', null),
77+
'review'
78+
);
79+
}
80+
7081
$this->addImage($options);
7182
$this->logAction('product_review_add', $product['id']);
7283
}
@@ -157,6 +168,14 @@ private function getData($product_id)
157168
$text = waRequest::post('text', null, waRequest::TYPE_STRING_TRIM);
158169
$title = waRequest::post('title', null, waRequest::TYPE_STRING_TRIM);
159170

171+
$service_agreement = wa('shop')->getSetting('review_service_agreement');
172+
if (
173+
empty($service_agreement)
174+
|| ($service_agreement === 'checkbox' && !waRequest::post('service_agreement', 0, waRequest::TYPE_INT))
175+
) {
176+
$service_agreement = '';
177+
}
178+
160179
return array(
161180
'product_id' => $product_id,
162181
'parent_id' => $parent_id,
@@ -165,6 +184,7 @@ private function getData($product_id)
165184
'rate' => $rate && !$parent_id ? $rate : null,
166185
'datetime' => date('Y-m-d H:i:s'),
167186
'status' => $this->getStatus(),
187+
'service_agreement' => $service_agreement,
168188
'images_count' => count(waRequest::file('images')),
169189
) + $this->getContactData();
170190
}

lib/actions/prod/main/shopProdList.action.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,16 @@ public function execute()
8484
$this->static_categories_tree = $category_model->buildNestedTree($static_categories);
8585

8686
$filter = $active_filter->getFilter();
87-
$filter_options = $active_filter->getFilterOptions(['tags_limit' => 100]);
87+
$tags_include_ids = [];
88+
foreach ($filter['rules'] as $rule) {
89+
if ($rule['rule_type'] === 'tags') {
90+
$tags_include_ids[] = $rule['rule_params'];
91+
}
92+
}
93+
$filter_options = $active_filter->getFilterOptions([
94+
'tags_limit' => 100,
95+
'tags_include_ids' => $tags_include_ids
96+
]);
8897
$this->clearMissingRules($filter['rules'], $filter_options, $categories);
8998

9099
$sort_column_type = $presentation->getSortColumnType();
@@ -1149,7 +1158,7 @@ protected function getMassActions()
11491158
[
11501159
"id" => "ai_generate",
11511160
"name" => _w("AI descriptions & SEO"),
1152-
"icon" => '<i class="icon webasyst-ai"></i>',
1161+
"icon" => '<i class="icon webasyst-magic-wand-ai"></i>',
11531162
"action_url" => $wa_app_url."?module=prod&action=massAIGenerateDescriptionDialog",
11541163
"premium_is_required" => !shopLicensing::isPremium()
11551164
]

lib/classes/blockpage/shopProductButtonBlockType.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function render(siteBlockData $data, bool $is_backend, array $tmpl_vars=[
2323
public function getExampleBlockData()
2424
{
2525
$result = $this->getEmptyBlockData();
26-
$result->data = ['html' => _w('Add to cart'), 'goto' => 'cart', 'tag' => 'a', 'block_props' => ['margin-bottom' => "m-b-0", 'button-style' => "bg-brn-1 t-wht b-r-s", 'button-size' => 'inp-m p-l-13 p-r-13']];
26+
$result->data = ['html' => _w('Add to cart'), 'goto' => 'cart', 'tag' => 'a', 'block_props' => ['margin-bottom' => "m-b-0", 'button-style' => ['name' => "complementary", 'scheme' => 'complementary', 'value' => "btn-a", 'type' => 'palette'], 'button-size' => 'inp-m p-l-13 p-r-13']];
2727
return $result;
2828
}
2929

lib/classes/blockpage/shopProductInfoBlockType.class.php

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,56 @@ public function render(siteBlockData $data, bool $is_backend, array $tmpl_vars=[
1414
if ($tmpl_vars['product']['status'] < 0) {
1515
$data->data['additional']['html'] = _w('Unavailable for purchase');
1616
}
17+
1718
return parent::render($data, $is_backend, $tmpl_vars);
1819
}
1920

2021
public function additionalData(siteBlockData $data)
2122
{
2223
$hash = '';
23-
$fields = 'id,name,summary,images,price,status';
24+
$fields = 'id,name,summary,description,images,price,status,sku_stock,skus,compare_price';
2425
if (!empty($data->data['product_id'])) {
2526
$hash = 'id/'.$data->data['product_id'];
26-
}
27-
$products = (new shopProductsCollection($hash))->getProducts($fields, 0, 1);
28-
if (empty($products) || $hash == '') {
29-
$p = ['id' => null, 'sku_id' => null, 'skus' => [], 'sku_type' => '1', 'status' => '0','price' => _w('Product price'), 'name' => _w('Product name'), 'summary' => _w('Product description')];
30-
if (empty($products)) {
31-
$p['status'] = '-1';
27+
$prod_data = new shopProduct($data->data['product_id']);
28+
//
29+
$p = $prod_data->data;
30+
$p['skus'] = $prod_data->skus;
31+
32+
switch (ifset($data->data, 'info_type', 'name')) {
33+
case 'price':
34+
//$result['html'] = shop_currency($p['price'], ["unit" => $p['currency'], "in_currency" => $p['currency'], "format" => "price_wrapper"]);
35+
$result_html = wa_currency_html($p['price'], $p['currency']);
36+
break;
37+
case 'compare_price':
38+
$result_html = '<span style="text-decoration: line-through;">'.wa_currency_html($p['compare_price'], $p['currency']).'</span>';
39+
break;
40+
case 'description':
41+
$result_html = strip_tags($p['description']);
42+
break;
43+
case 'summary':
44+
$result_html = strip_tags($p['summary']);
45+
break;
46+
case 'stock':
47+
$result_html = strip_tags($this->getStockInfo($p['skus'][$p['sku_id']]['count']));
48+
break;
49+
case 'name':
50+
default:
51+
$result_html = htmlspecialchars($p['name']);
52+
break;
3253
}
54+
3355
} else {
34-
$p = reset($products);
35-
//unset($data->data['html']);
56+
$p = ['id' => null, 'sku_id' => null, 'skus' => [], 'sku_type' => '1', 'status' => '0','price' => _w('Product price'), 'name' => _w('Product name'), 'summary' => _w('Product description')];
57+
58+
$result_html = _w('Choose product');
3659
}
37-
38-
$data->data['product_id'] = $p['id'];
60+
//wa_dump($prod_data['skus']);
3961
$result = [
4062
'product' => $p,
4163
];
64+
$result['html'] = $result_html;
65+
4266

43-
switch (ifset($data->data, 'info_type', 'name')) {
44-
case 'price':
45-
$result['html'] = shop_currency($p['price']);
46-
break;
47-
case 'description':
48-
$result['html'] = strip_tags($p['summary']);
49-
break;
50-
case 'name':
51-
default:
52-
$result['html'] = htmlspecialchars($p['name']);
53-
break;
54-
}
5567
return $result;
5668
}
5769

@@ -119,4 +131,22 @@ public function getTypeId()
119131
{
120132
return 'shop.ProductInfo';
121133
}
134+
135+
public function getStockInfo($n=0)
136+
{
137+
$low=5;
138+
$critical=2;
139+
140+
if ($n > $low || $n === null)
141+
$result = '<span class="text-green">'._w("In stock").'</span>';
142+
elseif ($n > $critical)
143+
$result = '<span class="stock-low">'._w("Only %d left in stock", "Only %d left in stock", $n).'</span>';
144+
elseif ($n > 0)
145+
$result = '<span class="text-orange">'._w("Only %d left in stock", "Only %d left in stock", $n).'</span>';
146+
else
147+
$result = '<span class="stock-none">'._w("Out of stock").'</span>';
148+
149+
return $result;
150+
}
151+
122152
}

0 commit comments

Comments
 (0)