-
Notifications
You must be signed in to change notification settings - Fork 220
Conversation
@senadir is this ready for review? I see it's in the Review/QA pipeline and it has the Needs review tag but it's a draft PR. |
@Aljullu yes and no, while it doesn’t link the option source to wcSettings yet, I would love if you can review the settings boilerplate in general see
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #1488 I'm not yet fully sure how we should wrap or present those settings or how to handle global default values, so until we finish the discussion in #1488 I'm keeping this a draft.
Sorry, I missed that comment, initially. 😅
I think we can work on that in a follow-up so this PR is not blocked by that. That will make the block to invalidate if we change the attributes, but as long as we fix #1488 before release we shouldn't bother about it.
The PR is looking great, just some comments:
-
I wonder if we should take the chance to make both settings positive, so instead of Hide shipping costs it's Shipping costs:
-
Looking at the old Cart, the string (change address) seems to be part of the Shipping Calculator, so it should be visible/hidden depending on the Shipping calculator setting instead of the Hide shipping costs. I'm ok fixing it in a follow-up, though. Since that will cause conflicts with Add ShippingCalculator component #1559 anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some code comments which may or may not be helpful. I think the best way to unblock this PR is to focus on:
- Persisting the settings in block attributes.
- Applying the settings in the front end render. I tested the front end and the settings aren't applying, though I'm guessing that's as intended (draft PR).
The next step would be correctly defaulting these attributes based on the woo core settings, which could be part of this PR or a follow up.
Might be worth focusing this PR on the happy case – site has shipping settings/zones all set up. I see in the design there's guidance for what to do when there are no shipping methods/zones, which could potentially be a follow up PR.
I think it's worth revisiting the wording of the options themselves (cc @garymurray @nerrad @pmcpinto), though possibly that can happen in a follow up PR. I thought I understood these options when initially reviewing the cart design, but looking at them now I'm confused :)
const Cart = () => { | ||
const currency = getCurrencyFromPriceResponse( cartTotals ); | ||
const totalRowsConfig = getTotalRowsConfig( cartTotals ); | ||
const Cart = ( { isShippingCalculatorEnabled, isShippingCostHidden } ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some whitespace issue that you're fixing here too? This diff is really big. (I reviewed with Hide whitespace changes
for now.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s mostly moving the getTotalRowsConfig
function to inside the Cart component since it depends on attributes based to Cart, mainly isShippingCostHidden
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that makes sense :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a slight preference for adding the param to getTotalRowsConfig
, so its dependencies are explicit, and less impact on the code. Not a blocker, happy for this to merge as is :)
(There's some fun merging coming with this and #1741 both close to merge!)
// @todo this are placeholders | ||
const onActivateCoupon = ( couponCode ) => { | ||
// eslint-disable-next-line no-console | ||
console.log( 'coupon activated: ' + couponCode ); | ||
}; | ||
const cartTotals = { | ||
const fetchedCartTotals = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this inline test data needed? We have previews/cart-items.js
which should contain a valid API response. If you need different data for testing, consider editing the preview data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was in the file when I started working on it so I didn’t feel like changing things, but I think you’re right, however the previews/cart-items
had only items values, not total.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. Could potentially add this test data to a new previews/cart
to match the store/cart
endpoint. But yep I see that I'm commenting on stuff that came in a previous PR, apologies :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can help you rebase if this was merged before your, or I can rebase mine, no problem
} | ||
const totalDiscount = parseInt( cartTotals.total_discount, 10 ); | ||
if ( totalDiscount > 0 ) { | ||
const totalDiscountTax = parseInt( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in this PR? Looks unrelated to shipping options to me :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was here when I started editing, it only shows up as edited since I moved the function from outside the component to inside it, the changes I made in assets/js/blocks/cart-checkout/cart/full-cart/index.js
are adding two props, and adding a condition to certain items according to those props.
To clarify what each setting does: Shipping calculator This one removes the shipping calculator from the cart completely, which makes the setting below it not needed, so if you disabled this, the setting below (Shipping costs) should be removed. Shipping costs If this setting is enabled, then the shipping costs are not shown automatically - the customer has to first enter and address to get the shipping costs to display. |
Definitely! I remember I brought this up once, double negation seems hard to comprehend cc @garymurray |
I addressed some comments here, and replied to other, this PR still needs some work, like showing shipping costs once an addressed is entred, once Albert merges his shipping calculator PR, we can try something like this. const [ showShippingCosts, setShowShippingCosts ] = useState( ! isShippingCostHidden );
useEffect( () => {
if ( isShippingCalculatorEnabled ) {
if ( isShippingCostHidden ) {
if ( shippingAddress ) {
return setShowShippingCosts( true );
}
} else {
return setShowShippingCosts( true );
}
}
return setShowShippingCosts( false );
}, [ isShippingCalculatorEnabled, isShippingCostHidden, shippingAddress ] ); |
Does this align with what you saying: So by default they both toggle on, if you toggle of the first one, the second one is removed automatically as it no longer applies, but you can optionally leave the first one enabled and disable the second one, which would require the customer to enter their address before seeing the shipping cost. |
If we want parity with the existing settings, this is not consistent with them. I found the best way to understand these options is to try the existing ones in the WooCommerce settings with the existing (not new) cart. I tested with a flat shipping cost (vs a geographical zone), so there may be some variations of behaviour depending on those. |
@nerrad yes, the way they are shown in the screenshot above is now counter to what is in Core currently: But the result is the same - the idea shared here was to see if it solved the double negation issue. The original design was as per the core settings - but in block format. |
The new commits hooks up the settings to Woo Core and render them in the frontend, it also rebases to the latest changes. We have a problem in which |
d2f3c61
to
f43c8e2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating this PR @senadir and hooking up the attributes to the store settings!
Some comments/questions:
-
It's not clear to me if we agreed to make both settings "positive", Gary's designs look like so but that's not implemented yet, right?
-
We also have the issue of the
(change address)
string. It belongs to the Shipping Calculator but currently it's hidden with the Shipping Costs toggle. As I said in my previous review, I think it's ok dealing with it in a follow-up, but we should either create a follow-up issue for it or not mark this PR as fixing Cart Block: Block settings for shipping options. #1488. Otherwise we will probably forget about it. 😅 -
I left a couple of small comments below in the code. 👇
We have a problem in which
withFeedback
would jump above the settings after the first change to settings, is this something you can look into @Aljullu
I'm unable to reproduce this. When does it happen?
'isShippingCalculatorEnabled', | ||
true | ||
); | ||
export const HIDE_SHIPPING_COST = getSetting( 'isShippingCostHidden', false ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should name these constants IS_SHIPPING_CALCULATOR_ENABLED
and IS_SHIPPING_COST_HIDDEN
, that would keep them consistent with the settings and make it clear they are booleans.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, let's use the same convention for naming these, so it's clear that they are a value (not an action) and boolean type.
@@ -37,14 +90,20 @@ const CartEditor = ( { className } ) => { | |||
] } | |||
defaultView={ 'full' } | |||
render={ ( currentView ) => ( | |||
<Fragment> | |||
<> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have any preference, but we are always explicitly writing Fragment
in tags. Should we keep it consistent? We could even add an eslint rule for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a preference for fewer keystrokes and fewer imports, but If we're always using Fragment
then I can switch back to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, makes sense... We could open an issue and discuss it there, I just feel that keeping it consistent makes code easier to scan, whichever way we go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd vote for the more explicit <Fragment>
here, but this doesn't need to block the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know I'm contradicting myself 🙂 but in another PR we were discussing if the short syntax (<>
) would be better.
I created an issue to discuss/switch: #1761, this way we don't block current open PRs because of that.
As per Darren and Gary, I feel like parity with Woo Core is more important here, removing double negation could start from Woo Core and get bubbled to us later.
I don’t think I'm following, the current behavior will hide |
I think I didn't pull before re-testing it, sorry for the confusion @senadir! 🤦♂️
Yes, I could reproduce it now. It looks like the order inside
Oh ok, nvm. I was confused about what was the calculator and what were the costs. One thing that still confuses me: I assumed the |
Yeah, that’s part of the testing data, my main point of confusion is, should the API do this, or should the setting code be responsible for the total |
@senadir Is this awaiting further review, or revisions? There are some conflicts also. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The recent fixes look great, like the use of conventional filter_var
for the bool option, and decreased nesting with ShippingCalculatorOptions
factored out.
Side note: I see that getTotalRowsConfig
is inline in master now, using cartTotals
from closure (no param) but still passing param in call (const totalRowsConfig = getTotalRowsConfig( cartTotals );
). So that shouldn't block this PR, but we might want to tidy up cc @Aljullu :)
I'm still seeing the validation error issue, and a new issue on the front end.
Validation error
To reproduce:
- Add cart block to a page, save.
- Visit WooCommerce > Settings > Shipping settings page (
/wp-admin/admin.php?page=wc-settings&tab=shipping§ion=options
). - Change shipping options defaults e.g.
Enable the shipping calculator on the cart page
, clickSave Changes
. - Reopen editor for page with cart block - see validation error.
Front end error
The shipping options aren't working at all for me, I think there's an issue getting the props out of the data attributes:
To reproduce:
- Ensure you have some shipping options set up.
- Add cart block to a page.
- Enable
Shipping calculator
option (and disableHide shipping costs
). Should see shipping options in cart sidebar card. - Publish/update the page.
- View page on front end – shipping options aren't shown.
04c65ff
to
4bb114e
Compare
Okay, so the latest round of commits includes:
|
4bb114e
to
236538f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The settings code looks good bar one point (the display of the show shipping setting should not be tied to the calculator), but pre-approving.
We should log a follow up issue for handling these new options on the frontend views properly once we understand what they should do :)
); | ||
totalRowsConfig.push( { | ||
label: __( 'Shipping:', 'woo-gutenberg-products-block' ), | ||
value: DISPLAY_PRICES_INCLUDING_TAXES |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This value should be hidden if totals are hidden and there is no address yet, but can be a follow up if you want to log it.
} ) | ||
} | ||
/> | ||
{ isShippingCalculatorEnabled && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This option should be independent of the calculator option, so you can remove the above check.
Fixes #1488.
getTotalRowsConfig
insideFullCart
since it depends on an attribute passed from the above block, we can keep it out and just add an extra param togetTotalRowsConfig
.Screenshots