Skip to content

Commit b62107d

Browse files
committed
chore: remove products cart related functionalities and update tests
1 parent 3e4a73d commit b62107d

15 files changed

Lines changed: 21 additions & 1149 deletions

src/helpers.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -376,16 +376,6 @@ export default function Helpers(mpInstance) {
376376
}
377377
};
378378

379-
this.createProductStorageName = function(workspaceToken) {
380-
if (workspaceToken) {
381-
return (
382-
StorageNames.currentStorageProductsName + '_' + workspaceToken
383-
);
384-
} else {
385-
return StorageNames.currentStorageProductsName;
386-
}
387-
};
388-
389379
// TODO: Refactor SDK to directly use these methods
390380
// https://go.mparticle.com/work/SQDSDKS-5239
391381
// Utility Functions

src/identity.js

Lines changed: 8 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,7 @@ export default function Identity(mpInstance) {
12861286
* @class mParticle.Identity.getCurrentUser().getCart()
12871287
* @deprecated
12881288
*/
1289+
// eslint-disable-next-line no-unused-vars
12891290
this.mParticleUserCart = function(mpid) {
12901291
return {
12911292
/**
@@ -1295,66 +1296,11 @@ export default function Identity(mpInstance) {
12951296
* @param {Boolean} [logEvent] a boolean to log adding of the cart object. If blank, no logging occurs.
12961297
* @deprecated
12971298
*/
1299+
// eslint-disable-next-line no-unused-vars
12981300
add: function(product, logEvent) {
12991301
mpInstance.Logger.warning(
1300-
'Deprecated function Identity.getCurrentUser().getCart().add() will be removed in future releases'
1302+
'Deprecated function Identity.getCurrentUser().getCart().add()'
13011303
);
1302-
var allProducts, userProducts, arrayCopy;
1303-
1304-
arrayCopy = Array.isArray(product)
1305-
? product.slice()
1306-
: [product];
1307-
arrayCopy.forEach(function(product) {
1308-
product.Attributes = mpInstance._Helpers.sanitizeAttributes(
1309-
product.Attributes
1310-
);
1311-
});
1312-
1313-
if (mpInstance._Store.webviewBridgeEnabled) {
1314-
mpInstance._NativeSdkHelpers.sendToNative(
1315-
Constants.NativeSdkPaths.AddToCart,
1316-
JSON.stringify(arrayCopy)
1317-
);
1318-
} else {
1319-
mpInstance._SessionManager.resetSessionTimer();
1320-
1321-
userProducts = mpInstance._Persistence.getUserProductsFromLS(
1322-
mpid
1323-
);
1324-
1325-
userProducts = userProducts.concat(arrayCopy);
1326-
1327-
if (logEvent === true) {
1328-
mpInstance._Events.logProductActionEvent(
1329-
Types.ProductActionType.AddToCart,
1330-
arrayCopy
1331-
);
1332-
}
1333-
1334-
var productsForMemory = {};
1335-
productsForMemory[mpid] = { cp: userProducts };
1336-
1337-
if (
1338-
userProducts.length >
1339-
mpInstance._Store.SDKConfig.maxProducts
1340-
) {
1341-
mpInstance.Logger.verbose(
1342-
'The cart contains ' +
1343-
userProducts.length +
1344-
' items. Only ' +
1345-
mpInstance._Store.SDKConfig.maxProducts +
1346-
' can currently be saved in cookies.'
1347-
);
1348-
userProducts = userProducts.slice(
1349-
-mpInstance._Store.SDKConfig.maxProducts
1350-
);
1351-
}
1352-
1353-
allProducts = mpInstance._Persistence.getAllUserProductsFromLS();
1354-
allProducts[mpid].cp = userProducts;
1355-
1356-
mpInstance._Persistence.setCartProducts(allProducts);
1357-
}
13581304
},
13591305
/**
13601306
* Removes a cart product from the current user cart
@@ -1363,56 +1309,11 @@ export default function Identity(mpInstance) {
13631309
* @param {Boolean} [logEvent] a boolean to log adding of the cart object. If blank, no logging occurs.
13641310
* @deprecated
13651311
*/
1312+
// eslint-disable-next-line no-unused-vars
13661313
remove: function(product, logEvent) {
13671314
mpInstance.Logger.warning(
1368-
'Deprecated function Identity.getCurrentUser().getCart().remove() will be removed in future releases'
1315+
'Deprecated function Identity.getCurrentUser().getCart().remove()'
13691316
);
1370-
var allProducts,
1371-
userProducts,
1372-
cartIndex = -1,
1373-
cartItem = null;
1374-
1375-
if (mpInstance._Store.webviewBridgeEnabled) {
1376-
mpInstance._NativeSdkHelpers.sendToNative(
1377-
Constants.NativeSdkPaths.RemoveFromCart,
1378-
JSON.stringify(product)
1379-
);
1380-
} else {
1381-
mpInstance._SessionManager.resetSessionTimer();
1382-
1383-
userProducts = mpInstance._Persistence.getUserProductsFromLS(
1384-
mpid
1385-
);
1386-
1387-
if (userProducts) {
1388-
userProducts.forEach(function(cartProduct, i) {
1389-
if (cartProduct.Sku === product.Sku) {
1390-
cartIndex = i;
1391-
cartItem = cartProduct;
1392-
}
1393-
});
1394-
1395-
if (cartIndex > -1) {
1396-
userProducts.splice(cartIndex, 1);
1397-
1398-
if (logEvent === true) {
1399-
mpInstance._Events.logProductActionEvent(
1400-
Types.ProductActionType.RemoveFromCart,
1401-
cartItem
1402-
);
1403-
}
1404-
}
1405-
}
1406-
1407-
var productsForMemory = {};
1408-
productsForMemory[mpid] = { cp: userProducts };
1409-
1410-
allProducts = mpInstance._Persistence.getAllUserProductsFromLS();
1411-
1412-
allProducts[mpid].cp = userProducts;
1413-
1414-
mpInstance._Persistence.setCartProducts(allProducts);
1415-
}
14161317
},
14171318
/**
14181319
* Clears the user's cart
@@ -1421,31 +1322,8 @@ export default function Identity(mpInstance) {
14211322
*/
14221323
clear: function() {
14231324
mpInstance.Logger.warning(
1424-
'Deprecated function Identity.getCurrentUser().getCart().clear() will be removed in future releases'
1325+
'Deprecated function Identity.getCurrentUser().getCart().clear()'
14251326
);
1426-
1427-
var allProducts;
1428-
1429-
if (mpInstance._Store.webviewBridgeEnabled) {
1430-
mpInstance._NativeSdkHelpers.sendToNative(
1431-
Constants.NativeSdkPaths.ClearCart
1432-
);
1433-
} else {
1434-
mpInstance._SessionManager.resetSessionTimer();
1435-
allProducts = mpInstance._Persistence.getAllUserProductsFromLS();
1436-
1437-
if (
1438-
allProducts &&
1439-
allProducts[mpid] &&
1440-
allProducts[mpid].cp
1441-
) {
1442-
allProducts[mpid].cp = [];
1443-
1444-
allProducts[mpid].cp = [];
1445-
1446-
mpInstance._Persistence.setCartProducts(allProducts);
1447-
}
1448-
}
14491327
},
14501328
/**
14511329
* Returns all cart products
@@ -1455,9 +1333,9 @@ export default function Identity(mpInstance) {
14551333
*/
14561334
getCartProducts: function() {
14571335
mpInstance.Logger.warning(
1458-
'Deprecated function Identity.getCurrentUser().getCart().getCartProducts() will be removed in future releases'
1336+
'Deprecated function Identity.getCurrentUser().getCart().getCartProducts()'
14591337
);
1460-
return mpInstance._Persistence.getCartProducts(mpid);
1338+
return [];
14611339
},
14621340
};
14631341
};

src/mp-instance.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -706,16 +706,8 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
706706
*/
707707
add: function(product, logEventBoolean) {
708708
self.Logger.warning(
709-
'Deprecated function eCommerce.Cart.add() will be removed in future releases'
709+
'Deprecated function eCommerce.Cart.add()'
710710
);
711-
let mpid;
712-
const currentUser = self.Identity.getCurrentUser();
713-
if (currentUser) {
714-
mpid = currentUser.getMPID();
715-
}
716-
self._Identity
717-
.mParticleUserCart(mpid)
718-
.add(product, logEventBoolean);
719711
},
720712
/**
721713
* Removes a product from the cart
@@ -726,16 +718,8 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
726718
*/
727719
remove: function(product, logEventBoolean) {
728720
self.Logger.warning(
729-
'Deprecated function eCommerce.Cart.remove() will be removed in future releases'
721+
'Deprecated function eCommerce.Cart.remove()'
730722
);
731-
let mpid;
732-
const currentUser = self.Identity.getCurrentUser();
733-
if (currentUser) {
734-
mpid = currentUser.getMPID();
735-
}
736-
self._Identity
737-
.mParticleUserCart(mpid)
738-
.remove(product, logEventBoolean);
739723
},
740724
/**
741725
* Clears the cart
@@ -744,14 +728,8 @@ export default function mParticleInstance(this: IMParticleWebSDKInstance, instan
744728
*/
745729
clear: function() {
746730
self.Logger.warning(
747-
'Deprecated function eCommerce.Cart.clear() will be removed in future releases'
731+
'Deprecated function eCommerce.Cart.clear()'
748732
);
749-
let mpid;
750-
const currentUser = self.Identity.getCurrentUser();
751-
if (currentUser) {
752-
mpid = currentUser.getMPID();
753-
}
754-
self._Identity.mParticleUserCart(mpid).clear();
755733
},
756734
},
757735
/**

src/persistence.interfaces.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,8 @@ export interface IPersistence {
9999
useLocalStorage(): boolean;
100100
initializeStorage(): void;
101101
update(): void;
102-
storeProductsInMemory(products: Product[], mpid: MPID): void;
103102
storeDataInMemory(obj: IPersistenceMinified, currentMPID: MPID): void;
104103
determineLocalStorageAvailability(storage: Storage): boolean;
105-
getUserProductsFromLS(mpid: MPID): Product[];
106-
getAllUserProductsFromLS(): Product[];
107104
setLocalStorage(): void;
108105
getLocalStorage(): IPersistenceMinified | null;
109106
expireCookies(cookieName: string): void;
@@ -120,8 +117,6 @@ export interface IPersistence {
120117
decodePersistence(persistenceString: string): string;
121118
getCookieDomain(): string;
122119
getDomain(doc: string, locationHostname: string): string;
123-
getCartProducts(mpid: MPID): Product[];
124-
setCartProducts(allProducts: Product[]): void;
125120
saveUserCookieSyncDatesToPersistence(mpid: MPID, csd: CookieSyncDates): void;
126121
savePersistence(persistance: IPersistenceMinified): void;
127122
getPersistence(): IPersistenceMinified;

0 commit comments

Comments
 (0)