Skip to content

Commit

Permalink
merge 8.1.x into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu-rolland committed Feb 8, 2023
2 parents 82a3a4d + 46362be commit ad59c82
Show file tree
Hide file tree
Showing 316 changed files with 8,386 additions and 4,398 deletions.
2 changes: 1 addition & 1 deletion admin-dev/themes/new-theme/js/fos_js_routes.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const CombinationsMap = ProductMap.combinations;
export default class CombinationsList {
private readonly productId: number;

private readonly shopId: number;

private readonly eventEmitter: EventEmitter;

private readonly combinationManagerWidget: HTMLDivElement;
Expand Down Expand Up @@ -94,6 +96,7 @@ export default class CombinationsList {
private productAttributeGroups: Array<AttributeGroup>;

constructor(productId: number, productFormModel: ProductFormModel, shopId: number) {
this.shopId = shopId;
this.productId = productId;
this.productFormModel = productFormModel;
this.eventEmitter = window.prestashop.instance.eventEmitter;
Expand Down Expand Up @@ -181,6 +184,7 @@ export default class CombinationsList {
CombinationsMap.combinationsGeneratorContainer,
this.eventEmitter,
this.productId,
this.shopId,
);
this.combinationModalApp = initCombinationModal(
CombinationsMap.editModal,
Expand Down Expand Up @@ -227,7 +231,7 @@ export default class CombinationsList {

private async refreshCombinationList(): Promise<void> {
// Wait for product attributes to adapt rendering depending on their number
this.productAttributeGroups = await getProductAttributeGroups(this.productId);
this.productAttributeGroups = await getProductAttributeGroups(this.productId, this.shopId);

if (this.filtersApp) {
this.filtersApp = initFilters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
class="card-footer"
v-if="areCombinationsNotEmpty"
>
<p>{{ selectedCombinationId }}</p>
<pagination
:pagination-length="14"
:datas="combinationsList"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@
type: Number,
required: true,
},
shopId: {
type: Number,
required: true,
},
eventEmitter: {
type: Object,
required: true,
Expand Down Expand Up @@ -177,7 +181,7 @@
*/
async initAttributeGroups(): Promise<void> {
try {
this.attributeGroups = await getAllAttributeGroups();
this.attributeGroups = await getAllAttributeGroups(this.shopId);
window.prestaShopUiKit.init();
this.preLoading = false;
this.eventEmitter.emit(CombinationEvents.combinationGeneratorReady);
Expand Down Expand Up @@ -212,10 +216,8 @@
*/
async generateCombinations(): Promise<void> {
this.loading = true;
const data: Record<string, any> = {
attributes: {},
applyToAllShops: this.applyToAllShops ? 1 : 0,
};
const data: Record<string, any> = {attributes: {}};

Object.keys(this.selectedAttributeGroups).forEach((attributeGroupId) => {
data.attributes[attributeGroupId] = [];
this.selectedAttributeGroups[attributeGroupId].attributes.forEach(
Expand All @@ -226,7 +228,11 @@
});

try {
const response = await this.combinationsService.generateCombinations(this.productId, data);
const response = await this.combinationsService.generateCombinations(
this.productId,
this.applyToAllShops ? null : this.shopId,
data,
);
$.growl({
message: this.$t('generator.success', {
combinationsNb: response.combination_ids.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function initCombinationGenerator(
combinationGeneratorSelector: string,
eventEmitter: typeof EventEmitter,
productId: number,
shopId: number,
): App {
const container = <HTMLElement> document.querySelector(combinationGeneratorSelector);

Expand All @@ -45,6 +46,7 @@ export default function initCombinationGenerator(
const vueApp = createApp(CombinationGenerator, {
i18n,
productId,
shopId,
eventEmitter,
}).use(i18n);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import _ from 'lodash';
import ProductEventMap from '@pages/product/product-event-map';
import {EventEmitter} from 'events';
import ProductMap from '@pages/product/product-map';

const {$} = window;

Expand Down Expand Up @@ -56,6 +57,8 @@ export default class ProductPartialUpdater {

private $productFormCancelButton: JQuery;

private $productTypePreview: JQuery;

private initialData: Record<string, any>;

private listEditionMode: boolean = false;
Expand Down Expand Up @@ -88,6 +91,7 @@ export default class ProductPartialUpdater {
this.$productFormNewProductButton = $productFormNewProductButton;
this.$productFormGoToCatalogButton = $productFormGoToCatalogButton;
this.$productFormCancelButton = $productFormCancelButton;
this.$productTypePreview = $(ProductMap.productType.headerPreviewButton);
this.initialData = {};

this.watch();
Expand Down Expand Up @@ -233,20 +237,25 @@ export default class ProductPartialUpdater {
this.$productFormPreviewButton.addClass('disabled');
this.$productFormDuplicateButton.addClass('disabled');
this.$productFormNewProductButton.addClass('disabled');
this.$productTypePreview.off('click');
this.$productTypePreview.addClass('disabled');
} else if (updatedData === null) {
this.$productFormSubmitButton.prop('disabled', true);
this.$productFormCancelButton.addClass('disabled');
this.$productFormGoToCatalogButton.removeClass('disabled');
this.$productFormPreviewButton.removeClass('disabled');
this.$productFormDuplicateButton.removeClass('disabled');
this.$productFormNewProductButton.removeClass('disabled');
this.$productTypePreview.removeClass('disabled');
} else {
this.$productFormSubmitButton.prop('disabled', false);
this.$productFormCancelButton.removeClass('disabled');
this.$productFormGoToCatalogButton.addClass('disabled');
this.$productFormPreviewButton.addClass('disabled');
this.$productFormDuplicateButton.addClass('disabled');
this.$productFormNewProductButton.addClass('disabled');
this.$productTypePreview.off('click');
this.$productTypePreview.addClass('disabled');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,20 @@ import {AttributeGroup} from '@pages/product/types';
const router = new Router();
const {$} = window;

export const getProductAttributeGroups = async (productId: number): Promise<Array<AttributeGroup>> => $.get(router.generate('admin_products_attribute_groups', {
productId,
}));
export const getProductAttributeGroups = async (productId: number, shopId: number|null): Promise<Array<AttributeGroup>> => {
const routeParams = <Record<string, number>> {productId};

export const getAllAttributeGroups = async (): Promise<Array<AttributeGroup>> => $.get(router.generate('admin_all_attribute_groups'));
if (shopId) {
routeParams.shopId = shopId;
}

return $.get(router.generate('admin_products_attribute_groups', routeParams));
};

export const getAllAttributeGroups = async (shopId: number|null): Promise<Array<AttributeGroup>> => $.get(router.generate(
'admin_all_attribute_groups',
shopId ? {shopId} : {},
));

export default {
getProductAttributeGroups,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,18 @@ export default class CombinationsService {

/**
* @param {number} productId
* @param {number|null} shopId
* @param {Record<number, number[]>} data Attributes indexed by attributeGroupId { 1: [23, 34], 3: [45, 52]}
*/
generateCombinations(productId: number, data: Record<number, number[]>): JQuery.jqXHR {
generateCombinations(productId: number, shopId: number|null, data: Record<number, number[]>): JQuery.jqXHR {
const routeParams = <Record<string, number>> {productId};

if (shopId) {
routeParams.shopId = shopId;
}

return $.ajax({
url: this.router.generate('admin_products_combinations_generate', {
productId,
}),
url: this.router.generate('admin_products_combinations_generate', routeParams),
data,
method: 'POST',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ $product-page-padding-bottom: 80px !default;
color: $primary;
}
}

.product-type-preview.disabled {
color: $gray-500;
cursor: not-allowed;

&:hover {
color: $gray-500;
}
}
}

.product-header-details {
Expand Down
4 changes: 2 additions & 2 deletions classes/AttributeGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
*/
class AttributeGroupCore extends ObjectModel
{
/** @var string Name */
/** @var string|string[] Name */
public $name;
/** @var bool Whether the attribute group is a color group */
public $is_color_group;
/** @var int Position */
public $position;
/** @var string Group type */
public $group_type;
/** @var string Public Name */
/** @var string|string[] Public Name */
public $public_name;

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/ProductAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ProductAttributeCore extends ObjectModel
/** @var int Group id which attribute belongs */
public $id_attribute_group;

/** @var string Name */
/** @var string|string[] Name */
public $name;
/** @var string */
public $color;
Expand Down
8 changes: 1 addition & 7 deletions classes/QuickAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,6 @@ public function toggleNewWindow()
*/
private static function productPageV2Enabled(): bool
{
$multistoreFeature = SymfonyContainer::getInstance()->get('prestashop.adapter.multistore_feature');

return SymfonyContainer::getInstance()->get('prestashop.core.admin.feature_flag.repository')->isEnabled(
$multistoreFeature->isActive()
? FeatureFlagSettings::FEATURE_FLAG_PRODUCT_PAGE_V2_MULTI_SHOP
: FeatureFlagSettings::FEATURE_FLAG_PRODUCT_PAGE_V2
);
return SymfonyContainer::getInstance()->get('prestashop.core.admin.feature_flag.repository')->isEnabled(FeatureFlagSettings::FEATURE_FLAG_PRODUCT_PAGE_V2);
}
}
2 changes: 2 additions & 0 deletions classes/lang/KeysReference/FeatureFlagLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

// Product feature flag in 8.0
trans('New product page - Single store', 'Admin.Advparameters.Feature');
// Product feature flag in 8.1
trans('New product page', 'Admin.Advparameters.Feature');
trans('This page benefits from increased performance and includes new features such as a new combination management system.', 'Admin.Advparameters.Help');

// Product multi store feature flag in 8.0
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"symfony/property-access": "^4",
"symfony/psr-http-message-bridge": "^2.1",
"symfony/swiftmailer-bundle": "^3.1",
"symfony/symfony": "^4.4.49",
"symfony/symfony": "4.4.*",
"tecnickcom/tcpdf": "^6.2.12",
"tijsverkoyen/css-to-inline-styles": "^2.2",
"twig/twig": "^3.0"
Expand Down
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion controllers/admin/AdminImagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

use PrestaShop\PrestaShop\Core\FeatureFlag\FeatureFlagSettings;
use PrestaShop\PrestaShop\Core\Image\ImageFormatConfiguration;
use PrestaShopBundle\Entity\Repository\FeatureFlagRepository;

/**
* @property ImageType $object
Expand Down Expand Up @@ -96,7 +97,7 @@ public function init()
parent::init();

$this->canGenerateAvif = $this->get('PrestaShop\PrestaShop\Core\Image\AvifExtensionChecker')->isAvailable();
$this->isMultipleImageFormatFeatureEnabled = $this->get('prestashop.core.admin.feature_flag.repository')->isEnabled(FeatureFlagSettings::FEATURE_FLAG_MULTIPLE_IMAGE_FORMAT);
$this->isMultipleImageFormatFeatureEnabled = $this->get(FeatureFlagRepository::class)->isEnabled(FeatureFlagSettings::FEATURE_FLAG_MULTIPLE_IMAGE_FORMAT);
$this->imageFormatConfiguration = $this->get('PrestaShop\PrestaShop\Core\Image\ImageFormatConfiguration');

$fields = [
Expand Down
3 changes: 1 addition & 2 deletions install-dev/data/xml/feature_flag.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<field name="stability"/>
</fields>
<entities>
<feature_flag id="product_page_v2" name="product_page_v2" label_wording="New product page - Single store" label_domain="Admin.Advparameters.Feature" description_wording="This page benefits from increased performance and includes new features such as a new combination management system." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
<feature_flag id="product_page_v2_multi_shop" name="product_page_v2_multi_shop" label_wording="New product page - Multi store" label_domain="Admin.Advparameters.Feature" description_wording="Access the new product page, even in a multistore context. This is a work in progress and some features are not available." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
<feature_flag id="product_page_v2" name="product_page_v2" label_wording="New product page" label_domain="Admin.Advparameters.Feature" description_wording="This page benefits from increased performance and includes new features such as a new combination management system." description_domain="Admin.Advparameters.Help" state="1" stability="stable" />
<feature_flag id="attribute_group" name="attribute_group" label_wording="Attribute group" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable migrated attribute group page." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
<feature_flag id="authorization_server" name="authorization_server" label_wording="Authorization server" label_domain="Admin.Advparameters.Feature" description_wording="Enable or disable the authorization server page." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
<feature_flag id="cart_rule" name="cart_rule" label_wording="Cart rules" label_domain="Admin.Advparameters.Feature" description_wording="Enable / Disable the migrated cart rules page." description_domain="Admin.Advparameters.Help" state="0" stability="beta" />
Expand Down
Loading

0 comments on commit ad59c82

Please sign in to comment.