Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update cart example #57

Merged
merged 1 commit into from
Mar 30, 2016
Merged

update cart example #57

merged 1 commit into from
Mar 30, 2016

Conversation

harisaurus
Copy link
Contributor

Updates cart example to add the following and to match SDK documentation:

  • persist cart
  • cart tab update: increment, show, hide
  • cart hide when items count = 0
  • update functions to use getters

please review: @minasmart

@harisaurus harisaurus changed the title [WIP] update cart example update cart example Mar 28, 2016
<!-- .cart-tab start -->
<button class="btn btn--cart-tab">
<div class="btn__counter"></div>
<svg xmlns="http://www.w3.org/2000/svg" class="icon-cart icon-cart--side" viewBox="0 0 25 25" enable-background="new 0 0 25 25"><g fill="#fff"><path d="M24.6 3.6c-.3-.4-.8-.6-1.3-.6h-18.4l-.1-.5c-.3-1.5-1.7-1.5-2.5-1.5h-1.3c-.6 0-1 .4-1 1s.4 1 1 1h1.8l3 13.6c.2 1.2 1.3 2.4 2.5 2.4h12.7c.6 0 1-.4 1-1s-.4-1-1-1h-12.7c-.2 0-.5-.4-.6-.8l-.2-1.2h12.6c1.3 0 2.3-1.4 2.5-2.4l2.4-7.4v-.2c.1-.5-.1-1-.4-1.4zm-4 8.5v.2c-.1.3-.4.8-.5.8h-13l-1.8-8.1h17.6l-2.3 7.1z"></path><circle cx="9" cy="22" r="2"></circle><circle cx="19" cy="22" r="2"></circle></g></svg>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this live in its own file maybe? Keep large blobs out of the index?

I don't feel strongly either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's such a small example that I think we should keep it all in the same place. Keeps the example as straight forward as possible

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@minasmart minasmart mentioned this pull request Mar 28, 2016
9 tasks
if (cart.lineItems.length > 0) {
var totalItems = cart.lineItems.reduce(function(total, item) {
return total + item.quantity;
}, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a note to move this work to the cart: #51

@minasmart
Copy link
Contributor

Couple small issues, then set sail! ⛵

@richgilbank
Copy link
Contributor

Let's expand these out a bit now that the context is all available from being open source. @Shopify/channels-fed can one of you take a look at this?
Background: this is the example for a cart, using the JS Buy SDK - it's styled to be similar to the Buy Button's embedded cart, but work sans-iframe. Browser support is aiming for IE9+, though CORS support is temporarily limited to IE10+.

@minasmart
Copy link
Contributor

IE9 CORS currently predicated by: https://github.com/Shopify/shopify/pull/68257

@@ -61,6 +61,14 @@ <h2 class="cart-title">Your cart</h2>
<!-- .cart end -->


<!-- .cart-tab start -->
<button class="btn btn--cart-tab">
<div class="btn__counter"></div>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically only phrasing content can live inside a button, which means this would need to be a span instead of a div. I’ve never seen it cause an actual problem, but if switching to span with display: block doesn’t cause issues it may be safer.

@nwtn
Copy link

nwtn commented Mar 29, 2016

looks good to me, though this crazy js-buy stuff is all new to me.

@harisaurus harisaurus force-pushed the cart-example-with-variants branch 3 times, most recently from 76df237 to 33f282b Compare March 29, 2016 20:22
@harisaurus
Copy link
Contributor Author

@minasmart ready to go. @nwtn thanks for the review, homie

cart = newCart;
});
var cartLineItemCount;
if(localStorage.lastCartId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always use getItem and setItem

@minasmart
Copy link
Contributor

👍 just that one thing about using localStorage getters and setters. I'd like to have tests for this at some point and getters and setters let us stub native behaviours.

@harisaurus
Copy link
Contributor Author

Updated all localStorage stuff to use getters and setters.

var $cartLineItems = cart.lineItems.map(function (lineItem, index) {
var $lineItemTemplate = $(lineItemEmptyTemplate);
var itemImage = lineItem.image.src;
$lineItemTemplate.find('.cart-item__img').css('background-image', 'url(' + itemImage + ')');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you avoiding using a templating system here for any reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just trying to keep the example as simple and small as possible. The focus of the example is meant to be the interactions with the SDK, so I didn't want to add in anything fancy with templating. I'm open to hearing other options though - whatever makes the example as simple and digestible as possible.

@richgilbank thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just chatted with tyler in person - verdict was that it makes sense to not add an additional dependency for an example.

@harisaurus harisaurus merged commit a5a3b90 into master Mar 30, 2016
@harisaurus harisaurus deleted the cart-example-with-variants branch March 30, 2016 15:55
@minasmart minasmart temporarily deployed to production April 28, 2016 02:20 Inactive
mikkoh pushed a commit that referenced this pull request Oct 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants