Fix catalog offers

This commit is contained in:
Bill 2022-02-27 20:58:28 -05:00
parent 06bc3f238e
commit c7d3022ccb
5 changed files with 35 additions and 11 deletions

View File

@ -1,5 +1,6 @@
import { IFurnitureData } from '@nitrots/nitro-renderer'; import { GetProductOfferComposer, IFurnitureData } from '@nitrots/nitro-renderer';
import { GetProductDataForLocalization } from '../../../api'; import { GetProductDataForLocalization } from '../../../api';
import { SendMessageHook } from '../../../hooks';
import { ICatalogPage } from './ICatalogPage'; import { ICatalogPage } from './ICatalogPage';
import { IProduct } from './IProduct'; import { IProduct } from './IProduct';
import { IPurchasableOffer } from './IPurchasableOffer'; import { IPurchasableOffer } from './IPurchasableOffer';
@ -18,6 +19,11 @@ export class FurnitureOffer implements IPurchasableOffer
this._product = (new Product(this._furniData.type, this._furniData.id, this._furniData.customParams, 1, GetProductDataForLocalization(this._furniData.className), this._furniData) as IProduct); this._product = (new Product(this._furniData.type, this._furniData.id, this._furniData.customParams, 1, GetProductDataForLocalization(this._furniData.className), this._furniData) as IProduct);
} }
public activate(): void
{
SendMessageHook(new GetProductOfferComposer((this._furniData.rentOfferId > -1) ? this._furniData.rentOfferId : this._furniData.purchaseOfferId));
}
public get offerId(): number public get offerId(): number
{ {
return (this.isRentOffer) ? this._furniData.rentOfferId : this._furniData.purchaseOfferId; return (this.isRentOffer) ? this._furniData.rentOfferId : this._furniData.purchaseOfferId;
@ -107,4 +113,9 @@ export class FurnitureOffer implements IPurchasableOffer
{ {
return this._furniData.description; return this._furniData.description;
} }
public get isLazy(): boolean
{
return true;
}
} }

View File

@ -3,6 +3,7 @@ import { IProduct } from './IProduct';
export interface IPurchasableOffer export interface IPurchasableOffer
{ {
activate(): void;
clubLevel: number; clubLevel: number;
page: ICatalogPage; page: ICatalogPage;
offerId: number; offerId: number;
@ -19,5 +20,6 @@ export interface IPurchasableOffer
badgeCode: string; badgeCode: string;
localizationName: string; localizationName: string;
localizationDescription: string; localizationDescription: string;
isLazy: boolean;
products: IProduct[]; products: IProduct[];
} }

View File

@ -59,6 +59,11 @@ export class Offer implements IPurchasableOffer
} }
} }
public activate(): void
{
}
public get clubLevel(): number public get clubLevel(): number
{ {
return this._clubLevel; return this._clubLevel;
@ -160,6 +165,11 @@ export class Offer implements IPurchasableOffer
return LocalizeText(this._localizationId); return LocalizeText(this._localizationId);
} }
public get isLazy(): boolean
{
return false;
}
public get products(): IProduct[] public get products(): IProduct[]
{ {
return this._products; return this._products;

View File

@ -21,6 +21,10 @@ export const CatalogItemGridWidgetView: FC<CatalogItemGridWidgetViewProps> = pro
const selectOffer = (offer: IPurchasableOffer) => const selectOffer = (offer: IPurchasableOffer) =>
{ {
offer.activate();
if(offer.isLazy) return;
setCurrentOffer(offer); setCurrentOffer(offer);
if(offer.product && (offer.product.productType === ProductTypeEnum.WALL)) if(offer.product && (offer.product.productType === ProductTypeEnum.WALL))
@ -31,10 +35,7 @@ export const CatalogItemGridWidgetView: FC<CatalogItemGridWidgetViewProps> = pro
return ( return (
<AutoGrid columnCount={ columnCount } { ...rest }> <AutoGrid columnCount={ columnCount } { ...rest }>
{ currentPage.offers && (currentPage.offers.length > 0) && currentPage.offers.map((offer, index) => { currentPage.offers && (currentPage.offers.length > 0) && currentPage.offers.map((offer, index) => <CatalogGridOfferView key={ index } itemActive={ (currentOffer && (currentOffer.offerId === offer.offerId)) } offer={ offer } onClick={ event => selectOffer(offer) } />) }
{
return <CatalogGridOfferView key={ index } itemActive={ (currentOffer && (currentOffer.offerId === offer.offerId)) } offer={ offer } onClick={ event => selectOffer(offer) } />;
}) }
{ children } { children }
</AutoGrid> </AutoGrid>
); );

View File

@ -106,15 +106,15 @@ export const CatalogPurchaseWidgetView: FC<CatalogPurchaseWidgetViewProps> = pro
let pageId = currentOffer.page.pageId; let pageId = currentOffer.page.pageId;
if(pageId === -1) // if(pageId === -1)
{ // {
const nodes = getNodesByOfferId(currentOffer.offerId); // const nodes = getNodesByOfferId(currentOffer.offerId);
if(nodes) pageId = nodes[0].pageId; // if(nodes) pageId = nodes[0].pageId;
} // }
SendMessageHook(new PurchaseFromCatalogComposer(pageId, currentOffer.offerId, extraData, quantity)); SendMessageHook(new PurchaseFromCatalogComposer(pageId, currentOffer.offerId, extraData, quantity));
}, [ currentOffer, purchaseCallback, extraData, quantity, getNodesByOfferId ]); }, [ currentOffer, purchaseCallback, extraData, quantity ]);
useEffect(() => useEffect(() =>
{ {