Skip to content

Commit 0ed5277

Browse files
release: fixes
- Fixed issue with multiple checked options not displaying as checked by default - Updated dependencies
2 parents 8caa440 + 16fef6c commit 0ed5277

File tree

6 files changed

+116
-12
lines changed

6 files changed

+116
-12
lines changed

classes/admin.class.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ function product_meta() {
212212
<?php endif; ?>
213213
</div>
214214
</div>
215+
<div id="tsdk_banner" class="ppom-banner"></div>
215216
<?php
216217
echo '<p>' . __( 'You can create different meta groups for different products.', 'woocommerce-product-addon' ) . '</p>';
217218
}
@@ -238,6 +239,14 @@ function product_meta() {
238239
// existing meta group tables show only ppom main page
239240
if ( $action != 'new' && $do_meta != 'edit' && $view != 'addons' && $view != 'changelog' ) {
240241
ppom_load_template( 'admin/existing-meta.php' );
242+
243+
// NOTE: Allow only for Tier 1 Plan or lower if license is present.
244+
$should_load_banner = NM_PersonalizedProduct::LICENSE_PLAN_1 >= NM_PersonalizedProduct::get_license_category( intval( apply_filters( 'product_ppom_license_plan', 0 ) ) );
245+
246+
if ( $should_load_banner ) {
247+
do_action( 'themeisle_sdk_load_banner', 'ppom' );
248+
}
249+
241250
}
242251

243252
echo '</div>';

composer.lock

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/ppom-admin.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,3 +1862,7 @@ header.ppom-modal-header {
18621862
.ppom-wrapper a.ppom-upsell-condition:hover{
18631863
text-decoration: none;
18641864
}
1865+
1866+
.ppom-banner:has(.tsdk-banner-cta) {
1867+
margin: 20px 0;
1868+
}

images/black-friday.jpg

90.1 KB
Loading

js/admin/ppom-admin.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,16 @@ jQuery(function($) {
134134
const formData = new FormData();
135135
const ppomFields = new URLSearchParams();
136136

137-
// NOTE: since the request is to big for small values of `max_input_vars`, we will send the PPOM fields as a single string.
138-
(new FormData(this)).forEach(( value, key) => {
139-
if ( key.startsWith('ppom[') && typeof value === 'string' ) {
140-
ppomFields.append( key, value );
137+
/*
138+
NOTE: since the request is to big for small values of `max_input_vars`, we will send the PPOM fields as a single string.
139+
140+
INFO: some parts of the code use `\r\n` as delimiter for arrays in textarea. `serializeArray` respect this convention while native JS Form value access sanitize it to just `\n`.
141+
*/
142+
$( this ).serializeArray().forEach(({ value, name }) => {
143+
if ( name.startsWith('ppom[') && typeof value === 'string' ) {
144+
ppomFields.append( name, value );
141145
} else {
142-
formData.append(key, value);
146+
formData.append(name, value);
143147
}
144148
});
145149

tests/e2e/specs/checkbox.spec.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { test, expect } from "@wordpress/e2e-test-utils-playwright";
5+
6+
import {
7+
addNewField,
8+
addNewOptionInModal,
9+
fillFieldNameAndId,
10+
fillOptionNameAndValue,
11+
pickFieldTypeInModal,
12+
saveFieldInModal,
13+
saveFields,
14+
} from "../utils";
15+
16+
const CHECKBOX_OPTIONS = {
17+
CHECKED_OPTION_1: 'yes',
18+
CHECKED_OPTION_2: 'no',
19+
UNCHECKED_OPTION_1: 'maybe'
20+
};
21+
22+
test.describe("Checkbox", () => {
23+
/***
24+
* Create a simple checkbox with 3 options. Two will be marked as checked by default. Check if the selection is respected on rendering.
25+
*/
26+
test("check default selected options", async ({ page, admin }) => {
27+
await admin.visitAdminPage("admin.php?page=ppom");
28+
29+
await page.getByRole("link", { name: "Add New Group" }).click();
30+
await page
31+
.getByRole("textbox")
32+
.fill("Default Value for Checkbox");
33+
34+
await addNewField(page);
35+
await pickFieldTypeInModal(page, "checkbox");
36+
37+
const modelId = 1;
38+
const fieldId = `checkbox_test`;
39+
40+
await fillFieldNameAndId(
41+
page,
42+
modelId,
43+
`Checkbox Default values`,
44+
fieldId,
45+
);
46+
47+
48+
await page.locator(`textarea[name="ppom\\[${modelId}\\]\\[checked\\]"]`)
49+
.fill(`${CHECKBOX_OPTIONS.CHECKED_OPTION_1}\r\n${CHECKBOX_OPTIONS.CHECKED_OPTION_2}`);
50+
51+
await page
52+
.locator(`#ppom_field_model_${modelId}`)
53+
.getByText("Add Options", { exact: true })
54+
.click();
55+
56+
await fillOptionNameAndValue(page, modelId, 0, CHECKBOX_OPTIONS.CHECKED_OPTION_1, CHECKBOX_OPTIONS.CHECKED_OPTION_1);
57+
await addNewOptionInModal(page, modelId);
58+
await fillOptionNameAndValue(page, modelId, 1, CHECKBOX_OPTIONS.CHECKED_OPTION_2, CHECKBOX_OPTIONS.CHECKED_OPTION_2);
59+
await addNewOptionInModal(page, modelId);
60+
await fillOptionNameAndValue(page, modelId, 2, CHECKBOX_OPTIONS.UNCHECKED_OPTION_1, CHECKBOX_OPTIONS.UNCHECKED_OPTION_1);
61+
await saveFieldInModal(page, modelId);
62+
63+
await saveFields(page);
64+
await page.waitForLoadState("networkidle");
65+
await page.reload();
66+
67+
await page.getByText("Attach to Products").click({ force: true });
68+
await page.waitForLoadState("networkidle");
69+
70+
const productSelector = page.locator(
71+
'select[name="ppom-attach-to-products\\[\\]"]',
72+
);
73+
await page.waitForLoadState("networkidle");
74+
75+
await productSelector.selectOption({ index: 0 });
76+
const selectedProductId = await productSelector.inputValue();
77+
await page.getByRole("button", { name: "Save", exact: true }).click();
78+
79+
await page.waitForLoadState("networkidle");
80+
await page.goto(`/?p=${selectedProductId}`);
81+
82+
await expect(page.locator(`input[name="ppom[fields][${fieldId}][]"][value="${CHECKBOX_OPTIONS.CHECKED_OPTION_1}"]`)).toBeChecked();
83+
await expect(page.locator(`input[name="ppom[fields][${fieldId}][]"][value="${CHECKBOX_OPTIONS.CHECKED_OPTION_2}"]`)).toBeChecked();
84+
await expect(page.locator(`input[name="ppom[fields][${fieldId}][]"][value="${CHECKBOX_OPTIONS.UNCHECKED_OPTION_1}"]`)).not.toBeChecked();
85+
});
86+
});

0 commit comments

Comments
 (0)