Skip to content
This repository has been archived by the owner on Dec 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #191 from mozilla/delete-price-history
Browse files Browse the repository at this point in the history
#145: Delete related prices when deleting a product.
  • Loading branch information
Osmose authored Oct 23, 2018
2 parents 4d2aa85 + 6e8351e commit f150e33
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/state/prices.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import orderBy from 'lodash.orderby';
import pt from 'prop-types';

import config from 'commerce/config';
import {ADD_PRODUCT, getProductIdFromExtracted} from 'commerce/state/products';
import {
ADD_PRODUCT,
getProduct,
getProductIdFromExtracted,
REMOVE_MARKED_PRODUCTS,
} from 'commerce/state/products';

// Types

Expand Down Expand Up @@ -125,6 +130,17 @@ export default function reducer(state = initialState(), action) {
};
}

// Delete related prices when deleting products.
case REMOVE_MARKED_PRODUCTS: {
return {
...state,
prices: state.prices.filter((price) => {
const product = getProduct(state, price.productId);
return product && !product.isDeleted;
}),
};
}

case ADD_PRICE_ALERT: {
// New alerts are active by default.
const newAlert = {
Expand Down
2 changes: 1 addition & 1 deletion src/state/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const extractedProductShape = pt.shape({

export const ADD_PRODUCT = 'commerce/products/ADD_PRODUCT'; // Used by price duck
const SET_DELETION_FLAG = 'commerce/products/SET_DELETION_FLAG';
const REMOVE_MARKED_PRODUCTS = 'commerce/products/REMOVE_MARKED_PRODUCTS';
export const REMOVE_MARKED_PRODUCTS = 'commerce/products/REMOVE_MARKED_PRODUCTS';

// Reducer

Expand Down

0 comments on commit f150e33

Please sign in to comment.