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

Implement product options processors #20

Merged
merged 2 commits into from
Apr 17, 2020
Merged

Conversation

MinasMazar
Copy link
Contributor

Ref. #15

Shopify allows a maximum of three key, value options to define product
attributes (I don't know if premium shops permit more options)

We map these keys into into Spree::OptionType/OptionValue 

@MinasMazar MinasMazar changed the title Mm/product options Implement product options processors Apr 3, 2020
'Option1 Name',
'Option2 Name',
'Option3 Name'
).compact.reject { |t| t == 'Title' }
Copy link
Contributor

Choose a reason for hiding this comment

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

So we could have a title in options?
It would be nice a comment to explain or an explicit method to filter out that case (ex. reject_on_title)

option_type = option_type(variant.product, i)

v = Spree::OptionValue.find_or_initialize_by(
option_type: option_type,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest using a different name for this local variable (option_type) to avoid misunderstandings with the method name.

end

def option_type(product, index)
product.option_types.find_by(position: index + 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

A way to skip the find_by here could be to attach the option types to the context in OptionTypes processor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I totally agree! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I amend previous comment: this solution doesn't fit since each processor works on a row, so we have no reference to the product's option types because they're not replicated on every row, but they're defined in the first row only.

Copy link
Contributor

@blocknotes blocknotes left a comment

Choose a reason for hiding this comment

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

Simple and clean PR 👍
I added some optional points, but we can live without them if you prefer the current state.

Copy link
Member

@elia elia left a comment

Choose a reason for hiding this comment

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

Just needs a tiny correction to the first commit message and attached comment, except from that LGTM 👍

def option_types?
# NOTE: according to https://help.shopify.com/en/manual/products/import-export
# when `Option Name1` is equal to 'Default`, means that product has no variants.
(@data['Option1 Name'] != 'Title') && option_type_names.any?
Copy link
Member

Choose a reason for hiding this comment

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

I think there's something not right here, the commit description and the comment refer to "Default", the code uses "Title" and the official docs refer to "Title" and "Default Title" 😅

image

https://help.shopify.com/en/manual/products/import-export/using-csv#product-csv-file-format

Shopify allows a maximum of three key,value options to define product
attributes (I don't know if premium shop permits more options)

We map these keys into into Spree::OptionTypes

NOTE: according to https://help.shopify.com/en/manual/products/import-export
when `Option Name1` is equal to `Title`, means that product has no variants.
@elia elia dismissed blocknotes’s stale review April 17, 2020 13:33

Everything has been addressed

Shopify allows a maximum of three key,value options to define product
attributes (I don't know if premium shop permits more options)

We map these values into into Spree::OptionValue

NOTE: according to https://help.shopify.com/en/manual/products/import-export
when `Option Value1` is equal to 'Default Title`, means that product has no
variants.
@MinasMazar MinasMazar merged commit 5d9024a into master Apr 17, 2020
@MinasMazar MinasMazar deleted the mm/product-options branch April 17, 2020 15:15
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.

3 participants