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

Allow shipping category on variants #4739

Merged

Conversation

tvdeyen
Copy link
Member

@tvdeyen tvdeyen commented Nov 23, 2022

Summary

Like with the tax category a variant could have a different shipping category.
Think of a digital vs. physical variant of the same product.

Size: L - Variants - Ruby Hoodie - Products 2022-11-23 18-21-12

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

  • I have written a thorough PR description.
  • I have kept my commits small and atomic.
  • I have used clear, explanatory commit messages.

The following are not always needed (cross them out if they are not):

  • I have added automated tests to cover my changes.
  • I have attached screenshots to demo visual changes.

@github-actions github-actions bot added changelog:solidus_backend Changes to the solidus_backend gem changelog:solidus_core Changes to the solidus_core gem labels Nov 23, 2022
@tvdeyen tvdeyen marked this pull request as draft November 23, 2022 17:37
@tvdeyen tvdeyen self-assigned this Nov 23, 2022
@tvdeyen tvdeyen force-pushed the allow-shipping-category-on-variants branch from 72249ed to 3e7b80b Compare November 23, 2022 19:00
@codecov
Copy link

codecov bot commented Nov 23, 2022

Codecov Report

Merging #4739 (3e7b80b) into master (d582f54) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 3e7b80b differs from pull request most recent head 8dd4c4c. Consider uploading reports for the commit 8dd4c4c to get more accurate results

@@           Coverage Diff           @@
##           master    #4739   +/-   ##
=======================================
  Coverage   86.14%   86.14%           
=======================================
  Files         578      578           
  Lines       14654    14661    +7     
=======================================
+ Hits        12623    12630    +7     
  Misses       2031     2031           
Impacted Files Coverage Δ
core/lib/spree/permitted_attributes.rb 100.00% <ø> (ø)
...app/controllers/spree/admin/variants_controller.rb 100.00% <100.00%> (ø)
core/app/models/spree/variant.rb 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@tvdeyen tvdeyen marked this pull request as ready for review November 23, 2022 22:22
@tvdeyen tvdeyen requested a review from a team November 23, 2022 22:24
Copy link
Contributor

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

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

Thanks! I think it makes sense, and I can't see it breaking any behavior ❤️

core/spec/models/spree/variant_spec.rb Outdated Show resolved Hide resolved
core/spec/models/spree/variant_spec.rb Outdated Show resolved Hide resolved
@waiting-for-dev waiting-for-dev added the type:enhancement Proposed or newly added feature label Nov 24, 2022
@tvdeyen tvdeyen force-pushed the allow-shipping-category-on-variants branch from 3e7b80b to 8dd4c4c Compare November 24, 2022 07:20
@tvdeyen
Copy link
Member Author

tvdeyen commented Nov 24, 2022

@waiting-for-dev addressed

@tvdeyen
Copy link
Member Author

tvdeyen commented Nov 24, 2022

@waiting-for-dev can you tell me why we have a bunch of unrelated CI fails?

@waiting-for-dev
Copy link
Contributor

@waiting-for-dev can you tell me why we have a bunch of unrelated CI fails?

I can't 🙂 Re-running CI

@waiting-for-dev
Copy link
Contributor

@tvdeyen, for some reason, tests are failing consistently. I don't understand why, as your changes don't seem related. However, #4741, submitted later, went through without problems. I thought that maybe it was because of the latter using Nebulab's pipeline, but I pushed another branch to this repo to run it with the solidusio pipeline, and tests also passed: https://github.com/solidusio/solidus/tree/testing_ci

@kennyadsl
Copy link
Member

One thing that comes to mind, related to API, is that we probably need also to update the fields of the resources in the configuration file and the corresponding REST API documentation. Not sure how related this is to test failures, though.

In the test results:

Running 1 projects(s) on node 2 / 3
- backend
Building: backend
Run: bundle exec rspec --format documentation --profile 10 --no-color -r rspec_junit_formatter --format RspecJunitFormatter -o /tmp/test-results/rspec/backend.xml
Configuration changed. Re-running migrations
rake db:reset VERBOSE=false
Database 'solidus_backend_test' does not exist
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

Column `shipping_category_id` on table `spree_variants` does not match column `id` on `spree_shipping_categories`, which has type `int(11)`. To resolve this issue, change the type of the `shipping_category_id` column on `spree_variants` to be :integer. (For example `t.integer :shipping_category_id`).
Original message: Mysql2::Error: Cannot add foreign key constraint
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:148:in `_query'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:148:in `block in query'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:147:in `handle_interrupt'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/mysql2-0.5.4/lib/mysql2/client.rb:147:in `query'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:632:in `block (2 levels) in raw_execute'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/dependencies/interlock.rb:41:in `permit_concurrent_loads'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:631:in `block in raw_execute'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract_adapter.rb:765:in `block in log'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract_adapter.rb:756:in `log'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:630:in `raw_execute'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/mysql/database_statements.rb:96:in `raw_execute'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/mysql/database_statements.rb:47:in `execute'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:1093:in `add_foreign_key'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:790:in `foreign_key'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:184:in `add_to'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:989:in `add_reference'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:932:in `block in method_missing'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:900:in `block in say_with_time'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:900:in `say_with_time'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:921:in `method_missing'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration/compatibility.rb:138:in `add_reference'
/home/circleci/solidus/core/db/migrate/20221123152807_add_shipping_category_to_spree_variants.rb:3:in `change'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:870:in `exec_migration'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:854:in `block (2 levels) in migrate'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:853:in `block in migrate'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:215:in `with_connection'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:852:in `migrate'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:1046:in `migrate'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:1360:in `block in execute_migration_in_transaction'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:1413:in `ddl_transaction'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:1359:in `execute_migration_in_transaction'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:1333:in `each'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:1333:in `migrate_without_lock'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:1282:in `block in migrate'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:1432:in `block in with_advisory_lock'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:215:in `with_connection'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:1447:in `with_advisory_lock_connection'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:1428:in `with_advisory_lock'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:1282:in `migrate'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:1117:in `up'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/active_record/migration.rb:1092:in `migrate'
/home/circleci/solidus/core/lib/spree/testing_support/dummy_app/rake_tasks.rb:45:in `block (3 levels) in <top (required)>'
/home/circleci/solidus/core/lib/spree/testing_support/dummy_app/rake_tasks.rb:40:in `each'
/home/circleci/solidus/core/lib/spree/testing_support/dummy_app/rake_tasks.rb:40:in `block (2 levels) in <top (required)>'
/home/circleci/solidus/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'

@tvdeyen tvdeyen force-pushed the allow-shipping-category-on-variants branch from 8dd4c4c to 37e2e69 Compare November 29, 2022 14:06
@tvdeyen
Copy link
Member Author

tvdeyen commented Nov 29, 2022

One thing that comes to mind, related to API, is that we probably need also to update the fields of the resources in the configuration file and the corresponding REST API documentation. Not sure how related this is to test failures, though.

In the test results:

Running 1 projects(s) on node 2 / 3
- backend
Building: backend
Run: bundle exec rspec --format documentation --profile 10 --no-color -r rspec_junit_formatter --format RspecJunitFormatter -o /tmp/test-results/rspec/backend.xml
Configuration changed. Re-running migrations
rake db:reset VERBOSE=false
Database 'solidus_backend_test' does not exist
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

Column `shipping_category_id` on table `spree_variants` does not match column `id` on `spree_shipping_categories`, which has type `int(11)`. To resolve this issue, change the type of the `shipping_category_id` column on `spree_variants` to be :integer. (For example `t.integer :shipping_category_id`).
Original message: Mysql2::Error: Cannot add foreign key constraint
...

That one is funny. IMO a Rails Bug. It tries to create a foreign key from a table with a bigint as primary key to a column that is integer (or the other way round). Thats a common rails mysql issue. I now use the current active record migration schema version for the migration file instead of just 5.2 (the default for our migrations). Hope this will fix it.

@tvdeyen
Copy link
Member Author

tvdeyen commented Nov 29, 2022

One thing that comes to mind, related to API, is that we probably need also to update the fields of the resources in the configuration file and the corresponding REST API documentation. Not sure how related this is to test failures, though.

@kennyadsl could you explain what needs to be done case of the API documentation? The tax_category is not listed on the variant_attributes in the api_configuration.rb either. The attribute has always been on the variant, but it was delegated to the product. API wise there should not be any change, or do I miss something?

@kennyadsl
Copy link
Member

@tvdeyen right now we have the shipping_category_id listed among the other product attributes, eg https://solidus.stoplight.io/docs/solidus/bc0d29264a088-create-product. We do not have it in the variant attributes, eg. https://solidus.stoplight.io/docs/solidus/681aa6cb75b1e-create-product-variant. If we allow people to change that via API, we should list it.

For the tax_category_id not being present in that configuration file, I think I was wrong. That file should configure the response attributes for those resources, not the payload we can attach to the requests.

Does it make sense?

@tvdeyen
Copy link
Member Author

tvdeyen commented Nov 29, 2022

@tvdeyen right now we have the shipping_category_id listed among the other product attributes, eg https://solidus.stoplight.io/docs/solidus/bc0d29264a088-create-product. We do not have it in the variant attributes, eg. https://solidus.stoplight.io/docs/solidus/681aa6cb75b1e-create-product-variant. If we allow people to change that via API, we should list it.

@kennyadsl How do I add something to the API documentation? I couldn't find anything in the source, Wiki or README. Do I have to log into stoplight.io?

@waiting-for-dev
Copy link
Contributor

@tvdeyen, look into the api/openapi/solidus-api.oas.yml file.

@github-actions github-actions bot added the changelog:solidus_api Changes to the solidus_api gem label Nov 30, 2022
@tvdeyen
Copy link
Member Author

tvdeyen commented Nov 30, 2022

@tvdeyen, look into the api/openapi/solidus-api.oas.yml file.

@waiting-for-dev thanks. I added the attribute. Hopefully into the correct place. I am new to OpenAPI schema, so bare with me.

/cc @kennyadsl

@kennyadsl
Copy link
Member

@waiting-for-dev thanks. I added the attribute. Hopefully into the correct place. I am new to OpenAPI schema, so bare with me.

That's very hard to change, actually. We still couldn't find a better system, though. Thanks Thomas!

@tvdeyen
Copy link
Member Author

tvdeyen commented Nov 30, 2022

@waiting-for-dev @kennyadsl the builds are still failing because of "Unable to locate package libvips". Any ideas?

@waiting-for-dev
Copy link
Contributor

@tvdeyen, you can now rebase from master to fix CI 🙂

We must not reserve a complete grid column for the checkbox.
Using the same look as on the product form.
@tvdeyen tvdeyen force-pushed the allow-shipping-category-on-variants branch from bcd2527 to 0af8385 Compare December 2, 2022 09:46
@tvdeyen tvdeyen force-pushed the allow-shipping-category-on-variants branch from 0af8385 to 45a0d3f Compare December 6, 2022 13:21
@tvdeyen
Copy link
Member Author

tvdeyen commented Dec 6, 2022

@tvdeyen, you can now rebase from master to fix CI 🙂

@waiting-for-dev I did. Thanks. Unfortunately it still fails:

undefined method `spree_api_key=' for Spree::LegacyUser

what seems to be very unrelated to my changes. Any idea?

@tvdeyen
Copy link
Member Author

tvdeyen commented Dec 6, 2022

Only the mysql specs, though.

@tvdeyen
Copy link
Member Author

tvdeyen commented Dec 6, 2022

Argh, still mysql does not like the foreign key

Column `shipping_category_id` on table `spree_variants` does not match column `id` on `spree_shipping_categories`, which has type `int(11)`. To resolve this issue, change the type of the `shipping_category_id` column on `spree_variants` to be :integer. (For example `t.integer :shipping_category_id`).
Original message: Mysql2::Error: Cannot add foreign key constraint

@waiting-for-dev I already added the Rails version to the migration in the hope of fixing this issue with a more recent schema version, but this didn't turned out to work as well. Are you ok with removing the foreign key again? There is probably more work necessary to support foreign keys in Solidus with mysql. Something I do not want to tackle in this PR.

Like with the tax category a variant could have a different shipping category.
Think of a digital vs. physical variant of the same product.
@tvdeyen tvdeyen force-pushed the allow-shipping-category-on-variants branch from 45a0d3f to 470b90a Compare December 6, 2022 14:15
@waiting-for-dev
Copy link
Contributor

@waiting-for-dev I already added the Rails version to the migration in the hope of fixing this issue with a more recent schema version, but this didn't turned out to work as well. Are you ok with removing the foreign key again? There is probably more work necessary to support foreign keys in Solidus with mysql. Something I do not want to tackle in this PR.

Absolutely.

@jarednorman
Copy link
Member

Fantastic work on this, @tvdeyen. This will benefit a number of our stores. 🙏🏻

@waiting-for-dev waiting-for-dev merged commit 14f7667 into solidusio:master Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_api Changes to the solidus_api gem changelog:solidus_backend Changes to the solidus_backend gem changelog:solidus_core Changes to the solidus_core gem type:enhancement Proposed or newly added feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants