Skip to content

Commit

Permalink
Merge pull request #614 from shopgate/PWA-1849-keep-shipping-selector
Browse files Browse the repository at this point in the history
Keep shipping costs selector
  • Loading branch information
devbucket committed Apr 9, 2019
2 parents ae64ac0 + a095d94 commit bd28322
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
17 changes: 16 additions & 1 deletion libraries/commerce/cart/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,26 @@ export const getGrandTotal = createSelector(
* Selects the shipping costs.
* @returns {Object}
*/
export const getShippingCosts = createSelector(
export const getShippingCost = createSelector(
getTotals,
totals => totals.find(total => total.type === CART_TOTALS_TYPE_SHIPPING) || null
);

/**
* Selects the summed up shipping costs of the cart.
* @returns {number}
*/
export const getShippingCosts = createSelector(
getShippingCost,
(shippingCost) => {
if (!shippingCost) {
return null;
}
const { amount = 0 } = shippingCost;
return amount;
}
);

/**
* Selects the tax value of the cart.
* @returns {Object}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { connect } from 'react-redux';
import { getShippingCosts } from '@shopgate/pwa-common-commerce/cart/selectors';
import { getShippingCost } from '@shopgate/pwa-common-commerce/cart/selectors';

/**
* Maps the contents of the state to the component props.
* @param {Object} state The current application state.
* @return {Object} The extended component props.
*/
const mapStateToProps = state => ({
shippingCost: getShippingCosts(state),
shippingCost: getShippingCost(state),
});

export default connect(mapStateToProps);
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { connect } from 'react-redux';
import { getShippingCosts } from '@shopgate/pwa-common-commerce/cart/selectors';
import { getShippingCost } from '@shopgate/pwa-common-commerce/cart/selectors';

/**
* Maps the contents of the state to the component props.
* @param {Object} state The current application state.
* @return {Object} The extended component props.
*/
const mapStateToProps = state => ({
shippingCost: getShippingCosts(state),
shippingCost: getShippingCost(state),
});

export default connect(mapStateToProps);

0 comments on commit bd28322

Please sign in to comment.