Compare commits

..

271 Commits

Author SHA1 Message Date
David Cook
fd889133cb Enable master variants with associated order cycles
There's only 5 in UK prod. keeping them is easier than figuring out if it's safe to delete.

(cherry picked from commit 4bf65e330b)
2023-06-23 14:16:45 +10:00
David Cook
4ac3dda398 Delete stock_items for master variants
All variants have stock_items records, but master variants never use them, so these were always redundant.

(cherry picked from commit 2025a98f58)
2023-06-23 14:16:45 +10:00
Matt-Yorkley
9d5d269f1f Set master variants which are associated to line items to non-master
Line items which reference a master variant is a scenario that in theory shouldn't have been valid or even possible for at least 5-6 years, and these old bits of data in theory should have been cleaned up at the time those changes were made. But a couple of servers have some really old data that's not in a nice state.

Here we can just flip the is_master flag to false for those specific (legacy data) cases before deleting any other master variants, to keep the legacy line item data intact.

(cherry picked from commit c88799618f)
2023-06-23 14:16:45 +10:00
Matt-Yorkley
f4405775f6 Remove line items related to master variants
These shouldn't technically exist, but apparently they can be present if the dataset is old enough. They can trigger a foreign key violation if they are present when a master variant is deleted, so they need to be dropped if present.

(cherry picked from commit f9185ea56e)
2023-06-23 14:16:45 +10:00
Matt-Yorkley
3a38361857 Remove inventory units related to master variants
These shouldn't technically exist, but apparently they can be present if the dataset is old enough. They can trigger a foreign key violation if they are present when a master variant is deleted, so they need to be dropped if present.

(cherry picked from commit 6f5d3ceacc)
2023-06-23 14:16:45 +10:00
Matt-Yorkley
68b59ab7a6 Remove array syntax on new product form for product image
(cherry picked from commit 24aa55e053)
2023-06-23 14:16:45 +10:00
Matt-Yorkley
a56541216e Update ScopeVariantsForSearch logic to match both product and variant SKUs
(cherry picked from commit ae24b2d688)
2023-06-23 14:16:45 +10:00
Matt-Yorkley
05d9646f3e Blank out product SKU when cloning a product
This was effectively being done before for the product's sku (stored on the master variant) via the #duplicate_variant method, but now it needs to be done explicitly on the product in #duplicate_product

(cherry picked from commit 0f253bb2a0)
2023-06-23 14:16:45 +10:00
Matt-Yorkley
b1de64bf3e Remove unnecessary iterator
(cherry picked from commit 15000c7ed1)
2023-06-23 14:16:45 +10:00
Matt-Yorkley
e976cc6d95 Disable variant is_master column
(cherry picked from commit 733dd3c428)
2023-06-23 14:16:45 +10:00
Matt-Yorkley
9a89b22364 Remove master images data migration tests
(cherry picked from commit be72bbebb9)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
1b304e2aa4 Remove is_master from variant serializer
(cherry picked from commit fbd09869bb)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
48cdca59fd Remove superfluous method from products controller
(cherry picked from commit ced60d4382)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
9095abfed2 Delete master variants
(cherry picked from commit b59bdc75e9)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
aa9fd682d8 Remove is_master and not_master scopes
(cherry picked from commit 1daab8994d)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
5b73ccb213 Remove unused is_master references in tests
(cherry picked from commit 0703bb4583)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
dda3cfa58d Remove master variant validation conditionals
(cherry picked from commit 85059bfb26)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
9da649a296 Improve validation feedback on new variant page and add test coverage
(cherry picked from commit 8247dce2dc)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
2e53b9a0c6 Fix flaky spec: use milliseconds in cache service and remove sleep
(cherry picked from commit 618900767f)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
527e305e2f Set unit_value to true when cloning a product
This value doesn't get persisted, but it's presence is validated. The product's duplicated variants store the actual :unit_value attribute

(cherry picked from commit 1e36043a2e)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
89b59f97ee Reorganise associations, validations, scopes and callbacks for clarity
(cherry picked from commit 1922598d2d)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
26d3cffba3 Remove master variant from product
(cherry picked from commit 3ef7d2c9ff)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
86703bb545 Migrate first master variant image to product image
(cherry picked from commit 21cba0aa13)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
8e99f496ff Migrate product image from master variant to product
(cherry picked from commit 7dc1091bc2)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
2f2506e698 Migrate master variant :sku to product
(cherry picked from commit d8649fc9fb)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
7ef9c2f56a Stop storing unit_value and unit_description on master variant
(cherry picked from commit 6b9b5ea347)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
ee4402f751 Stop using master variant for storing :display_as value
(cherry picked from commit 8c0b8dad85)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
79a2d1228d Stop using master variant as a potential store for prices
(cherry picked from commit 1b06c20197)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
da3202460c Update old specs that rely on master variant instead of real variants
(cherry picked from commit 80a0138b48)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
75ccc5c72f Simplify product images delegation mess
(cherry picked from commit d4188da7c1)
2023-06-23 14:16:44 +10:00
Matt-Yorkley
aca72e6071 Remove dead code
(cherry picked from commit 42a5a48816)
2023-06-23 14:16:44 +10:00
Maikel Linke
2453084a6b Update translations 2023-06-16 14:02:47 +10:00
Maikel
39183547aa Merge pull request #11033 from openfoodfoundation/revert-10455-dependabot/bundler/redis-5.0.6
Revert "Fix `redis` and `hiredis-client` version requirements "
2023-06-16 13:42:55 +10:00
Maikel
24000b2ce3 Revert "Fix redis and hiredis-client version requirements " 2023-06-16 13:09:25 +10:00
Maikel
8e86f76278 Merge pull request #11018 from openfoodfoundation/dependabot/bundler/sidekiq-7.1.2
chore(deps): bump sidekiq from 7.1.1 to 7.1.2
2023-06-16 12:08:25 +10:00
Maikel
4a91c180a3 Merge pull request #11017 from openfoodfoundation/dependabot/bundler/ddtrace-1.12.1
chore(deps): bump ddtrace from 1.12.0 to 1.12.1
2023-06-16 11:14:10 +10:00
Maikel
d192024786 Merge pull request #11019 from filipefurtad0/flaky_cache_spec
Clears cache around examples
2023-06-16 11:12:24 +10:00
Maikel
ec7de516aa Merge pull request #11011 from openfoodfoundation/dependabot/bundler/aws-sdk-s3-1.124.0
chore(deps): bump aws-sdk-s3 from 1.123.1 to 1.124.0
2023-06-16 10:59:56 +10:00
David Cook
47745b5e49 Merge pull request #11004 from dacook/show-current-version
Show current version at bottom of admin dashboard
2023-06-16 09:26:00 +10:00
Matt-Yorkley
3301c7cabc Update stage.yml 2023-06-16 00:18:36 +01:00
David Cook
35d9837f24 Show current version at bottom of admin dashboard
With generic link to the releases page. We could provide a link to latest tag with `git describe --tags --abbrev=0`. But I thought it better to keep things simple.
2023-06-16 09:11:59 +10:00
Matt-Yorkley
436deb9797 Update stage.yml 2023-06-16 00:03:16 +01:00
Matt-Yorkley
57451f2639 Update stage.yml 2023-06-15 23:26:27 +01:00
Matt-Yorkley
d56ad66ab8 Update stage.yml 2023-06-15 20:57:40 +01:00
Matt-Yorkley
fc5a53ebd9 Update stage.yml 2023-06-15 20:53:20 +01:00
Matt-Yorkley
f27472106e Update stage.yml 2023-06-15 20:52:07 +01:00
Matt-Yorkley
5729e33f69 Merge pull request #11031 from Matt-Yorkley/deployment-workflow
Add workflow for deploying to staging
2023-06-15 20:40:10 +01:00
Matt-Yorkley
584f6297f5 Allow manual workflow triggers 2023-06-15 20:18:44 +01:00
Matt-Yorkley
12bf17e21e Add workflow for deploying to staging 2023-06-15 19:37:18 +01:00
Matt-Yorkley
7068df5d4b Merge pull request #10804 from Matt-Yorkley/public-images
Update ActiveStorage image processing
2023-06-15 15:49:11 +01:00
Konrad
7a10edff82 Merge pull request #10988 from jibees/10980-white-label-trix-bullets-and-numbers-are-displayed-outside-the-text-field
[White Label] Custom tab content editor: order and unordered list should have a margin-left set
2023-06-15 16:13:19 +02:00
Konrad
5c0db892e5 Merge pull request #10983 from jibees/10982-admin_style_v3-use-oidc-settings-instead-of-oidc-settings-in-navigation
[OIDC] Translate 'Enterprises' > 'OIDC Settings' tab title
2023-06-15 16:07:07 +02:00
filipefurtad0
598f69f42f Clears cache around examples
for specs testing cache
2023-06-15 11:28:01 +01:00
dependabot[bot]
ca5de6b0b2 chore(deps): bump sidekiq from 7.1.1 to 7.1.2
Bumps [sidekiq](https://github.com/sidekiq/sidekiq) from 7.1.1 to 7.1.2.
- [Changelog](https://github.com/sidekiq/sidekiq/blob/main/Changes.md)
- [Commits](https://github.com/sidekiq/sidekiq/compare/v7.1.1...v7.1.2)

---
updated-dependencies:
- dependency-name: sidekiq
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-15 10:05:58 +00:00
dependabot[bot]
b0c9c6e6e1 chore(deps): bump ddtrace from 1.12.0 to 1.12.1
Bumps [ddtrace](https://github.com/DataDog/dd-trace-rb) from 1.12.0 to 1.12.1.
- [Release notes](https://github.com/DataDog/dd-trace-rb/releases)
- [Changelog](https://github.com/DataDog/dd-trace-rb/blob/master/CHANGELOG.md)
- [Commits](https://github.com/DataDog/dd-trace-rb/compare/v1.12.0...v1.12.1)

---
updated-dependencies:
- dependency-name: ddtrace
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-15 09:58:24 +00:00
Maikel
701fef84f3 Merge pull request #10850 from mkllnk/require-belongs-to--part1
Require belongs_to associations - part 1
2023-06-15 09:20:42 +10:00
Konrad
cf3692e688 Merge pull request #10992 from openfoodfoundation/dependabot/bundler/active_storage_validations-1.0.4
chore(deps): bump active_storage_validations from 1.0.3 to 1.0.4
2023-06-14 22:25:16 +02:00
Konrad
863fed56ce Merge pull request #10455 from openfoodfoundation/dependabot/bundler/redis-5.0.6
Fix `redis` and `hiredis-client` version requirements
2023-06-14 22:09:13 +02:00
Filipe
e6d42a0c4f Merge pull request #10999 from Matt-Yorkley/bom-issues
Fix BOM order loading issue
2023-06-14 19:01:54 +01:00
Matt-Yorkley
64508d3c3d Add unit test for direct image URLs 2023-06-14 12:53:20 +01:00
Matt-Yorkley
395cf7fb8d Use direct image URLs for enterprise logos 2023-06-14 12:53:20 +01:00
Matt-Yorkley
5ad37ce6a5 Return default image url on ActiveStorage errors in image loading 2023-06-14 12:53:20 +01:00
dependabot[bot]
6e9721b64c chore(deps): bump aws-sdk-s3 from 1.123.1 to 1.124.0
Bumps [aws-sdk-s3](https://github.com/aws/aws-sdk-ruby) from 1.123.1 to 1.124.0.
- [Release notes](https://github.com/aws/aws-sdk-ruby/releases)
- [Changelog](https://github.com/aws/aws-sdk-ruby/blob/version-3/gems/aws-sdk-s3/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-ruby/commits)

---
updated-dependencies:
- dependency-name: aws-sdk-s3
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-14 09:58:54 +00:00
Matt-Yorkley
4c7e947738 Migrate data
So it turns out all images uploaded before the ActiveStorage migration are internally set to "public-read", and all images uploaded after the migration are internally set to "private". This migration switches all images in S3 buckets back to "public-read".
2023-06-14 10:56:10 +01:00
Matt-Yorkley
b510668ecf Render direct URLs for s3 images 2023-06-14 10:56:10 +01:00
Matt-Yorkley
6f12d012ed Use #url helper 2023-06-14 10:56:10 +01:00
Matt-Yorkley
551d0d3a93 Simplify calling #url_for in models 2023-06-14 10:56:10 +01:00
Matt-Yorkley
a898915724 Use named image variants 2023-06-14 10:56:10 +01:00
Matt-Yorkley
e54cff2274 Set images to public-read
Defining an alternate s3 configuration set to `public: true` means we can use it selectively. It sets the objects to `acl: "public-read"` by default (read-only) and means any image tags for those assets can use direct public links in the src attribute (without hitting the ActiveStorage::Representation endpoint). The default non-public service will still be used by default for any other files on instances using s3.
2023-06-14 10:56:10 +01:00
Maikel Linke
91d0dabc1d Require associations on DistributorShippingMethod 2023-06-14 15:09:12 +10:00
Maikel Linke
bd11475fe1 Require associations on DistributorPaymentMethod 2023-06-14 15:08:22 +10:00
Maikel Linke
ed231ec512 Update belongs_to default in Customer model 2023-06-14 15:08:05 +10:00
Maikel Linke
fc00a48d67 Require associations of CoordinatorFee 2023-06-14 15:08:05 +10:00
Maikel Linke
c02c90317f Require user of column preference record
It doesn't make sense to have a preference without a user. And it was
already enforced in the database.
2023-06-14 15:07:43 +10:00
Maikel Linke
2d4cfd7548 Validate and enforce AdjustmentMetadata associations 2023-06-14 15:07:43 +10:00
Maikel Linke
d88781a083 Start to adopt new default to require belongs_to
Newer version of Rails have this option as default. We can slowly
transition to opt in gradually, model by model. Once all models are
covered, we can change the default and remove the setting from the
models again.

The style violation was added to the todo file because it's temporary.

We have 60 models using `belongs_to`. And changing them all at once
breaks some specs. So let's do it gradually.
2023-06-14 15:06:59 +10:00
Maikel
989a88e252 Merge pull request #10848 from mkllnk/totals-report
Fix error on summarising total_units in Order Cycle Supplier Totals report
2023-06-14 13:59:48 +10:00
Filipe
9c42781ff1 Merge pull request #10913 from abdellani/remove-split-checkout-toggle-and-legacy-checkout
Remove split checkout toggle and legacy checkout
2023-06-13 17:00:07 +01:00
Matt-Yorkley
73b2d37224 Don't try to load orders if the number of line_items with the current filters applied is zero
This ends up sending a request to the orders endpoint with no filters and no search params, which then tries to load every order in the entire database if the user is superadmin, which blows up.
2023-06-13 15:47:19 +01:00
Mohamed ABDELLANI
2654d3b866 update the rubocop_todo list 2023-06-13 14:58:16 +01:00
Matt-Yorkley
5fa81d1333 Fix invalid test setup in old tax tests 2023-06-13 14:58:16 +01:00
Matt-Yorkley
4e7fab6914 Delete dead code Checkout#find_transition
This method is only called from tests and nowhere else in the codebase. We may as well remove it.
2023-06-13 14:58:16 +01:00
Matt-Yorkley
8d633234f4 Set voucher specs to pending temporarily 2023-06-13 14:58:16 +01:00
Matt-Yorkley
d5a625bdeb Fix Paypal spec 2023-06-13 14:58:16 +01:00
Matt-Yorkley
0e289a23c1 Set some legacy checkout specs that we might want to rewrite later to pending 2023-06-13 14:58:16 +01:00
Matt-Yorkley
5487aa19fc Fix missing checkout_state_path 2023-06-13 14:58:16 +01:00
Mohamed ABDELLANI
345f540723 fix spec/models/spree/tax_rate_spec.rb 2023-06-13 14:58:16 +01:00
Mohamed ABDELLANI
78617905c6 remove spec/requests/checkout/concurrency_spec.rb 2023-06-13 14:58:16 +01:00
Mohamed ABDELLANI
56204b2315 fix ./spec/routing/stripe_spec.rb 2023-06-13 14:58:16 +01:00
Mohamed ABDELLANI
905187f3ce fix ./spec/services/order_tax_adjustments_fetcher_spec.rb:100 2023-06-13 14:58:16 +01:00
Mohamed ABDELLANI
7e84579aa3 spec/system/consumer/shopping/checkout_stripe_spec
these tests are using the legacy checkout
2023-06-13 14:58:16 +01:00
Mohamed ABDELLANI
bd0e7cdfc8 remove legacy checkout tests 2023-06-13 14:58:16 +01:00
Mohamed ABDELLANI
907c65d98c run create_tax_charge! after transition to payment state 2023-06-13 14:58:16 +01:00
Mohamed ABDELLANI
c2aaf88e98 remove checkout controller 2023-06-13 14:58:16 +01:00
Mohamed ABDELLANI
fc0cca2210 remove legacy checkout view 2023-06-13 14:58:16 +01:00
jibees
c379dcacc5 Merge pull request #10993 from openfoodfoundation/dependabot/bundler/jwt-2.7.1
chore(deps): bump jwt from 2.7.0 to 2.7.1
2023-06-13 15:05:30 +02:00
jibees
64e6d639c1 Merge pull request #10995 from openfoodfoundation/dependabot/bundler/rubocop-1.52.1
chore(deps-dev): bump rubocop from 1.52.0 to 1.52.1
2023-06-13 15:03:45 +02:00
jibees
374904f473 Merge pull request #10996 from openfoodfoundation/dependabot/bundler/test-unit-3.6.0
chore(deps): bump test-unit from 3.5.9 to 3.6.0
2023-06-13 15:03:03 +02:00
jibees
fb7ae9fd58 Merge pull request #10991 from openfoodfoundation/dependabot/bundler/view_component-3.2.0
chore(deps): bump view_component from 3.1.0 to 3.2.0
2023-06-13 15:02:26 +02:00
dependabot[bot]
19bd05ce5a chore(deps): bump test-unit from 3.5.9 to 3.6.0
Bumps [test-unit](https://github.com/test-unit/test-unit) from 3.5.9 to 3.6.0.
- [Release notes](https://github.com/test-unit/test-unit/releases)
- [Commits](https://github.com/test-unit/test-unit/compare/3.5.9...3.6.0)

---
updated-dependencies:
- dependency-name: test-unit
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-13 10:11:47 +00:00
dependabot[bot]
f9abec4346 chore(deps-dev): bump rubocop from 1.52.0 to 1.52.1
Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.52.0 to 1.52.1.
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop/compare/v1.52.0...v1.52.1)

---
updated-dependencies:
- dependency-name: rubocop
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-13 10:10:38 +00:00
dependabot[bot]
3e7ad17f69 chore(deps): bump jwt from 2.7.0 to 2.7.1
Bumps [jwt](https://github.com/jwt/ruby-jwt) from 2.7.0 to 2.7.1.
- [Release notes](https://github.com/jwt/ruby-jwt/releases)
- [Changelog](https://github.com/jwt/ruby-jwt/blob/main/CHANGELOG.md)
- [Commits](https://github.com/jwt/ruby-jwt/compare/v2.7.0...v2.7.1)

---
updated-dependencies:
- dependency-name: jwt
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-13 10:08:44 +00:00
dependabot[bot]
b813879330 chore(deps): bump active_storage_validations from 1.0.3 to 1.0.4
Bumps [active_storage_validations](https://github.com/igorkasyanchuk/active_storage_validations) from 1.0.3 to 1.0.4.
- [Release notes](https://github.com/igorkasyanchuk/active_storage_validations/releases)
- [Changelog](https://github.com/igorkasyanchuk/active_storage_validations/blob/master/CHANGES.md)
- [Commits](https://github.com/igorkasyanchuk/active_storage_validations/compare/1.0.3...1.0.4)

---
updated-dependencies:
- dependency-name: active_storage_validations
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-13 10:02:26 +00:00
Filipe
12bb8db7b3 Merge pull request #10933 from Matt-Yorkley/fix-payment-intents
Fix ProcessPaymentIntent service
2023-06-13 11:00:27 +01:00
dependabot[bot]
c3846ad269 chore(deps): bump view_component from 3.1.0 to 3.2.0
Bumps [view_component](https://github.com/viewcomponent/view_component) from 3.1.0 to 3.2.0.
- [Release notes](https://github.com/viewcomponent/view_component/releases)
- [Changelog](https://github.com/ViewComponent/view_component/blob/main/docs/CHANGELOG.md)
- [Commits](https://github.com/viewcomponent/view_component/compare/v3.1.0...v3.2.0)

---
updated-dependencies:
- dependency-name: view_component
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-13 09:58:11 +00:00
Matt-Yorkley
93c3241bb5 Add more test coverage in stripe controller spec 2023-06-13 10:14:09 +01:00
Matt-Yorkley
abd55b2104 Move order to completed whether it's current state is payment or confirmation 2023-06-13 10:14:09 +01:00
Matt-Yorkley
47df9493ae Fix ProcessPaymentIntent service 2023-06-13 10:14:09 +01:00
Gaetan Craig-Riou
694e46d1fb Fix Bundler/OrderedGems 2023-06-13 15:35:40 +10:00
Gaetan Craig-Riou
4564021f79 Remove redis version limitation 2023-06-13 15:06:52 +10:00
David Cook
b85cf26907 Add comment 2023-06-13 15:00:09 +10:00
Jean-Baptiste Bellet
02432ee2ec Do not upgrade to redis >= 5
since Redis >= 3, < 5 is actually a requirement of Action Cable Redis subscription adapter until Rails 7.0.4.

https://github.com/rails/rails/blob/v6.1.7/actioncable/lib/action_cable/subscription_adapter/redis.rb
2023-06-13 15:00:09 +10:00
Jean-Baptiste Bellet
520ced350e Do not specify redis version 2023-06-13 14:59:19 +10:00
Jean-Baptiste Bellet
e41d1f2205 Following the doc, remove hiredis and use hiredis-client
Reference:
 - https://github.com/redis/redis-rb/issues/1178
 - https://github.com/redis/redis-rb#hiredis-binding
2023-06-13 14:59:19 +10:00
David Cook
c5ce49e08c Merge pull request #10948 from dacook/buu-table-styles
[admin_v3] Update all table styles
2023-06-13 13:08:55 +10:00
David Cook
e4c65ea87d Prettify palette file 2023-06-13 11:46:28 +10:00
David Cook
f007cf3dad Fix up table borders 2023-06-13 11:45:39 +10:00
David Cook
edcdcd3f74 Use header colour for table headers 2023-06-13 11:45:39 +10:00
David Cook
16534319b6 Replace dark blue with "Sherpa blue"
It looks like it’s used in headers, some buttons and a loading message
2023-06-13 11:45:39 +10:00
David Cook
d85ea628e2 Change default font colour to near-black
It looks like this is the main font colour in the new designs.
2023-06-13 11:45:39 +10:00
David Cook
821446e150 Style pagination links
And provide a basic hover state for most other buttons.
The pagination button hover and active states will need updating.

The darker background colour sometimes wraps a whole table (eg products table).
2023-06-13 11:45:39 +10:00
David Cook
744f95809a Remove uppercase styling of form elements 2023-06-13 11:45:39 +10:00
David Cook
fb17a679c0 First pass at new table colours
There is more to do, for example the dropshadows.

I've continued with the unopinionated colour naming (eg color-7), but would like to consider giving them more meaningfule names..
2023-06-13 11:45:39 +10:00
David Cook
2ae91bdbe2 Use variable for font size reset
The current value is 13px already, but I'd like to experiment changing this.

I'm not sure if we even need the reset, but am not delving into that right now.
2023-06-13 11:44:48 +10:00
David Cook
3967f54533 Use different variables and table styles for admin_v3 2023-06-13 11:44:48 +10:00
Konrad
6bd66585a9 Merge pull request #10935 from openfoodfoundation/dependabot/bundler/i18n-1.14.1
chore(deps): bump i18n from 1.13.0 to 1.14.1
2023-06-12 17:39:42 +02:00
Konrad
11f84b5276 Merge pull request #10934 from openfoodfoundation/dependabot/bundler/aws-sdk-s3-1.123.1
chore(deps): bump aws-sdk-s3 from 1.122.0 to 1.123.1
2023-06-12 17:24:20 +02:00
Filipe
23239bad8b Merge pull request #10970 from openfoodfoundation/dependabot/bundler/knapsack_pro-5.1.0
chore(deps-dev): bump knapsack_pro from 4.1.0 to 5.1.0
2023-06-12 16:19:32 +01:00
Konrad
a207a445b1 Merge pull request #10907 from jibees/3041-missing-translation-in-product-variant-selection-upon-order-creation
Admin, Create an order, Select a product: translate some messages in the product selection search box
2023-06-12 17:08:52 +02:00
Jean-Baptiste Bellet
16256ee114 Order and Unordered list should have a margin-left set
Has been reset to 0 via `typography.scss`
2023-06-12 16:58:00 +02:00
dependabot[bot]
15e9c4eb37 chore(deps): bump i18n from 1.13.0 to 1.14.1
Bumps [i18n](https://github.com/ruby-i18n/i18n) from 1.13.0 to 1.14.1.
- [Release notes](https://github.com/ruby-i18n/i18n/releases)
- [Changelog](https://github.com/ruby-i18n/i18n/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ruby-i18n/i18n/compare/v1.13.0...v1.14.1)

---
updated-dependencies:
- dependency-name: i18n
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-12 14:44:01 +00:00
Konrad
3e3ae5d8ae Merge pull request #10929 from openfoodfoundation/dependabot/bundler/ddtrace-1.12.0
chore(deps): bump ddtrace from 1.11.1 to 1.12.0
2023-06-12 16:43:01 +02:00
Konrad
48c107bde1 Merge pull request #10974 from cillian/ignore-whitespace-in-product-import
Ignore leading and trailing whitespace when importing products via a spreadsheet
2023-06-12 16:32:15 +02:00
Konrad
80dd8755b0 Merge pull request #10915 from mkllnk/mini-racer
Remove unused mini_racer gem
2023-06-12 16:05:52 +02:00
Konrad
791518988d Merge pull request #10918 from openfoodfoundation/dependabot/bundler/view_component-3.1.0
chore(deps): bump view_component from 3.0.0 to 3.1.0
2023-06-12 15:36:21 +02:00
Jean-Baptiste Bellet
149ec5511c Translate select2 messages 2023-06-12 15:11:23 +02:00
dependabot[bot]
351343fb6c chore(deps): bump aws-sdk-s3 from 1.122.0 to 1.123.1
Bumps [aws-sdk-s3](https://github.com/aws/aws-sdk-ruby) from 1.122.0 to 1.123.1.
- [Release notes](https://github.com/aws/aws-sdk-ruby/releases)
- [Changelog](https://github.com/aws/aws-sdk-ruby/blob/version-3/gems/aws-sdk-s3/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-ruby/commits)

---
updated-dependencies:
- dependency-name: aws-sdk-s3
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-12 15:06:04 +02:00
dependabot[bot]
6145413b1a chore(deps): bump ddtrace from 1.11.1 to 1.12.0
Bumps [ddtrace](https://github.com/DataDog/dd-trace-rb) from 1.11.1 to 1.12.0.
- [Release notes](https://github.com/DataDog/dd-trace-rb/releases)
- [Changelog](https://github.com/DataDog/dd-trace-rb/blob/master/CHANGELOG.md)
- [Commits](https://github.com/DataDog/dd-trace-rb/compare/v1.11.1...v1.12.0)

---
updated-dependencies:
- dependency-name: ddtrace
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-12 15:05:11 +02:00
dependabot[bot]
d87e40bb69 chore(deps): bump view_component from 3.0.0 to 3.1.0
Bumps [view_component](https://github.com/viewcomponent/view_component) from 3.0.0 to 3.1.0.
- [Release notes](https://github.com/viewcomponent/view_component/releases)
- [Changelog](https://github.com/ViewComponent/view_component/blob/main/docs/CHANGELOG.md)
- [Commits](https://github.com/viewcomponent/view_component/compare/v3.0.0...v3.1.0)

---
updated-dependencies:
- dependency-name: view_component
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-12 15:04:17 +02:00
Maikel Linke
d6859e0bf7 Remove unused mini_racer gem
All asset compilation is done with webpacker at the moment.
2023-06-12 15:01:11 +02:00
Konrad
1f2f5e2eec Merge pull request #10892 from openfoodfoundation/dependabot/bundler/rails-7.0.5
chore(deps): bump rails from 7.0.4.3 to 7.0.5
2023-06-12 14:58:07 +02:00
jibees
b53aba3844 Merge pull request #10986 from openfoodfoundation/dependabot/bundler/capybara-3.39.2
chore(deps-dev): bump capybara from 3.39.1 to 3.39.2
2023-06-12 14:42:48 +02:00
jibees
45dcdf1611 Merge pull request #10985 from openfoodfoundation/dependabot/npm_and_yarn/jasmine-core-5.0.1
chore(deps-dev): bump jasmine-core from 5.0.0 to 5.0.1
2023-06-12 14:31:03 +02:00
jibees
8c971f2efa Merge pull request #10984 from openfoodfoundation/dependabot/npm_and_yarn/floating-ui/dom-1.3.0
chore(deps): bump @floating-ui/dom from 1.2.9 to 1.3.0
2023-06-12 14:29:56 +02:00
dependabot[bot]
8a8200a039 chore(deps-dev): bump capybara from 3.39.1 to 3.39.2
Bumps [capybara](https://github.com/teamcapybara/capybara) from 3.39.1 to 3.39.2.
- [Changelog](https://github.com/teamcapybara/capybara/blob/master/History.md)
- [Commits](https://github.com/teamcapybara/capybara/compare/3.39.1...3.39.2)

---
updated-dependencies:
- dependency-name: capybara
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-12 09:58:05 +00:00
dependabot[bot]
8a376e782a chore(deps-dev): bump jasmine-core from 5.0.0 to 5.0.1
Bumps [jasmine-core](https://github.com/jasmine/jasmine) from 5.0.0 to 5.0.1.
- [Release notes](https://github.com/jasmine/jasmine/releases)
- [Changelog](https://github.com/jasmine/jasmine/blob/main/RELEASE.md)
- [Commits](https://github.com/jasmine/jasmine/compare/v5.0.0...v5.0.1)

---
updated-dependencies:
- dependency-name: jasmine-core
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-12 09:57:39 +00:00
dependabot[bot]
6ab1bfb2ab chore(deps): bump @floating-ui/dom from 1.2.9 to 1.3.0
Bumps [@floating-ui/dom](https://github.com/floating-ui/floating-ui/tree/HEAD/packages/dom) from 1.2.9 to 1.3.0.
- [Release notes](https://github.com/floating-ui/floating-ui/releases)
- [Commits](https://github.com/floating-ui/floating-ui/commits/@floating-ui/dom@1.3.0/packages/dom)

---
updated-dependencies:
- dependency-name: "@floating-ui/dom"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-12 09:57:18 +00:00
Sigmund Petersen
c2305615a6 Merge pull request #10971 from filipefurtad0/mouse_hover_spec
Adds spec for tooltips on orders page
2023-06-12 09:53:16 +02:00
Jean-Baptiste Bellet
ff0f81167a Translate 'Enterprises' > 'OIDC Settings' tab title 2023-06-12 09:19:16 +02:00
Gaetan Craig-Riou
41b3ddae08 Merge pull request #10714 from macanudo527/fix_linelength
Fix Style/LineLength
2023-06-12 09:53:23 +10:00
Konrad
fc09f95fa1 Merge pull request #10961 from jibees/10946-white-label-trix-editor-changes-on-the-custom-tab-content-do-not-trigger-the-update-button
[WhiteLabel] Make update button active when changing custom tab content
2023-06-09 21:46:02 +02:00
Konrad
13037d2d9d Merge pull request #10949 from jibees/10630-buu-as-an-enterprise-user-i-can-see-the-back-office-with-new-brand-colours
[`admin_style_v3`] As an enterprise user i can see the back office with new brand colours
2023-06-09 21:24:01 +02:00
Konrad
9125c730ed Merge pull request #10960 from jibees/customize-trix-editor-to-have-the-right-colors
[White Label] Customize colors of custom content editor to have beautiful toolbar
2023-06-09 20:35:36 +02:00
Matt-Yorkley
70170078d1 Merge pull request #10976 from Matt-Yorkley/payment-localized-number
Require localized_number in Payment class
2023-06-09 18:45:13 +01:00
Konrad
bd505bbee7 Merge pull request #10959 from jibees/10945-white-label-narrow-screen-width-no-marging-on-custom-tab-content
[WhiteLabel] Add some margin to custom tab content for a shop
2023-06-09 19:45:04 +02:00
Matt-Yorkley
24200de8dd Require localized_number in Payment class
There seems to be some contexts (jobs for subscriptions) where the Payment class loads but LocalizedNumber is an undefined constant. It lives in the /lib directory so it's not auto-loaded.
2023-06-09 18:16:37 +01:00
Konrad
d0f4c44add Merge pull request #10938 from jibees/10931-white-label-custom-tab-without-a-title-impossible-to-disable-the-custom-tab
[White Label] Validate the presence of a custom tab title before creating it (+ max 20 characters length)
2023-06-09 19:01:13 +02:00
Cillian O'Ruanaidh
5cde4de512 Ignore leading and trailing whitespace in spreadsheet when importing products 2023-06-09 16:23:18 +01:00
Konrad
502b5e8664 Merge pull request #10937 from jibees/10900-white-label-remove-ofn-navigation-for-small-width-screens
[White Label] Remove ofn navigation for small width screens as well when option is activated
2023-06-09 16:28:22 +02:00
Konrad
35fef9e7ac Merge pull request #10876 from dacook/prettier-css-admin
Prettier css admin
2023-06-09 16:02:11 +02:00
filipefurtad0
24913476ac Adds spec for tooltips on orders page 2023-06-09 11:23:42 +01:00
dependabot[bot]
515a9a9b1c chore(deps-dev): bump knapsack_pro from 4.1.0 to 5.1.0
Bumps [knapsack_pro](https://github.com/KnapsackPro/knapsack_pro-ruby) from 4.1.0 to 5.1.0.
- [Changelog](https://github.com/KnapsackPro/knapsack_pro-ruby/blob/master/CHANGELOG.md)
- [Commits](https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v4.1.0...v5.1.0)

---
updated-dependencies:
- dependency-name: knapsack_pro
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-09 10:02:21 +00:00
Neal Chambers
a65b43d32f Update .rubocop_todo.yml 2023-06-09 16:39:29 +09:00
Neal Chambers
9a8551e3ea Shorten Where Statement 2023-06-09 16:39:29 +09:00
Neal Chambers
a35a07b441 Rewrite sum to be more Readable 2023-06-09 16:39:29 +09:00
Neal Chambers
449430cabc Indent code to be more Readable 2023-06-09 16:39:29 +09:00
Neal Chambers
252697b782 Rewrite If and Unless Statements to be more Readable 2023-06-09 16:39:26 +09:00
Jean-Baptiste Bellet
74fd1814e4 Create a trixeditor controller and broadcast a change event on form
Therefore, AngularJS can set form as dirty

+ add associated spec
2023-06-09 08:03:17 +02:00
Maikel Linke
6803e0a8f9 Fix error on summarising total_units 2023-06-09 09:55:33 +10:00
Maikel Linke
71e4d2c6ed Spec total_units report column
Current reports don't deal with invalid legacy data.
2023-06-09 09:55:33 +10:00
Maikel Linke
00e171a8f1 Reduce indentation in report spec
Specs should also test from the outside instead of declaring modules and
test from within those modules.
2023-06-09 09:55:33 +10:00
Jean-Baptiste Bellet
5d43285834 Update all locales with the latest Transifex translations 2023-06-08 17:36:04 +02:00
Filipe
ca03e1596b Merge pull request #10952 from Matt-Yorkley/full-name
Improve nil-safety in variant naming methods
2023-06-08 16:26:28 +01:00
Filipe
c12415a340 Merge pull request #10955 from Matt-Yorkley/bulk-invoice-bug
Ensure directory exists before saving invoices pdf
2023-06-08 15:22:27 +01:00
Matt-Yorkley
f4261b85b8 Merge pull request #10940 from Matt-Yorkley/order-tidyup
Order class tidyup
2023-06-08 15:06:59 +01:00
Filipe
7974e1eaa6 Merge pull request #10936 from abdellani/fix-order-progressing-automatically-on-BOO
fix Viewing an order in state "confirmation" changes the state to "complete"
2023-06-08 14:50:04 +01:00
Jean-Baptiste Bellet
457d5a6c83 Override some css classes, to have a beautiful trix editor toolbar buttons
- buttons background are transparent (instead of blue)
 - buttons background on hovering are transparent (instead of green)
 - disabled buttons cursor is default (instead of pointer)
2023-06-08 11:43:59 +02:00
Jean-Baptiste Bellet
05104841cd Add some margin to custom tab content via columns css class 2023-06-08 11:36:06 +02:00
Jean-Baptiste Bellet
d1d050e6a4 Limit size to 20 char for the custom tab title 2023-06-08 11:27:07 +02:00
David Cook
e2ba18f828 Set sentence case tab names in Ruby instead of CSS
I chose .capitalize instead of .humanize, because the latter has extra features which may not be desired.
2023-06-08 11:24:44 +02:00
Jean-Baptiste Bellet
d6cb483f0d Adjust color to the title of the page 2023-06-08 11:24:44 +02:00
Jean-Baptiste Bellet
d7f7ff7436 Remove background, border and adjust margin top 2023-06-08 11:24:44 +02:00
Jean-Baptiste Bellet
905220a055 Add new color: $color-8 #191c1d Near-black 2023-06-08 11:24:44 +02:00
Jean-Baptiste Bellet
b865d8c1c0 Copy/Paste file admin/shared/layout under admin_v3 folder
+ prettier
2023-06-08 11:24:44 +02:00
Jean-Baptiste Bellet
51f47fc351 Add border bottom when hovering or selected
+ add some padding to separate those borders then
2023-06-08 11:24:44 +02:00
Jean-Baptiste Bellet
1b4236640d Add border with box-shadow to menu and sub-menu 2023-06-08 11:24:44 +02:00
Jean-Baptiste Bellet
2057449dac Add new color: $color-7 #EFF1F2 Light grey 2023-06-08 11:24:44 +02:00
Jean-Baptiste Bellet
ba98039e95 Adjust color to orange when selected or hover 2023-06-08 11:24:44 +02:00
Jean-Baptiste Bellet
d51786ac9e Adjust font size for labels in menu 2023-06-08 11:24:44 +02:00
Jean-Baptiste Bellet
ccd7466ede No more white on labels but dark grey 2023-06-08 11:24:44 +02:00
Jean-Baptiste Bellet
b163d4a584 Remove background-color on menu 2023-06-08 11:24:44 +02:00
Jean-Baptiste Bellet
a4d3011e27 Add new color: $color-9 #2E3132 Dark Grey 2023-06-08 11:24:44 +02:00
Jean-Baptiste Bellet
dd48092728 Prettier file 2023-06-08 11:24:44 +02:00
Jean-Baptiste Bellet
5ee3550ebd Change case to Sentence case
CSS property `capitalize` uppercase all first letter of each words.

I need to use a small trick with `::first-letter` selector
2023-06-08 11:24:44 +02:00
Jean-Baptiste Bellet
eab46b67e3 Copy/Paste file admin/components/navigation under admin_v3 folder
+ prettier
2023-06-08 11:24:44 +02:00
Jean-Baptiste Bellet
e34f4a9971 AdminV3: Remove icon from icon from primary navigation menu
Co-Authored-By: Maikel <maikel@email.org.au>
2023-06-08 11:24:43 +02:00
Neal Chambers
dde775d2b7 Remove Old Code and Comments 2023-06-08 15:20:04 +10:00
Neal Chambers
3432e30465 Fix Style/UnlessGuard 2023-06-08 15:20:04 +10:00
Neal Chambers
12aa4f9970 Fix Layout/IndentationStyle 2023-06-08 15:20:04 +10:00
Neal Chambers
b04879604a Rewrite Ternary Expression to Prevent Layout/LineLength 2023-06-08 15:20:04 +10:00
Maikel Linke
4ecbbae55e Adapt large browser window as default
We were really close to that anyway. It simplifies the code a bit.
2023-06-08 13:51:29 +10:00
Maikel Linke
7cf68cd33b Ensure that specs restore default window size 2023-06-08 13:51:25 +10:00
Maikel Linke
241b307762 Fix typos 2023-06-08 11:34:05 +10:00
David Cook
7d26158e06 Code cleanup
Co-authored-by: Maikel <maikel@email.org.au>
2023-06-08 11:31:37 +10:00
Maikel Linke
99fbf80b4c Style Layout/MultilineMethodCallIndentation 2023-06-08 11:15:42 +10:00
Matt-Yorkley
98f78927b7 Update app/jobs/bulk_invoice_job.rb
Co-authored-by: Maikel <maikel@email.org.au>
2023-06-08 00:56:24 +01:00
Matt-Yorkley
bf051fc35b Pull checkout-workflow-related callback methods out into the Checkout module which defines checkout state changes 2023-06-07 18:54:20 +01:00
Matt-Yorkley
760bf269ca Pull validations-related methods out into a separate module 2023-06-07 18:54:20 +01:00
Matt-Yorkley
bed2fe69f6 Update regression tests 2023-06-07 16:39:37 +01:00
jibees
c6b5eda85c Merge pull request #10951 from openfoodfoundation/dependabot/bundler/faraday-2.7.6
chore(deps): bump faraday from 2.7.5 to 2.7.6
2023-06-07 17:34:10 +02:00
Matt-Yorkley
b091a0ed1a Ensure directory exists before saving pdf
These directories can get wiped during deployments
2023-06-07 16:25:53 +01:00
Mohamed ABDELLANI
fbf55cf7bd Merge pull request #2 from Matt-Yorkley/fix-order-progressing-automatically-on-BOO
Fix pre-existing issues with admin order controller
2023-06-07 13:49:06 +01:00
David Cook
3ce48848f0 Prettify the rest 2023-06-07 14:23:57 +02:00
David Cook
548a6f8d2e Prettify app/webpacker/css/admin/plugins/ 2023-06-07 14:23:57 +02:00
David Cook
10c52959ad Prettify app/webpacker/css/admin/hacks/ 2023-06-07 14:23:57 +02:00
David Cook
08dc3e3cbe Prettify more admin css
yarn prettier --write
2023-06-07 14:23:02 +02:00
David Cook
fbf5862c66 Ignore some css subfolders
Prettier changes these files dramatically and they're arguably not easier to read.
2023-06-07 14:21:34 +02:00
dependabot[bot]
01dcf068f9 chore(deps): bump rails from 7.0.4.3 to 7.0.5
Bumps [rails](https://github.com/rails/rails) from 7.0.4.3 to 7.0.5.
- [Release notes](https://github.com/rails/rails/releases)
- [Commits](https://github.com/rails/rails/compare/v7.0.4.3...v7.0.5)

---
updated-dependencies:
- dependency-name: rails
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-07 14:12:34 +02:00
Matt-Yorkley
b58b555e38 Improve flaky spec 2023-06-07 13:01:37 +01:00
Matt-Yorkley
983353e078 Remove dead code
I'm pretty sure this was here because advancing the order was adding order errors in some cases
2023-06-07 13:01:37 +01:00
Matt-Yorkley
968bf882c4 Fix flaky spec 2023-06-07 13:01:37 +01:00
Matt-Yorkley
daf243996b Improve flaky spec 2023-06-07 13:01:37 +01:00
Matt-Yorkley
7a7ab17db4 Improve customer tests 2023-06-07 13:01:37 +01:00
Matt-Yorkley
6daf29400f Improve distribution and line items tests 2023-06-07 13:01:37 +01:00
Matt-Yorkley
f3ee10dd5a Simplify by moving conditional to guard clause 2023-06-07 13:01:37 +01:00
Matt-Yorkley
cf0f148dba Advance order when creating a shipment
This action gets called from the order edit page when adding line items and it's one of the places that needs to advance the order *before* redirecting back to the order edit action
2023-06-07 13:01:37 +01:00
Matt-Yorkley
bb73d70e57 Improve nil-safety in variant naming methods 2023-06-07 12:17:50 +01:00
dependabot[bot]
24343c769e chore(deps): bump faraday from 2.7.5 to 2.7.6
Bumps [faraday](https://github.com/lostisland/faraday) from 2.7.5 to 2.7.6.
- [Release notes](https://github.com/lostisland/faraday/releases)
- [Changelog](https://github.com/lostisland/faraday/blob/main/CHANGELOG.md)
- [Commits](https://github.com/lostisland/faraday/compare/v2.7.5...v2.7.6)

---
updated-dependencies:
- dependency-name: faraday
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-07 09:57:34 +00:00
Filipe
2d28a57c6f Merge pull request #10922 from jibees/10903-white-label-make-logo-url-link-more-tolerant-in-terms-of-format-and-add-example
[White Label] Make logo url link more tolerant in terms of format
2023-06-07 10:00:31 +01:00
Maikel
1c9a09d88d Merge pull request #10943 from openfoodfoundation/dependabot/bundler/paranoia-2.6.2
chore(deps): bump paranoia from 2.6.1 to 2.6.2
2023-06-07 16:31:01 +10:00
Maikel Linke
1ebacf96ad Ignore accidental spaces around whitelabel URL 2023-06-07 13:12:06 +10:00
Matt-Yorkley
acc34d1deb Update advance to payment logic 2023-06-07 00:58:43 +01:00
Matt-Yorkley
e1b37090be Use _path helper instead of _url 2023-06-07 00:58:43 +01:00
Matt-Yorkley
6e8ed1f612 Hide secondary form until the order has line items 2023-06-07 00:58:43 +01:00
Matt-Yorkley
c7bb24e2a0 Remove dead code and clarify update logic 2023-06-07 00:58:43 +01:00
Matt-Yorkley
e88843c733 Ensure order number is generated nicely on new records 2023-06-07 00:58:43 +01:00
Matt-Yorkley
67c3e09dba Use RESTful routes for orders controller actions 2023-06-07 00:35:47 +01:00
Konrad
1b6147db30 Merge pull request #10896 from jibees/10571-bom-orders-not-sorted-by-most-recent-date
BOM: Sort by order completed at desc for line items by default
2023-06-06 17:37:54 +02:00
Matt-Yorkley
2bfb57a1a1 Clarify shipments partial inclusion 2023-06-06 14:59:53 +01:00
Matt-Yorkley
8813edaed8 Fix variables in form partial 2023-06-06 14:59:03 +01:00
Jean-Baptiste Bellet
7dc8c4b891 Hide OFN navigation also on small width screens 2023-06-06 14:55:41 +02:00
Jean-Baptiste Bellet
a8b85a65e9 Add context for visiting a path 2023-06-06 14:44:05 +02:00
Jean-Baptiste Bellet
5c3e07db52 Test that OFN navigation is on mobile views as well 2023-06-06 14:44:05 +02:00
dependabot[bot]
10ca09eaef chore(deps): bump paranoia from 2.6.1 to 2.6.2
Bumps [paranoia](https://github.com/rubysherpas/paranoia) from 2.6.1 to 2.6.2.
- [Release notes](https://github.com/rubysherpas/paranoia/releases)
- [Changelog](https://github.com/rubysherpas/paranoia/blob/core/CHANGELOG.md)
- [Commits](https://github.com/rubysherpas/paranoia/compare/v2.6.1...v2.6.2)

---
updated-dependencies:
- dependency-name: paranoia
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-06 10:00:41 +00:00
Jean-Baptiste Bellet
daaeca88e8 Add some helpers to test mobile views 2023-06-06 12:00:16 +02:00
Mohamed ABDELLANI
77554e21fc move advance_to_payment on order's details page from edit to update 2023-06-06 10:23:01 +01:00
Matt-Yorkley
7c72969792 Move Order #state_changed method out into Checkout concern (alongside order states logic) 2023-06-05 23:54:04 +01:00
Matt-Yorkley
a62e51c0d0 Remove Order #refresh_shipment_rates method 2023-06-05 23:54:04 +01:00
Matt-Yorkley
1a7d70772a Make Order #products_available_from_new_distribution method private 2023-06-05 23:54:04 +01:00
Matt-Yorkley
3dd4e7ef03 Delegate order updater method 2023-06-05 23:54:04 +01:00
Matt-Yorkley
8a27dd84fe Make Order #disallow_guest_order method private 2023-06-05 21:30:49 +01:00
Matt-Yorkley
05a715a43a Remove Order #distribution_set? method 2023-06-05 21:30:46 +01:00
Matt-Yorkley
17b10d10c0 Make Order #deliver_order_confirmation_email method private 2023-06-05 21:30:43 +01:00
Matt-Yorkley
10dbeb32b2 Remove Order #credit_cards method 2023-06-05 21:30:40 +01:00
Matt-Yorkley
b3bd112cdb Remove Order #shipped_shipments method 2023-06-05 21:30:36 +01:00
Jean-Baptiste Bellet
93cf562d59 Update en.yml 2023-06-05 15:48:02 +02:00
Jean-Baptiste Bellet
5938577bd1 Update custom_tab_spec.rb 2023-06-05 15:43:11 +02:00
Jean-Baptiste Bellet
1594d1c718 Validate custom tab title 2023-06-05 15:41:33 +02:00
Jean-Baptiste Bellet
abe63e5b04 Add context for visiting a path 2023-06-05 12:08:43 +02:00
Jean-Baptiste Bellet
40111910b6 Validates white_label_logo_link on enterprise model 2023-06-05 11:24:07 +02:00
Jean-Baptiste Bellet
4edb159ef8 Avoid flaky spec by matching the array
Context: https://github.com/openfoodfoundation/openfoodnetwork/actions/runs/5081492387/jobs/9129944001?pr=10896
2023-06-05 10:05:09 +02:00
Jean-Baptiste Bellet
ccb183d60b Sort by order_date desc for line_items in BOM
+ update spec to have different order time
2023-06-05 10:05:09 +02:00
jibees
a785b4d5e0 Merge pull request #10928 from openfoodfoundation/dependabot/bundler/rubocop-1.52.0
chore(deps-dev): bump rubocop from 1.51.0 to 1.52.0
2023-06-05 09:28:04 +02:00
Maikel Linke
16fba20686 Update rubocop todo file 2023-06-05 12:13:35 +10:00
Maikel Linke
1cbb45a618 Style Lint/RedundantSafeNavigation
The cop suggested to change more but they were false positives:

* https://github.com/rubocop/rubocop/pull/11915
2023-06-05 12:09:32 +10:00
Maikel Linke
38bd31d0e3 Style Layout/TrailingWhitespace 2023-06-05 10:42:21 +10:00
Konrad
750b6b284d Merge pull request #10910 from jibees/10902-white-label-for-uploading-custom-logo-use-same-design-as-for-enterprise-logobanner-and-provide-required-image-dimensions
[White Label] Backoffice: improve design for logo used in shopfront
2023-06-04 14:50:49 +02:00
dependabot[bot]
78338864d8 chore(deps-dev): bump rubocop from 1.51.0 to 1.52.0
Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.51.0 to 1.52.0.
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop/compare/v1.51.0...v1.52.0)

---
updated-dependencies:
- dependency-name: rubocop
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-02 09:57:30 +00:00
Jean-Baptiste Bellet
880ba85791 Add http to white label logo link if this do not start with http 2023-06-01 17:37:05 +02:00
Jean-Baptiste Bellet
ced8f8aa58 Use shared_examples as we will test many URLs later on
"It's a Surprise Tool That Will Help Us Later"
2023-06-01 17:37:05 +02:00
Jean-Baptiste Bellet
2e0191e603 Improve UX: same as enterprise logo and promo image 2023-06-01 17:16:22 +02:00
323 changed files with 3698 additions and 4084 deletions

49
.github/workflows/stage.yml vendored Normal file
View File

@@ -0,0 +1,49 @@
name: "Deploy to Staging"
on:
pull_request:
types: [labeled]
workflow_dispatch:
inputs:
server:
description: "Staging Server"
type: choice
required: true
options:
- staging.openfoodnetwork.org.uk
- staging.openfoodnetwork.org.au
- staging.coopcircuits.fr
permissions:
contents: read
jobs:
deploy_pr:
if: contains(fromJSON('["pr-staged-uk", "pr-staged-au", "pr-staged-fr"]'), github.event.label.name)
runs-on: ubuntu-latest
steps:
- name: Configure deployment key
run: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.DEPLOYMENT_KEY }}" > ~/.ssh/id_rsa
echo "${{ secrets.DEPLOYMENT_HOSTS }}" > ~/.ssh/known_hosts
- name: Deploy to Staging
env:
LABEL: ${{ github.event.label.name }}
run: |
ssh ofn-deploy@${{ github.event.label.description }} -o LogLevel=ERROR "pull-request-${{ github.event.pull_request.number }} ."
deploy_branch:
if: ${{ inputs.server }}
runs-on: ubuntu-latest
steps:
- name: Configure deployment key
run: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.DEPLOYMENT_KEY }}" > ~/.ssh/id_rsa
echo "${{ secrets.DEPLOYMENT_HOSTS }}" > ~/.ssh/known_hosts
- name: Deploy to Staging
run: |
ssh ofn-deploy@${{ inputs.server }} -o LogLevel=ERROR "$GITHUB_REF_NAME $GITHUB_SHA"

View File

@@ -1,4 +1,4 @@
# Basically, ignore everythings expect app/webpacker/controllers/*.js and app/webpacker/packs/*.js
# Ignore a lot of things, but we should enable where it can be helpful.
*.md
*.yml
@@ -6,13 +6,21 @@
*.json
*.html
# JS
# Enabled: app/webpacker/controllers/*.js and app/webpacker/packs/*.js
babel.config.js
postcss.config.js
# SCSS
# Enabled: most of admin
/app/webpacker/css/admin/globals/
/app/webpacker/css/admin/shared/
/app/webpacker/css/admin_v3/globals/variables.scss
/app/webpacker/css/darkswarm/
/app/webpacker/css/mail/
/app/webpacker/css/shared/
# More
/app/assets/
/config/
/coverage/

View File

@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1400 --no-auto-gen-timestamp`
# using RuboCop version 1.51.0.
# using RuboCop version 1.52.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@@ -16,7 +16,7 @@ Gemspec/RequiredRubyVersion:
- 'engines/order_management/order_management.gemspec'
- 'engines/web/web.gemspec'
# Offense count: 28
# Offense count: 31
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: with_first_argument, with_fixed_indentation
@@ -62,11 +62,10 @@ Layout/BlockEndNewline:
- 'spec/lib/open_food_network/enterprise_fee_calculator_spec.rb'
- 'spec/system/admin/orders_spec.rb'
# Offense count: 3
# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
Layout/ClosingParenthesisIndentation:
Exclude:
- 'lib/reporting/queries/joins.rb'
- 'spec/system/admin/orders_spec.rb'
# Offense count: 1
@@ -141,7 +140,7 @@ Layout/LeadingCommentSpace:
Exclude:
- 'spec/system/admin/enterprises_spec.rb'
# Offense count: 115
# Offense count: 114
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, no_space
@@ -198,7 +197,7 @@ Layout/LineEndStringConcatenationIndentation:
- 'spec/system/consumer/cookies_spec.rb'
- 'spec/system/consumer/shopping/cart_spec.rb'
# Offense count: 643
# Offense count: 606
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
@@ -206,28 +205,20 @@ Layout/LineLength:
Exclude:
- 'app/components/confirm_modal_component.rb'
- 'app/controllers/admin/bulk_line_items_controller.rb'
- 'app/controllers/admin/enterprise_fees_controller.rb'
- 'app/controllers/admin/enterprise_relationships_controller.rb'
- 'app/controllers/admin/enterprises_controller.rb'
- 'app/controllers/admin/product_import_controller.rb'
- 'app/controllers/admin/schedules_controller.rb'
- 'app/controllers/admin/subscriptions_controller.rb'
- 'app/controllers/api/v0/order_cycles_controller.rb'
- 'app/controllers/payment_gateways/paypal_controller.rb'
- 'app/helpers/angular_form_builder.rb'
- 'app/helpers/angular_form_helper.rb'
- 'app/helpers/enterprises_helper.rb'
- 'app/helpers/order_cycles_helper.rb'
- 'app/helpers/spree/orders_helper.rb'
- 'app/jobs/subscription_confirm_job.rb'
- 'app/mailers/subscription_mailer.rb'
- 'app/models/column_preference.rb'
- 'app/models/concerns/order_shipment.rb'
- 'app/models/concerns/product_stock.rb'
- 'app/models/concerns/variant_stock.rb'
- 'app/models/customer.rb'
- 'app/models/enterprise.rb'
- 'app/models/product_import/entry_processor.rb'
- 'app/models/product_import/spreadsheet_entry.rb'
- 'app/models/product_import/unit_converter.rb'
- 'app/models/proxy_order.rb'
@@ -236,17 +227,13 @@ Layout/LineLength:
- 'app/models/spree/gateway/stripe_sca.rb'
- 'app/models/spree/line_item.rb'
- 'app/models/spree/order.rb'
- 'app/models/spree/payment_method.rb'
- 'app/models/spree/preferences/store.rb'
- 'app/models/subscription.rb'
- 'app/models/variant_override.rb'
- 'app/serializers/api/admin/subscription_line_item_serializer.rb'
- 'app/services/cart_service.rb'
- 'app/services/checkout/post_checkout_actions.rb'
- 'app/services/embedded_page_service.rb'
- 'app/services/order_cycle_form.rb'
- 'app/services/order_syncer.rb'
- 'app/services/products_renderer.rb'
- 'app/services/variant_units/variant_and_line_item_naming.rb'
- 'engines/order_management/app/services/order_management/subscriptions/validator.rb'
- 'engines/order_management/spec/services/order_management/order/updater_spec.rb'
@@ -260,7 +247,6 @@ Layout/LineLength:
- 'lib/open_food_network/scope_variants_for_search.rb'
- 'lib/reporting/line_items.rb'
- 'lib/reporting/reports/enterprise_fee_summary/report_data/enterprise_fee_type_total.rb'
- 'lib/reporting/reports/xero_invoices/base.rb'
- 'lib/spree/localized_number.rb'
- 'lib/tasks/data.rake'
- 'lib/tasks/enterprises.rake'
@@ -362,7 +348,6 @@ Layout/LineLength:
- 'spec/support/cancan_helper.rb'
- 'spec/support/features/datepicker_helper.rb'
- 'spec/support/matchers/select2_matchers.rb'
- 'spec/support/matchers/table_matchers.rb'
- 'spec/support/request/web_helper.rb'
- 'spec/system/admin/adjustments_spec.rb'
- 'spec/system/admin/bulk_order_management_spec.rb'
@@ -376,13 +361,12 @@ Layout/MultilineBlockLayout:
Exclude:
- 'engines/order_management/app/services/order_management/subscriptions/validator.rb'
# Offense count: 7
# Offense count: 6
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: symmetrical, new_line, same_line
Layout/MultilineMethodCallBraceLayout:
Exclude:
- 'lib/reporting/queries/joins.rb'
- 'spec/system/admin/orders_spec.rb'
- 'spec/system/admin/products_spec.rb'
@@ -414,7 +398,7 @@ Layout/TrailingEmptyLines:
Exclude:
- 'Rakefile'
# Offense count: 73
# Offense count: 76
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowInHeredoc.
Layout/TrailingWhitespace:
@@ -550,13 +534,17 @@ Lint/RedundantDirGlobSort:
- 'spec/base_spec_helper.rb'
- 'spec/system_helper.rb'
# Offense count: 1
# Offense count: 6
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedMethods.
# AllowedMethods: instance_of?, kind_of?, is_a?, eql?, respond_to?, equal?
Lint/RedundantSafeNavigation:
Exclude:
- 'app/models/report_blob.rb'
- 'app/models/spree/payment.rb'
- 'app/serializers/api/admin/subscription_line_item_serializer.rb'
- 'lib/open_food_network/address_finder.rb'
- 'lib/tasks/missing_payments.rake'
# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
@@ -640,11 +628,16 @@ Metrics/BlockLength:
- 'spec/factories/user_factory.rb'
- 'spec/factories/variant_factory.rb'
- 'spec/requests/api/orders_spec.rb'
- 'spec/requests/checkout/failed_checkout_spec.rb'
- 'spec/requests/checkout/stripe_sca_spec.rb'
- 'spec/support/cancan_helper.rb'
- 'spec/support/matchers/select2_matchers.rb'
- 'spec/support/matchers/table_matchers.rb'
- 'spec/swagger_helper.rb'
- 'spec/system/consumer/shopping/checkout_spec.rb'
- 'spec/system/consumer/shopping/checkout_stripe_spec.rb'
- 'spec/system/consumer/shopping/variant_overrides_spec.rb'
- 'spec/system/consumer/split_checkout_tax_not_incl_spec.rb'
# Offense count: 1
# Configuration parameters: CountBlocks, Max.
@@ -688,6 +681,7 @@ Metrics/ClassLength:
- 'app/models/spree/payment.rb'
- 'app/models/spree/product.rb'
- 'app/models/spree/shipment.rb'
- 'app/models/spree/shipping_method.rb'
- 'app/models/spree/user.rb'
- 'app/models/spree/variant.rb'
- 'app/models/spree/zone.rb'
@@ -900,7 +894,7 @@ Rails/ActionOrder:
- 'app/controllers/spree/admin/variants_controller.rb'
- 'app/controllers/user_confirmations_controller.rb'
# Offense count: 15
# Offense count: 13
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Include.
# Include: app/models/**/*.rb
@@ -910,7 +904,6 @@ Rails/ActiveRecordCallbacksOrder:
- 'app/models/enterprise.rb'
- 'app/models/enterprise_group.rb'
- 'app/models/enterprise_relationship.rb'
- 'app/models/spree/line_item.rb'
- 'app/models/spree/order.rb'
- 'app/models/spree/payment.rb'
- 'app/models/spree/product.rb'
@@ -991,7 +984,7 @@ Rails/FilePath:
- 'spec/models/content_configuration_spec.rb'
- 'spec/support/downloads_helper.rb'
# Offense count: 11
# Offense count: 8
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/HasAndBelongsToMany:
@@ -999,12 +992,9 @@ Rails/HasAndBelongsToMany:
- 'app/models/enterprise.rb'
- 'app/models/enterprise_group.rb'
- 'app/models/order_cycle.rb'
- 'app/models/spree/line_item.rb'
- 'app/models/spree/option_value.rb'
- 'app/models/spree/role.rb'
- 'app/models/spree/shipping_method.rb'
- 'app/models/spree/user.rb'
- 'app/models/spree/variant.rb'
- 'app/models/spree/zone.rb'
# Offense count: 47
@@ -1071,7 +1061,7 @@ Rails/I18nLocaleTexts:
Exclude:
- 'app/controllers/admin/stripe_accounts_controller.rb'
# Offense count: 27
# Offense count: 26
# Configuration parameters: IgnoreScopes, Include.
# Include: app/models/**/*.rb
Rails/InverseOf:
@@ -1081,7 +1071,6 @@ Rails/InverseOf:
- 'app/models/spree/country.rb'
- 'app/models/spree/inventory_unit.rb'
- 'app/models/spree/line_item.rb'
- 'app/models/spree/option_type.rb'
- 'app/models/spree/order.rb'
- 'app/models/spree/payment.rb'
- 'app/models/spree/price.rb'
@@ -1480,7 +1469,7 @@ Style/GlobalStdStream:
- 'lib/tasks/subscriptions/debug.rake'
- 'lib/tasks/subscriptions/test.rake'
# Offense count: 39
# Offense count: 38
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
Style/GuardClause:
@@ -1499,7 +1488,6 @@ Style/GuardClause:
- 'app/models/spree/order.rb'
- 'app/models/spree/preferences/preferable_class_methods.rb'
- 'app/services/order_syncer.rb'
- 'app/services/variant_units/variant_and_line_item_naming.rb'
- 'engines/order_management/app/services/order_management/order/updater.rb'
- 'lib/discourse/single_sign_on.rb'
- 'lib/open_food_network/order_cycle_form_applicator.rb'

View File

@@ -119,8 +119,6 @@ gem 'test-unit', '~> 3.5'
gem 'coffee-rails', '~> 5.0.0'
gem 'mini_racer'
gem 'angular_rails_csrf'
gem 'jquery-rails', '4.4.0'

View File

@@ -44,73 +44,73 @@ GEM
remote: https://rubygems.org/
specs:
Ascii85 (1.1.0)
actioncable (7.0.4.3)
actionpack (= 7.0.4.3)
activesupport (= 7.0.4.3)
actioncable (7.0.5)
actionpack (= 7.0.5)
activesupport (= 7.0.5)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.4.3)
actionpack (= 7.0.4.3)
activejob (= 7.0.4.3)
activerecord (= 7.0.4.3)
activestorage (= 7.0.4.3)
activesupport (= 7.0.4.3)
actionmailbox (7.0.5)
actionpack (= 7.0.5)
activejob (= 7.0.5)
activerecord (= 7.0.5)
activestorage (= 7.0.5)
activesupport (= 7.0.5)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.4.3)
actionpack (= 7.0.4.3)
actionview (= 7.0.4.3)
activejob (= 7.0.4.3)
activesupport (= 7.0.4.3)
actionmailer (7.0.5)
actionpack (= 7.0.5)
actionview (= 7.0.5)
activejob (= 7.0.5)
activesupport (= 7.0.5)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.4.3)
actionview (= 7.0.4.3)
activesupport (= 7.0.4.3)
rack (~> 2.0, >= 2.2.0)
actionpack (7.0.5)
actionview (= 7.0.5)
activesupport (= 7.0.5)
rack (~> 2.0, >= 2.2.4)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actionpack-action_caching (1.2.2)
actionpack (>= 4.0.0)
actiontext (7.0.4.3)
actionpack (= 7.0.4.3)
activerecord (= 7.0.4.3)
activestorage (= 7.0.4.3)
activesupport (= 7.0.4.3)
actiontext (7.0.5)
actionpack (= 7.0.5)
activerecord (= 7.0.5)
activestorage (= 7.0.5)
activesupport (= 7.0.5)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.4.3)
activesupport (= 7.0.4.3)
actionview (7.0.5)
activesupport (= 7.0.5)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
active_model_serializers (0.8.4)
activemodel (>= 3.0)
active_storage_validations (1.0.3)
active_storage_validations (1.0.4)
activejob (>= 5.2.0)
activemodel (>= 5.2.0)
activestorage (>= 5.2.0)
activesupport (>= 5.2.0)
activejob (7.0.4.3)
activesupport (= 7.0.4.3)
activejob (7.0.5)
activesupport (= 7.0.5)
globalid (>= 0.3.6)
activemerchant (1.123.0)
activesupport (>= 4.2)
builder (>= 2.1.2, < 4.0.0)
i18n (>= 0.6.9)
nokogiri (~> 1.4)
activemodel (7.0.4.3)
activesupport (= 7.0.4.3)
activerecord (7.0.4.3)
activemodel (= 7.0.4.3)
activesupport (= 7.0.4.3)
activemodel (7.0.5)
activesupport (= 7.0.5)
activerecord (7.0.5)
activemodel (= 7.0.5)
activesupport (= 7.0.5)
activerecord-import (1.4.1)
activerecord (>= 4.2)
activerecord-postgresql-adapter (0.0.1)
@@ -121,14 +121,14 @@ GEM
multi_json (~> 1.11, >= 1.11.2)
rack (>= 2.0.8, < 3)
railties (>= 5.2.4.1)
activestorage (7.0.4.3)
actionpack (= 7.0.4.3)
activejob (= 7.0.4.3)
activerecord (= 7.0.4.3)
activesupport (= 7.0.4.3)
activestorage (7.0.5)
actionpack (= 7.0.5)
activejob (= 7.0.5)
activerecord (= 7.0.5)
activesupport (= 7.0.5)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.4.3)
activesupport (7.0.5)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
@@ -157,17 +157,17 @@ GEM
awesome_nested_set (3.5.0)
activerecord (>= 4.0.0, < 7.1)
aws-eventstream (1.2.0)
aws-partitions (1.760.0)
aws-sdk-core (3.171.1)
aws-partitions (1.779.0)
aws-sdk-core (3.174.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.5)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.64.0)
aws-sdk-core (~> 3, >= 3.165.0)
aws-sdk-kms (1.66.0)
aws-sdk-core (~> 3, >= 3.174.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.122.0)
aws-sdk-core (~> 3, >= 3.165.0)
aws-sdk-s3 (1.124.0)
aws-sdk-core (~> 3, >= 3.174.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.4)
aws-sigv4 (1.5.2)
@@ -191,7 +191,7 @@ GEM
railties (>= 5.2)
thread-local (>= 1.1.0)
cancancan (1.15.0)
capybara (3.39.1)
capybara (3.39.2)
addressable
matrix
mini_mime (>= 0.1.3)
@@ -237,12 +237,12 @@ GEM
datafoodconsortium-connector (1.0.0.pre.alpha.6)
virtual_assembly-semantizer (~> 1.0, >= 1.0.4)
date (3.3.3)
ddtrace (1.11.1)
debase-ruby_core_source (>= 0.10.16, <= 3.2.0)
ddtrace (1.12.1)
debase-ruby_core_source (= 3.2.1)
libdatadog (~> 2.0.0.1.0)
libddwaf (~> 1.8.2.0.0)
libddwaf (~> 1.9.0.0.0)
msgpack
debase-ruby_core_source (3.2.0)
debase-ruby_core_source (3.2.1)
debug (1.8.0)
irb (>= 1.5.0)
reline (>= 0.3.1)
@@ -276,7 +276,7 @@ GEM
factory_bot_rails (6.2.0)
factory_bot (~> 6.2.0)
railties (>= 5.0.0)
faraday (2.7.5)
faraday (2.7.6)
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-follow_redirects (0.3.0)
@@ -340,7 +340,7 @@ GEM
hiredis (0.6.3)
htmlentities (4.3.4)
httpclient (2.8.3)
i18n (1.13.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
i18n-js (3.9.2)
i18n (>= 0.6.6)
@@ -382,17 +382,16 @@ GEM
rspec (>= 2.0, < 4.0)
jsonapi-serializer (2.2.0)
activesupport (>= 4.2)
jwt (2.7.0)
knapsack_pro (4.1.0)
jwt (2.7.1)
knapsack_pro (5.1.0)
rake
launchy (2.5.0)
addressable (~> 2.7)
letter_opener (1.8.1)
launchy (>= 2.2, < 3)
libdatadog (2.0.0.1.0)
libddwaf (1.8.2.0.0)
libddwaf (1.9.0.0.1)
ffi (~> 1.0)
libv8-node (16.10.0.0)
link_header (0.0.8)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
@@ -417,14 +416,12 @@ GEM
mini_magick (4.11.0)
mini_mime (1.1.2)
mini_portile2 (2.8.2)
mini_racer (0.6.3)
libv8-node (~> 16.10.0.0)
minitest (5.18.0)
monetize (1.12.0)
money (~> 6.12)
money (6.16.0)
i18n (>= 0.6.4, <= 2)
msgpack (1.7.0)
msgpack (1.7.1)
multi_json (1.15.0)
multi_xml (0.6.0)
net-imap (0.3.4)
@@ -474,10 +471,11 @@ GEM
activerecord (>= 5.2)
request_store (~> 1.1)
parallel (1.23.0)
paranoia (2.6.1)
paranoia (2.6.2)
activerecord (>= 5.1, < 7.1)
parser (3.2.2.1)
parser (3.2.2.3)
ast (~> 2.4.1)
racc
paypal-sdk-core (0.3.4)
multi_json (~> 1.0)
xml-simple
@@ -502,7 +500,7 @@ GEM
activerecord (>= 4.2)
railties (>= 4.2)
raabro (1.4.0)
racc (1.6.2)
racc (1.7.0)
rack (2.2.7)
rack-mini-profiler (2.3.4)
rack (>= 1.2.0)
@@ -520,20 +518,20 @@ GEM
rack-test (2.1.0)
rack (>= 1.3)
rack-timeout (0.6.3)
rails (7.0.4.3)
actioncable (= 7.0.4.3)
actionmailbox (= 7.0.4.3)
actionmailer (= 7.0.4.3)
actionpack (= 7.0.4.3)
actiontext (= 7.0.4.3)
actionview (= 7.0.4.3)
activejob (= 7.0.4.3)
activemodel (= 7.0.4.3)
activerecord (= 7.0.4.3)
activestorage (= 7.0.4.3)
activesupport (= 7.0.4.3)
rails (7.0.5)
actioncable (= 7.0.5)
actionmailbox (= 7.0.5)
actionmailer (= 7.0.5)
actionpack (= 7.0.5)
actiontext (= 7.0.5)
actionview (= 7.0.5)
activejob (= 7.0.5)
activemodel (= 7.0.5)
activerecord (= 7.0.5)
activestorage (= 7.0.5)
activesupport (= 7.0.5)
bundler (>= 1.15.0)
railties (= 7.0.4.3)
railties (= 7.0.5)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
@@ -553,9 +551,9 @@ GEM
i18n (>= 0.7, < 2)
railties (>= 6.0.0, < 8)
rails_safe_tasks (1.0.0)
railties (7.0.4.3)
actionpack (= 7.0.4.3)
activesupport (= 7.0.4.3)
railties (7.0.5)
actionpack (= 7.0.5)
activesupport (= 7.0.5)
method_source
rake (>= 12.2)
thor (~> 1.0)
@@ -575,7 +573,7 @@ GEM
redis (4.8.1)
redis-client (0.14.1)
connection_pool
regexp_parser (2.8.0)
regexp_parser (2.8.1)
reline (0.3.3)
io-console (~> 0.5)
request_store (1.5.1)
@@ -629,17 +627,17 @@ GEM
rswag-ui (2.9.0)
actionpack (>= 3.1, < 7.1)
railties (>= 3.1, < 7.1)
rubocop (1.51.0)
rubocop (1.52.1)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.2.0.0)
parser (>= 3.2.2.3)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.28.1)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
rubocop-rails (2.19.1)
activesupport (>= 4.2.0)
@@ -669,7 +667,7 @@ GEM
semantic_range (3.0.0)
shoulda-matchers (5.3.0)
activesupport (>= 5.2.0)
sidekiq (7.1.1)
sidekiq (7.1.2)
concurrent-ruby (< 2)
connection_pool (>= 2.3.0)
rack (>= 2.2.4)
@@ -721,7 +719,7 @@ GEM
attr_required (>= 0.0.5)
httpclient (>= 2.4)
temple (0.8.2)
test-unit (3.5.9)
test-unit (3.6.0)
power_assert
thor (1.2.2)
thread-local (1.1.0)
@@ -743,7 +741,7 @@ GEM
activemodel (>= 3.0.0)
public_suffix
vcr (6.1.0)
view_component (3.0.0)
view_component (3.2.0)
activesupport (>= 5.2.0, < 8.0)
concurrent-ruby (~> 1.0)
method_source (~> 1.0)
@@ -861,7 +859,6 @@ DEPENDENCIES
mime-types
mimemagic (> 0.3.5)
mini_portile2 (~> 2.8)
mini_racer
monetize (~> 1.11)
oauth2 (~> 1.4.7)
omniauth-rails_csrf_protection

View File

@@ -9,6 +9,7 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout,
$scope.sharedResource = false
$scope.columns = Columns.columns
$scope.sorting = SortOptions
$scope.sorting.toggle("order_date")
$scope.pagination = LineItems.pagination
$scope.per_page_options = [
{id: 15, name: t('js.admin.orders.index.per_page', results: 15)},
@@ -61,6 +62,8 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout,
$scope.dereferenceLoadedData()
$scope.loadOrders = ->
return $scope.orders = [] unless $scope.line_items.length
RequestMonitor.load $scope.orders = Orders.index(
"q[id_in][]": $scope.line_items.map((line_item) -> line_item.order.id)
)
@@ -79,6 +82,7 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout,
"q[order_order_cycle_id_eq]": $scope.orderCycleFilter,
"q[order_completed_at_gteq]": if formattedStartDate then formattedStartDate else undefined,
"q[order_completed_at_lt]": if formattedEndDate then formattedEndDate else undefined,
"q[s]": "order_completed_at desc",
"page": $scope.page,
"per_page": $scope.per_page
)

View File

@@ -33,6 +33,4 @@ angular.module('admin.orderCycles').factory('Enterprise', ($resource) ->
variantsOf: (product) ->
if product.variants.length > 0
variant.id for variant in product.variants
else
[product.master_id]
})

View File

@@ -1,15 +0,0 @@
$ ->
($ '#new_image_link').click (event) ->
event.preventDefault()
($ '.no-objects-found').hide()
($ this).hide()
$.ajax
type: 'GET'
url: @href
data: (
authenticity_token: AUTH_TOKEN
)
success: (r) ->
($ '#images').html r

View File

@@ -1,7 +0,0 @@
($ '#cancel_link').click (event) ->
event.preventDefault()
($ '.no-objects-found').show()
($ '#new_image_link').show()
($ '#images').html('')

View File

@@ -10,6 +10,12 @@ angular.module("admin.utils").directive "variantAutocomplete", ($timeout) ->
element.select2
placeholder: t('admin.orders.select_variant')
minimumInputLength: 3
formatInputTooShort: ->
t('admin.select2.minimal_search_length', count: 3)
formatSearching: ->
t('admin.select2.searching')
formatNoMatches: ->
t('admin.select2.no_matches')
ajax:
url: Spree.routes.variants_search
datatype: "json"

View File

@@ -1,22 +0,0 @@
angular.module('Darkswarm').controller "AccordionCtrl", ($scope, localStorageService, $timeout, $document, CurrentHub) ->
$scope.accordionSections = ["details", "billing", "shipping", "payment"]
$scope.accordion = { details: true, billing: true, shipping: true, payment: true }
$scope.show = (section) ->
$scope.accordion[section] = true
$scope.scrollTo = (section) ->
# Scrolling is confused by our position:fixed top bar - add an offset to scroll
# to the correct location, plus 5px buffer
offset_height = $("nav.top-bar").height() + 5
$document.scrollTo($("##{section}"), offset_height, 400)
$scope.$on 'purchaseFormInvalid', (event, form) ->
# Scroll to first invalid section
for section in $scope.accordionSections
if not form[section].$valid
$scope.show section
$timeout ->
$scope.scrollTo(section)
, 50
break

View File

@@ -1,12 +0,0 @@
angular.module('Darkswarm').controller "BillingCtrl", ($scope, $timeout, $controller) ->
angular.extend this, $controller('FieldsetMixin', {$scope: $scope})
$scope.name = "billing"
$scope.nextPanel = "shipping"
$scope.summary = ->
[$scope.order.bill_address.address1,
$scope.order.bill_address.city,
$scope.order.bill_address.zipcode]
$timeout $scope.onTimeout

View File

@@ -1,43 +0,0 @@
angular.module('Darkswarm').controller "CheckoutCtrl", ($scope, localStorageService, Checkout, CurrentUser, CurrentHub, $http) ->
$scope.Checkout = Checkout
$scope.submitted = false
# Bind to local storage
$scope.fieldsToBind = ["bill_address", "email", "payment_method_id", "shipping_method_id", "ship_address"]
prefix = "order_#{Checkout.order.id}#{CurrentUser.id or ""}#{CurrentHub.hub.id}"
for field in $scope.fieldsToBind
localStorageService.bind $scope, "Checkout.order.#{field}", Checkout.order[field], "#{prefix}_#{field}"
localStorageService.bind $scope, "Checkout.ship_address_same_as_billing", true, "#{prefix}_sameasbilling"
localStorageService.bind $scope, "Checkout.default_bill_address", false, "#{prefix}_defaultasbilladdress"
localStorageService.bind $scope, "Checkout.default_ship_address", false, "#{prefix}_defaultasshipaddress"
$scope.order = Checkout.order # Ordering is important
$scope.secrets = Checkout.secrets
$scope.enabled = !!CurrentUser.id?
$scope.purchase = (event, form) ->
event.preventDefault()
$scope.formdata = form
$scope.submitted = true
if CurrentUser.id
$scope.validateForm(form)
else
$scope.ensureUserIsGuest()
$scope.validateForm = ->
if $scope.formdata.$valid
$scope.Checkout.purchase()
else
$scope.$broadcast 'purchaseFormInvalid', $scope.formdata
$scope.ensureUserIsGuest = (callback = null) ->
$http.post("/user/registered_email", {email: $scope.order.email})
.then (response)->
window.CableReady.perform(response.data)
.catch ->
$scope.validateForm() if $scope.submitted
callback() if callback

View File

@@ -1,8 +0,0 @@
angular.module('Darkswarm').controller "CountryCtrl", ($scope, availableCountries) ->
$scope.countries = availableCountries
$scope.countriesById = $scope.countries.reduce (obj, country) ->
obj[country.id] = country
obj
, {}

View File

@@ -1,24 +0,0 @@
angular.module('Darkswarm').controller "DetailsCtrl", ($scope, $timeout, $http, CurrentUser, SpreeUser, $controller) ->
angular.extend this, $controller('FieldsetMixin', {$scope: $scope})
$scope.name = "details"
$scope.nextPanel = "billing"
$scope.login_or_next = (event) ->
event.preventDefault()
unless CurrentUser.id
$scope.ensureUserIsGuest($scope.next)
return
$scope.next()
$scope.summary = ->
[$scope.fullName(),
$scope.order.email,
$scope.order.bill_address.phone]
$scope.fullName = ->
[$scope.order.bill_address.firstname ? null,
$scope.order.bill_address.lastname ? null].join(" ").trim()
$timeout $scope.onTimeout

View File

@@ -1,19 +0,0 @@
angular.module('Darkswarm').controller "PaymentCtrl", ($scope, $timeout, savedCreditCards, Dates, $controller) ->
angular.extend this, $controller('FieldsetMixin', {$scope: $scope})
$scope.savedCreditCards = savedCreditCards
$scope.name = "payment"
$scope.months = Dates.months
$scope.years = Dates.years
$scope.secrets.card_month = "1"
$scope.secrets.card_year = moment().year()
for card in savedCreditCards when card.is_default
$scope.secrets.selected_card = card.id
break
$scope.summary = ->
[$scope.Checkout.paymentMethod()?.name]
$timeout $scope.onTimeout

View File

@@ -1,11 +0,0 @@
angular.module('Darkswarm').controller "ShippingCtrl", ($scope, $timeout, ShippingMethods, $controller) ->
angular.extend this, $controller('FieldsetMixin', {$scope: $scope})
$scope.ShippingMethods = ShippingMethods
$scope.name = "shipping"
$scope.nextPanel = "payment"
$scope.summary = ->
[$scope.Checkout.shippingMethod()?.name]
$timeout $scope.onTimeout

View File

@@ -33,9 +33,9 @@ angular.module('Darkswarm').factory 'Products', (OrderCycleResource, OrderCycle,
prices = (v.price for v in product.variants)
product.price = Math.min.apply(null, prices)
product.hasVariants = product.variants?.length > 0
product.primaryImage = product.images[0]?.small_url if product.images
product.primaryImage = product.image?.small_url if product.image
product.primaryImageOrMissing = product.primaryImage || "/noimage/small.png"
product.largeImage = product.images[0]?.large_url if product.images
product.largeImage = product.image?.large_url if product.image
dereference: ->
for product in @fetched_products

View File

@@ -15,6 +15,6 @@
.columns.small-12.medium-6.large-6.product-img
%img{"ng-src" => "{{::product.largeImage}}", "ng-if" => "::product.largeImage"}
%img.placeholder{ src: "/noimage/large.png", "ng-if" => "::!product.largeImage"}
%img.placeholder{ src: Spree::Image.default_image_url(:large), "ng-if" => "::!product.largeImage"}
%ng-include{src: "'partials/close.html'"}

View File

@@ -6,7 +6,7 @@ class ProductComponent < ViewComponentReflex::Component
def initialize(product:, columns:)
super
@product = product
@image = @product.images[0] if product.images.any?
@image = @product.image if product.image.present?
@columns = columns.map do |c|
{
id: c[:value],
@@ -28,7 +28,7 @@ class ProductComponent < ViewComponentReflex::Component
when 'price'
@product.price
when 'unit'
"#{@product.unit_value} #{@product.variant_unit}"
"#{@product.variants.first.unit_value} #{@product.variant_unit}"
when 'producer'
@product.supplier.name
when 'category'

View File

@@ -168,7 +168,7 @@ class ProductsTableComponent < ViewComponentReflex::Component
def product_query_includes
[
master: [:images],
:image,
variants: [
:default_price,
:stock_locations,

View File

@@ -12,8 +12,7 @@ module Admin
@line_items = order_permissions.
editable_line_items.where(order_id: orders).
includes(:variant).
ransack(params[:q]).result.
reorder('spree_line_items.order_id ASC, spree_line_items.id ASC')
ransack(params[:q]).result
@pagy, @line_items = pagy(@line_items) if pagination_required?

View File

@@ -25,7 +25,6 @@ module Admin
format.json {
render_as_json @collection, controller: self, include_calculators: @include_calculators
}
# format.json { @presented_collection = @collection.each_with_index.map { |ef, i| EnterpriseFeePresenter.new(self, ef, i) } }
end
end
@@ -63,7 +62,9 @@ module Admin
when :for_order_cycle
order_cycle = OrderCycle.find_by(id: params[:order_cycle_id]) if params[:order_cycle_id]
coordinator = Enterprise.find_by(id: params[:coordinator_id]) if params[:coordinator_id]
order_cycle = OrderCycle.new(coordinator: coordinator) if order_cycle.nil? && coordinator.present?
if order_cycle.nil? && coordinator.present?
order_cycle = OrderCycle.new(coordinator: coordinator)
end
enterprises = OpenFoodNetwork::OrderCyclePermissions.new(spree_current_user,
order_cycle).visible_enterprises
EnterpriseFee.for_enterprises(enterprises).order('enterprise_id', 'fee_type', 'name')

View File

@@ -178,7 +178,9 @@ module Admin
when :for_order_cycle
@order_cycle = OrderCycle.find_by(id: params[:order_cycle_id]) if params[:order_cycle_id]
coordinator = Enterprise.find_by(id: params[:coordinator_id]) if params[:coordinator_id]
@order_cycle = OrderCycle.new(coordinator: coordinator) if @order_cycle.nil? && coordinator.present?
if @order_cycle.nil? && coordinator.present?
@order_cycle = OrderCycle.new(coordinator: coordinator)
end
enterprises = OpenFoodNetwork::OrderCyclePermissions.new(spree_current_user, @order_cycle)
.visible_enterprises
@@ -186,7 +188,7 @@ module Admin
if enterprises.present?
enterprises.includes(
supplied_products:
[:supplier, :variants, { master: [:images] }]
[:supplier, :variants, :image]
)
end
when :index
@@ -195,7 +197,8 @@ module Admin
editable_enterprises.
order('is_primary_producer ASC, name')
elsif json_request?
OpenFoodNetwork::Permissions.new(spree_current_user).editable_enterprises.ransack(params[:q]).result
OpenFoodNetwork::Permissions.new(spree_current_user)
.editable_enterprises.ransack(params[:q]).result
else
Enterprise.where("1=0")
end
@@ -203,7 +206,6 @@ module Admin
OpenFoodNetwork::Permissions.new(spree_current_user).visible_enterprises
.includes(:shipping_methods, :payment_methods).ransack(params[:q]).result
else
# TODO was ordered with is_distributor DESC as well, not sure why or how we want to sort this now
OpenFoodNetwork::Permissions.new(spree_current_user).
editable_enterprises.
order('is_primary_producer ASC, name')
@@ -324,7 +326,9 @@ module Admin
:producer_properties_attributes).nil?
names = Spree::Property.pluck(:name)
enterprise_params[:producer_properties_attributes].each do |key, property|
enterprise_params[:producer_properties_attributes].delete key unless names.include? property[:property_name]
unless names.include? property[:property_name]
enterprise_params[:producer_properties_attributes].delete key
end
end
end
end

View File

@@ -40,8 +40,11 @@ module Admin
def index
respond_to do |format|
format.json do
render_as_json @collection, ams_prefix: params[:ams_prefix],
editable_schedule_ids: permissions.editable_schedules.pluck(:id)
render_as_json(
@collection,
ams_prefix: params[:ams_prefix],
editable_schedule_ids: permissions.editable_schedules.pluck(:id)
)
end
end
end
@@ -119,7 +122,8 @@ module Admin
.pluck(:id)
result = @existing_order_cycle_ids
result |= (requested & permitted) # add any requested & permitted ids
result -= ((result & permitted) - requested) # remove any existing and permitted ids that were not specifically requested
# remove any existing and permitted ids that were not specifically requested
result -= ((result & permitted) - requested)
result
end

View File

@@ -80,8 +80,12 @@ module Api
end
def permitted_ransack_params
[:name_or_meta_keywords_or_variants_display_as_or_variants_display_name_or_supplier_name_cont,
:with_properties, :primary_taxon_id_in_any]
[
"#{[:name, :meta_keywords, :variants_display_as,
:variants_display_name, :supplier_name]
.join('_or_')}_cont",
:with_properties, :primary_taxon_id_in_any
]
end
def distributor

View File

@@ -9,9 +9,9 @@ module Api
product = Spree::Product.find(params[:product_id])
authorize! :update, product
image = product.images.first || Spree::Image.new(
viewable_id: product.master.id,
viewable_type: 'Spree::Variant'
image = product.image || Spree::Image.new(
viewable_id: product.id,
viewable_type: 'Spree::Product'
)
success_status = image.persisted? ? :ok : :created

View File

@@ -116,7 +116,7 @@ module Api
def product_query_includes
[
master: { images: { attachment_attachment: :blob } },
image: { attachment_attachment: :blob },
variants: [:default_price, :stock_locations, :stock_items, :variant_overrides]
]
end

View File

@@ -21,7 +21,9 @@ module Api
@shipment.refresh_rates
@shipment.save!
render json: @shipment.reload, serializer: Api::ShipmentSerializer, status: :ok
OrderWorkflow.new(@order).advance_to_payment if @order.line_items.any?
render json: @shipment, serializer: Api::ShipmentSerializer, status: :ok
end
def update
@@ -32,7 +34,7 @@ module Api
@shipment.fee_adjustment.fire_events(:open)
if @shipment.update(shipment_params)
@order.updater.update_totals_and_states
@order.update_totals_and_states
end
@shipment.fee_adjustment.close

View File

@@ -56,9 +56,9 @@ module Api
def scope
if @product
variants = if current_api_user.has_spree_role?("admin") || params[:show_deleted]
@product.variants_including_master.with_deleted
@product.variants.with_deleted
else
@product.variants_including_master
@product.variants
end
else
variants = Spree::Variant.where(nil)

View File

@@ -1,187 +0,0 @@
# frozen_string_literal: true
require 'open_food_network/address_finder'
class CheckoutController < ::BaseController
include OrderStockCheck
include OrderCompletion
include WhiteLabel
layout 'darkswarm'
helper 'terms_and_conditions'
helper 'checkout'
# We need pessimistic locking to avoid race conditions.
# Otherwise we fail on duplicate indexes or end up with negative stock.
prepend_around_action CurrentOrderLocker, only: [:edit, :update]
prepend_before_action :check_hub_ready_for_checkout
prepend_before_action :check_order_cycle_expiry
prepend_before_action :require_order_cycle
prepend_before_action :require_distributor_chosen
before_action :load_order
before_action :handle_insufficient_stock
before_action :associate_user
before_action :check_authorization
before_action :hide_ofn_navigation, only: :edit
helper 'spree/orders'
def edit; end
def update
params_adapter = Checkout::FormDataAdapter.new(permitted_params, @order, spree_current_user)
return action_failed unless @order.update(params_adapter.params[:order] || {})
checkout_workflow(params_adapter.shipping_method_id)
rescue Spree::Core::GatewayError => e
gateway_error(e)
action_failed(e)
rescue StandardError => e
flash[:error] = I18n.t("checkout.failed")
action_failed(e)
ensure
@order.update_order!
end
private
def check_authorization
authorize!(:edit, current_order, session[:access_token])
end
def load_order
load_checkout_order
return handle_invalid_stock unless valid_order_line_items?
before_address
setup_for_current_state
end
def handle_invalid_stock
reset_order_to_cart
respond_to do |format|
format.html do
redirect_to main_app.cart_path
end
format.json do
render json: { path: main_app.cart_path }, status: :bad_request
end
end
end
def setup_for_current_state
method_name = :"before_#{@order.state}"
__send__(method_name) if respond_to?(method_name, true)
end
def before_address
associate_user
finder = OpenFoodNetwork::AddressFinder.new(@order.email, @order.customer, spree_current_user)
@order.bill_address = finder.bill_address
@order.ship_address = finder.ship_address
end
def before_payment
current_order.payments.destroy_all if request.put?
end
def checkout_workflow(shipping_method_id)
while @order.state != "complete"
if @order.state == "payment"
update_payment_total
return if redirect_to_payment_gateway
return action_failed if @order.errors.any?
return action_failed unless @order.process_payments!
end
next if OrderWorkflow.new(@order).next({ "shipping_method_id" => shipping_method_id })
return action_failed
end
update_response
end
def update_payment_total
@order.updater.update_totals
@order.updater.update_pending_payment
end
def redirect_to_payment_gateway
return unless selected_payment_method.external_gateway?
return unless (redirect_url = selected_payment_method.external_payment_url(order: @order))
render json: { path: redirect_url }, status: :ok
true
end
def selected_payment_method
@selected_payment_method ||= Spree::PaymentMethod.find(
params.dig(:order, :payments_attributes, 0, :payment_method_id)
)
end
def update_response
if order_complete?
processing_succeeded
update_succeeded_response
else
action_failed(RuntimeError.new("Order not complete after the checkout workflow"))
end
end
def order_complete?
@order.state == "complete" || @order.completed?
end
def update_succeeded_response
respond_to do |format|
format.html do
respond_with(@order, location: order_completion_route)
end
format.json do
render json: { path: order_completion_route }, status: :ok
end
end
end
def action_failed(error = RuntimeError.new(order_processing_error))
processing_failed(error)
action_failed_response
end
def action_failed_response
respond_to do |format|
format.html do
render :edit
end
format.json do
discard_flash_errors
render json: { errors: @order.errors, flash: flash.to_hash }.to_json, status: :bad_request
end
end
end
def permitted_params
PermittedAttributes::Checkout.new(params).call
end
def discard_flash_errors
# Marks flash errors for deletion after the current action has completed.
# This ensures flash errors generated during XHR requests are not persisted in the
# session for longer than expected.
flash.discard(:error)
end
end

View File

@@ -13,8 +13,6 @@ module OrderStockCheck
def handle_insufficient_stock
return if sufficient_stock?
reset_order_to_cart
flash[:error] = Spree.t(:inventory_error_flash_for_insufficient_quantity)
redirect_to main_app.cart_path
end
@@ -43,10 +41,4 @@ module OrderStockCheck
def sufficient_stock?
@sufficient_stock ||= @order.insufficient_stock_lines.blank?
end
def reset_order_to_cart
return if OpenFoodNetwork::FeatureToggle.enabled? :split_checkout, spree_current_user
OrderCheckoutRestart.new(@order).call
end
end

View File

@@ -29,11 +29,11 @@ module PaymentGateways
flash[:error] =
Spree.t('flash.generic_error', scope: 'paypal',
reasons: pp_response.errors.map(&:long_message).join(" "))
redirect_to main_app.checkout_state_path(:payment)
redirect_to main_app.checkout_step_path(:payment)
end
rescue SocketError
flash[:error] = Spree.t('flash.connection_failed', scope: 'paypal')
redirect_to main_app.checkout_state_path(:payment)
redirect_to main_app.checkout_step_path(:payment)
end
end

View File

@@ -172,7 +172,7 @@ class SplitCheckoutController < ::BaseController
@order.select_shipping_method(params[:shipping_method_id])
@order.update(order_params)
@order.updater.update_totals_and_states
@order.update_totals_and_states
validate_current_step!

View File

@@ -14,7 +14,7 @@ module Spree
def update_order
@order.reload
@order.updater.update_totals_and_states
@order.update_totals_and_states
end
def collection

View File

@@ -25,6 +25,7 @@ module Spree
set_viewable
@object.attributes = permitted_resource_params
if @object.save
flash[:success] = flash_message_for(@object, :successfully_created)
redirect_to spree.admin_product_images_url(params[:product_id], @url_filters)
@@ -62,20 +63,28 @@ module Spree
private
def collection
parent.image
end
def find_resource
parent.image
end
def build_resource
Spree::Image.new(viewable: parent)
end
def location_after_save
spree.admin_product_images_url(@product)
end
def load_data
@product = Product.find_by(permalink: params[:product_id])
@variants = @product.variants.collect do |variant|
[variant.options_text, variant.id]
end
@variants.insert(0, [Spree.t(:all), @product.master.id])
end
def set_viewable
@image.viewable_type = 'Spree::Variant'
@image.viewable_type = 'Spree::Product'
@image.viewable_id = params[:image][:viewable_id]
end

View File

@@ -58,7 +58,7 @@ module Spree
@order.create_tax_charge!
Spree::TaxRate.adjust(@order, @order.adjustments.admin)
@order.updater.update_totals_and_states
@order.update_totals_and_states
end
def order_params

View File

@@ -8,9 +8,8 @@ module Spree
include OpenFoodNetwork::SpreeApiKeyLoader
helper CheckoutHelper
before_action :load_order, only: [:edit, :update, :fire, :resend,
:invoice, :print, :distribution]
before_action :load_distribution_choices, only: [:new, :edit, :update, :distribution]
before_action :load_order, only: [:edit, :update, :fire, :resend, :invoice, :print]
before_action :load_distribution_choices, only: [:new, :create, :edit, :update]
before_action :require_distributor_abn, only: :invoice
before_action :restore_saved_query!, only: :index
@@ -24,47 +23,35 @@ module Spree
end
def new
@order = Order.create
@order.created_by = spree_current_user
@order.generate_order_number
@order.save
redirect_to spree.distribution_admin_order_path(@order)
end
def distribution
return if order_params.blank?
on_update
@order.assign_attributes(order_params)
return unless @order.save(context: :set_distribution_step)
redirect_to spree.admin_order_customer_path(@order)
@order = Spree::Order.new
end
def edit
@order.shipments.map(&:refresh_rates)
end
OrderWorkflow.new(@order).advance_to_payment
@order.errors.clear
def create
@order = Spree::Order.new(order_params.merge(created_by: spree_current_user))
if @order.save(context: :require_distribution)
redirect_to spree.admin_order_customer_path(@order)
else
render :new
end
end
def update
on_update
if params[:set_distribution_step] && @order.update(order_params)
return redirect_to spree.admin_order_customer_path(@order)
end
unless order_params.present? && @order.update(order_params) && @order.line_items.present?
if @order.line_items.empty? && !params[:suppress_error_msg]
@order.errors.add(:line_items, Spree.t('errors.messages.blank'))
end
order_updated = order_params.present? && @order.update(order_params)
unless order_updated && line_items_present?
flash[:error] = @order.errors.full_messages.join(', ') if @order.errors.present?
return redirect_to spree.edit_admin_order_path(@order)
end
OrderWorkflow.new(@order).advance_to_payment
if @order.complete?
redirect_to spree.edit_admin_order_path(@order)
else
@@ -117,6 +104,13 @@ module Spree
private
def line_items_present?
return true if @order.line_items.any?
@order.errors.add(:line_items, Spree.t('errors.messages.blank'))
false
end
def update_search_results
session[:admin_orders_search] = search_params

View File

@@ -129,7 +129,8 @@ module Spree
@payment_methods.first
end
@previous_cards = @order.credit_cards.with_payment_profile
credit_card_ids = @order.payments.from_credit_card.pluck(:source_id).uniq
@previous_cards = CreditCard.where(id: credit_card_ids).with_payment_profile
end
# At this point admin should have passed through Customer Details step

View File

@@ -121,8 +121,7 @@ module Spree
end
def product_includes
[{ variants: [:images] },
{ master: [:images, :default_price] }]
[:image, { variants: [:images] }]
end
def collection_actions
@@ -182,7 +181,6 @@ module Spree
joins(:product).
where('spree_products.supplier_id IN (?)', editable_enterprises.collect(&:id)).
where('spree_variants.import_date IS NOT NULL').
where(spree_variants: { is_master: false }).
where(spree_variants: { deleted_at: nil }).
order('spree_variants.import_date DESC')
end
@@ -208,7 +206,7 @@ module Spree
end
def set_stock_levels(product, on_hand, on_demand)
variant = product_variant(product)
variant = product.variants.first
begin
variant.on_demand = on_demand if on_demand.present?
@@ -228,14 +226,6 @@ module Spree
end
end
def product_variant(product)
if product.variants.any?
product.variants.first
else
product.master
end
end
def set_product_master_variant_price_to_zero
@product.price = 0 if @product.price.nil?
end

View File

@@ -7,8 +7,6 @@ module Spree
class VariantsController < ::Admin::ResourceController
belongs_to 'spree/product', find_by: :permalink
before_action :assign_default_attributes, only: :new
def index
@url_filters = ::ProductFilters.new.extract(request.query_parameters)
end
@@ -45,6 +43,7 @@ module Spree
flash[:success] = flash_message_for(@object, :successfully_created)
redirect_to spree.admin_product_variants_url(params[:product_id], @url_filters)
else
flash[:error] = @object.errors.full_messages.to_sentence if @object.errors.any?
redirect_to spree.new_admin_product_variant_url(params[:product_id], @url_filters)
end
@@ -83,13 +82,6 @@ module Spree
@object.save
end
def assign_default_attributes
@object.attributes = @object.product.master.
attributes.except('id', 'created_at', 'deleted_at', 'sku', 'is_master')
# Shallow Clone of the default price to populate the price field.
@object.default_price = @object.product.master.default_price.clone
end
def collection
@deleted = params.key?(:deleted) && params[:deleted] == "on" ? "checked" : ""

View File

@@ -78,7 +78,7 @@ module Spree
format.html do
if params.key?(:checkout)
@order.next_transition.run_callbacks if @order.cart?
redirect_to main_app.checkout_state_path(@order.checkout_steps.first)
redirect_to main_app.checkout_step_path(@order.checkout_steps.first)
elsif @order.complete?
redirect_to main_app.order_path(@order)
else

View File

@@ -34,7 +34,13 @@ class AngularFormBuilder < ActionView::Helpers::FormBuilder
options.reverse_merge!('id' => angular_id(method), 'ng-model' => angular_model(method).to_s)
@template.select_tag angular_name(method),
@template.ng_options_from_collection_for_select(collection, value_method, text_method, angular_field), options
@template.ng_options_from_collection_for_select(
collection,
value_method,
text_method,
angular_field
),
options
end
private

View File

@@ -89,16 +89,6 @@ module InjectionHelper
render partial: "json/injection_ams", locals: { name: "orderCycleData", json: json }
end
def inject_available_shipping_methods
inject_json_array "shippingMethods", available_shipping_methods,
Api::ShippingMethodSerializer, current_order: current_order
end
def inject_available_payment_methods
inject_json_array "paymentMethods", available_payment_methods,
Api::PaymentMethodSerializer, current_order: current_order
end
def inject_taxons
inject_json_array "taxons", Spree::Taxon.all.to_a, Api::TaxonSerializer
end

View File

@@ -53,7 +53,8 @@ module OrderCyclesHelper
end
def simple_index
@simple_index ||= !OpenFoodNetwork::Permissions.new(spree_current_user).can_manage_complex_order_cycles?
@simple_index ||=
!OpenFoodNetwork::Permissions.new(spree_current_user).can_manage_complex_order_cycles?
end
def pickup_time(order_cycle = current_order_cycle)
@@ -73,7 +74,8 @@ module OrderCyclesHelper
def validated_enterprise_options(enterprises, options = {})
enterprises.map do |e|
disabled_message = nil
if options[:shipping_and_payment_methods] && (e.shipping_methods.empty? || e.payment_methods.available.empty?)
if options[:shipping_and_payment_methods] &&
(e.shipping_methods.empty? || e.payment_methods.available.empty?)
if e.shipping_methods.empty? && e.payment_methods.available.empty?
disabled_message = I18n.t(:no_shipping_or_payment)
elsif e.shipping_methods.empty?

View File

@@ -5,11 +5,7 @@ module Spree
module ImagesHelper
def options_text_for(image)
if image.viewable.is_a?(Spree::Variant)
if image.viewable.is_master?
I18n.t(:all)
else
image.viewable.options_text
end
image.viewable.options_text
else
I18n.t(:all)
end

View File

@@ -26,11 +26,11 @@ module Spree
destination_url = options[:url] || spree.public_send("#{options[:route]}_path")
titleized_label = Spree.t(options[:label],
default: options[:label],
scope: [:admin, :tab]).titleize
scope: [:admin, :tab]).capitalize
css_classes = []
if options[:icon]
if options[:icon] && !feature?(:admin_style_v3, spree_current_user)
link = link_to_with_icon(options[:icon], titleized_label, destination_url)
css_classes << 'tab-with-icon'
else

View File

@@ -18,7 +18,9 @@ module Spree
def changeable_orders
# Only returns open order for the current user + shop + oc combo
return @changeable_orders unless @changeable_orders.nil?
return @changeable_orders = [] unless spree_current_user && current_distributor && current_order_cycle
unless spree_current_user && current_distributor && current_order_cycle
return @changeable_orders = []
end
return @changeable_orders = [] unless current_distributor.allow_order_changes?
@changeable_orders = Spree::Order.complete.where(

View File

@@ -6,16 +6,6 @@ module TermsAndConditionsHelper
rel: "noopener")
end
def render_terms_and_conditions
if platform_terms_required? && distributor_terms_required?
render("checkout/all_terms_and_conditions")
elsif platform_terms_required?
render "checkout/platform_terms_of_service"
elsif distributor_terms_required?
render "checkout/terms_and_conditions"
end
end
def any_terms_required?(distributor)
TermsOfService.required?(distributor)
end

View File

@@ -13,6 +13,8 @@ class BulkInvoiceJob < ApplicationJob
pdf << CombinePDF.parse(invoice)
end
ensure_directory_exists filepath
pdf.save filepath
broadcast(filepath, options[:channel]) if options[:channel]
@@ -41,4 +43,8 @@ class BulkInvoiceJob < ApplicationJob
).
broadcast
end
def ensure_directory_exists(filepath)
FileUtils.mkdir_p(File.dirname(filepath))
end
end

View File

@@ -1,6 +1,8 @@
# frozen_string_literal: true
class AdjustmentMetadata < ApplicationRecord
self.belongs_to_required_by_default = true
belongs_to :adjustment, class_name: 'Spree::Adjustment'
belongs_to :enterprise
end

View File

@@ -10,4 +10,12 @@ class ApplicationRecord < ActiveRecord::Base
include ArelHelpers::JoinAssociation
self.abstract_class = true
def self.image_service
ENV["S3_BUCKET"].present? ? :amazon_public : :local
end
def url_for(*args)
Rails.application.routes.url_helpers.url_for(*args)
end
end

View File

@@ -5,6 +5,8 @@ require 'open_food_network/column_preference_defaults'
class ColumnPreference < ApplicationRecord
extend OpenFoodNetwork::ColumnPreferenceDefaults
self.belongs_to_required_by_default = true
# Non-persisted attributes that only have one
# setting (ie. the default) for a given column
attr_accessor :name
@@ -48,6 +50,8 @@ class ColumnPreference < ApplicationRecord
def self.filter(default_preferences, user, action_name)
return unless action_name == 'order_cycles_index'
default_preferences.delete(:schedules) unless user.admin? || user.enterprises.where(enable_subscriptions: true).any?
return if user.admin? || user.enterprises.where(enable_subscriptions: true).any?
default_preferences.delete(:schedules)
end
end

View File

@@ -0,0 +1,42 @@
# frozen_string_literal: true
require 'active_support/concern'
module OrderValidations
extend ActiveSupport::Concern
private
def disallow_guest_order
return unless using_guest_checkout? && registered_email?
errors.add(:email, I18n.t('devise.failure.already_registered'))
end
# Check that line_items in the current order are available from a newly selected distribution
def products_available_from_new_distribution
return if OrderCycleDistributedVariants.new(order_cycle, distributor)
.distributes_order_variants?(self)
errors.add(:base, I18n.t(:spree_order_availability_error))
end
# Determine if email is required (we don't want validation errors before we hit the checkout)
def require_email
true unless (new_record? || cart?) && !checkout_processing
end
def ensure_line_items_present
return if line_items.present?
errors.add(:base, Spree.t(:there_are_no_items_for_this_order))
false
end
def ensure_available_shipping_rates
return unless shipments.empty? || shipments.any? { |shipment| shipment.shipping_rates.blank? }
errors.add(:base, Spree.t(:items_cannot_be_shipped))
false
end
end

View File

@@ -1,6 +1,8 @@
# frozen_string_literal: true
class CoordinatorFee < ApplicationRecord
self.belongs_to_required_by_default = true
belongs_to :order_cycle
belongs_to :enterprise_fee
end

View File

@@ -2,4 +2,6 @@
class CustomTab < ApplicationRecord
belongs_to :enterprise, optional: false
validates :title, presence: true, length: { maximum: 20 }
end

View File

@@ -10,20 +10,22 @@
class Customer < ApplicationRecord
include SetUnusedAddressFields
self.belongs_to_required_by_default = true
acts_as_taggable
searchable_attributes :first_name, :last_name, :email, :code
belongs_to :enterprise, optional: false
belongs_to :user, class_name: "Spree::User"
belongs_to :enterprise
belongs_to :user, class_name: "Spree::User", optional: true
has_many :orders, class_name: "Spree::Order"
before_destroy :update_orders_and_delete_canceled_subscriptions
belongs_to :bill_address, class_name: "Spree::Address"
belongs_to :bill_address, class_name: "Spree::Address", optional: true
alias_attribute :billing_address, :bill_address
accepts_nested_attributes_for :bill_address
belongs_to :ship_address, class_name: "Spree::Address"
belongs_to :ship_address, class_name: "Spree::Address", optional: true
alias_attribute :shipping_address, :ship_address
accepts_nested_attributes_for :ship_address

View File

@@ -2,6 +2,8 @@
class DistributorPaymentMethod < ApplicationRecord
self.table_name = "distributors_payment_methods"
self.belongs_to_required_by_default = true
belongs_to :payment_method, class_name: "Spree::PaymentMethod", touch: true
belongs_to :distributor, class_name: "Enterprise", touch: true
end

View File

@@ -2,6 +2,8 @@
class DistributorShippingMethod < ApplicationRecord
self.table_name = "distributors_shipping_methods"
self.belongs_to_required_by_default = true
belongs_to :shipping_method, class_name: "Spree::ShippingMethod", touch: true
belongs_to :distributor, class_name: "Enterprise", touch: true
end

View File

@@ -5,20 +5,9 @@ class Enterprise < ApplicationRecord
ENTERPRISE_SEARCH_RADIUS = 100
# The next Rails version will have named variants but we need to store them
# ourselves for now.
LOGO_SIZES = {
thumb: { gravity: "Center", resize: "100x100^", crop: '100x100+0+0' },
small: { gravity: "Center", resize: "180x180^", crop: '180x180+0+0' },
medium: { gravity: "Center", resize: "300x300^", crop: '300x300+0+0' },
}.freeze
PROMO_IMAGE_SIZES = {
thumb: { resize_to_limit: [100, 100] },
medium: { resize_to_fill: [720, 156] },
large: { resize_to_fill: [1200, 260] },
}.freeze
WHITE_LABEL_LOGO_SIZES = {
default: { gravity: "Center", resize_to_fill: [217, 44] },
mobile: { gravity: "Center", resize_to_fill: [75, 26] },
}.freeze
LOGO_SIZES = [:thumb, :small, :medium].freeze
PROMO_IMAGE_SIZES = [:thumb, :medium, :large].freeze
WHITE_LABEL_LOGO_SIZES = [:default, :mobile].freeze
VALID_INSTAGRAM_REGEX = %r{\A[a-zA-Z0-9._]{1,30}([^/-]*)\z}
searchable_attributes :sells, :is_primary_producer, :name
@@ -61,8 +50,10 @@ class Enterprise < ApplicationRecord
has_many :users, through: :enterprise_roles
belongs_to :owner, class_name: 'Spree::User',
inverse_of: :owned_enterprises
has_many :distributor_payment_methods, foreign_key: :distributor_id
has_many :distributor_shipping_methods, foreign_key: :distributor_id
has_many :distributor_payment_methods,
inverse_of: :distributor, foreign_key: :distributor_id
has_many :distributor_shipping_methods,
inverse_of: :distributor, foreign_key: :distributor_id
has_many :payment_methods, through: :distributor_payment_methods
has_many :shipping_methods, through: :distributor_shipping_methods
has_many :customers
@@ -87,10 +78,21 @@ class Enterprise < ApplicationRecord
}
accepts_nested_attributes_for :custom_tab
has_one_attached :logo
has_one_attached :promo_image
has_one_attached :terms_and_conditions
has_one_attached :white_label_logo
has_one_attached :logo, service: image_service do |attachment|
attachment.variant :thumb, resize_to_fill: [100, 100], crop: [0, 0, 100, 100]
attachment.variant :small, resize_to_fill: [180, 180], crop: [0, 0, 180, 180]
attachment.variant :medium, resize_to_fill: [300, 300], crop: [0, 0, 300, 300]
end
has_one_attached :promo_image, service: image_service do |attachment|
attachment.variant :thumb, resize_to_limit: [100, 100]
attachment.variant :medium, resize_to_fill: [720, 156]
attachment.variant :large, resize_to_fill: [1200, 260]
end
has_one_attached :white_label_logo, service: image_service do |attachment|
attachment.variant :default, resize_to_fill: [217, 44]
attachment.variant :mobile, resize_to_fill: [75, 26]
end
validates :logo,
processable_image: true,
@@ -117,6 +119,7 @@ class Enterprise < ApplicationRecord
with: VALID_INSTAGRAM_REGEX,
message: Spree.t('errors.messages.invalid_instagram_url')
}, allow_blank: true
validate :validate_white_label_logo_link
before_validation :initialize_permalink, if: lambda { permalink.nil? }
before_validation :set_unused_address_fields
@@ -157,7 +160,7 @@ class Enterprise < ApplicationRecord
scope :is_distributor, -> { where('sells != ?', 'none') }
scope :is_hub, -> { where(sells: 'any') }
scope :supplying_variant_in, lambda { |variants|
joins(supplied_products: :variants_including_master).
joins(supplied_products: :variants).
where('spree_variants.id IN (?)', variants).
select('DISTINCT enterprises.*')
}
@@ -294,27 +297,15 @@ class Enterprise < ApplicationRecord
end
def logo_url(name)
return unless logo.variable?
Rails.application.routes.url_helpers.url_for(
logo.variant(LOGO_SIZES[name])
)
image_url_for(logo, name)
end
def promo_image_url(name)
return unless promo_image.variable?
Rails.application.routes.url_helpers.url_for(
promo_image.variant(PROMO_IMAGE_SIZES[name])
)
image_url_for(promo_image, name)
end
def white_label_logo_url(name = :default)
return unless white_label_logo.variable?
Rails.application.routes.url_helpers.url_for(
white_label_logo.variant(WHITE_LABEL_LOGO_SIZES[name])
)
image_url_for(white_label_logo, name)
end
def website
@@ -398,7 +389,7 @@ class Enterprise < ApplicationRecord
def current_distributed_taxons
Spree::Taxon
.select("DISTINCT spree_taxons.*")
.joins(products: :variants_including_master)
.joins(products: :variants)
.joins("INNER JOIN (#{current_exchange_variants.to_sql}) \
AS exchange_variants ON spree_variants.id = exchange_variants.variant_id")
end
@@ -454,6 +445,29 @@ class Enterprise < ApplicationRecord
private
def validate_white_label_logo_link
return if white_label_logo.blank?
return if white_label_logo_link.blank?
white_label_logo_link.strip!
uri = URI(white_label_logo_link)
self.white_label_logo_link = "http://#{white_label_logo_link}" if uri.scheme.nil?
rescue URI::InvalidURIError
errors.add(:white_label_logo_link, I18n.t(:invalid_url))
end
def image_url_for(image, name)
return unless image.variable?
return image.variant(name).processed.url if image.attachment.service.name == :amazon_public
url_for(image.variant(name))
rescue ActiveStorage::Error => e
Rails.logger.error(e.message)
nil
end
def current_exchange_variants
ExchangeVariant.joins(exchange: :order_cycle)
.merge(Exchange.outgoing)

View File

@@ -25,8 +25,8 @@ class EnterpriseGroup < ApplicationRecord
delegate :phone, :address1, :address2, :city, :zipcode, :state, :country, to: :address
has_one_attached :logo
has_one_attached :promo_image
has_one_attached :logo, service: image_service
has_one_attached :promo_image, service: image_service
validates :logo,
processable_image: true,

View File

@@ -55,7 +55,7 @@ class Exchange < ApplicationRecord
}
scope :with_product, lambda { |product|
joins(:exchange_variants).
where('exchange_variants.variant_id IN (?)', product.variants_including_master.select(&:id))
where('exchange_variants.variant_id IN (?)', product.variants.select(&:id))
}
scope :by_enterprise_name, -> {
joins('INNER JOIN enterprises AS sender ON (sender.id = exchanges.sender_id)').

View File

@@ -55,7 +55,6 @@ module ProductImport
VariantOverride.for_hubs([enterprise_id]).count
else
Spree::Variant.
not_master.
joins(:product).
where('spree_products.supplier_id IN (?)', enterprise_id).
count
@@ -90,7 +89,8 @@ module ProductImport
end
def total_saved_count
@products_created + @variants_created + @variants_updated + @inventory_created + @inventory_updated
[@products_created, @variants_created, @variants_updated,
@inventory_created, @inventory_updated].sum
end
def permission_by_id?(enterprise_id)

View File

@@ -167,7 +167,7 @@ module ProductImport
def unit_fields_validation(entry)
unit_types = ['g', 'oz', 'lb', 'kg', 't', 'ml', 'l', 'kl', '']
unless entry.units&.present?
if entry.units.blank?
mark_as_invalid(entry, attribute: 'units',
error: I18n.t('admin.product_import.model.blank'))
end
@@ -180,7 +180,7 @@ module ProductImport
return if import_into_inventory?
# unit_type must be valid type
if entry.unit_type&.present?
if entry.unit_type.present?
unit_type = entry.unit_type.to_s.strip.downcase
unless unit_types.include?(unit_type)
mark_as_invalid(entry, attribute: 'unit_type',
@@ -190,7 +190,7 @@ module ProductImport
end
# variant_unit_name must be present if unit_type not present
return if entry.variant_unit_name&.present?
return if entry.variant_unit_name.present?
mark_as_invalid(entry, attribute: 'variant_unit_name',
error: I18n.t('admin.product_import.model.conditional_blank'))

View File

@@ -233,6 +233,8 @@ module ProductImport
def rows
return [] unless @sheet&.last_row
@sheet.parse(clean: true)
(2..@sheet.last_row).map do |i|
@sheet.row(i)
end

View File

@@ -2,14 +2,12 @@
module Spree
class Image < Asset
SIZES = {
mini: { resize_to_fill: [48, 48] },
small: { resize_to_fill: [227, 227] },
product: { resize_to_limit: [240, 240] },
large: { resize_to_limit: [600, 600] },
}.freeze
has_one_attached :attachment
has_one_attached :attachment, service: image_service do |attachment|
attachment.variant :mini, resize_to_fill: [48, 48]
attachment.variant :small, resize_to_fill: [227, 227]
attachment.variant :product, resize_to_limit: [240, 240]
attachment.variant :large, resize_to_limit: [600, 600]
end
validates :attachment,
attached: true,
@@ -17,20 +15,33 @@ module Spree
content_type: %r{\Aimage/(png|jpeg|gif|jpg|svg\+xml|webp)\Z}
validate :no_attachment_errors
def self.default_image_url(size)
return "/noimage/product.png" unless size&.to_sym.in?([:mini, :small, :product, :large])
"/noimage/#{size}.png"
end
def variant(name)
if attachment.variable?
attachment.variant(SIZES[name])
attachment.variant(name)
else
attachment
end
end
def url(size)
return unless attachment.attached?
return self.class.default_image_url(size) unless attachment.attached?
return variant(size).processed.url if attachment.service.name == :amazon_public
Rails.application.routes.url_helpers.url_for(variant(size))
url_for(variant(size))
rescue ActiveStorage::Error => e
Rails.logger.error(e.message)
self.class.default_image_url(size)
end
private
# if there are errors from the plugin, then add a more meaningful message
def no_attachment_errors
return if errors[:attachment].empty?

View File

@@ -8,6 +8,7 @@ require 'open_food_network/tag_rule_applicator'
module Spree
class Order < ApplicationRecord
include OrderShipment
include OrderValidations
include Checkout
include Balance
include SetUnusedAddressFields
@@ -24,9 +25,7 @@ module Spree
order.update_totals
order.payment_required?
}
go_to_state :confirmation, if: ->(order) {
OpenFoodNetwork::FeatureToggle.enabled? :split_checkout, order.created_by
}
go_to_state :confirmation
go_to_state :complete
end
@@ -83,13 +82,13 @@ module Spree
accepts_nested_attributes_for :shipments
delegate :admin_and_handling_total, :payment_fee, :ship_total, to: :adjustments_fetcher
delegate :update_totals, to: :updater
delegate :update_totals, :update_totals_and_states, to: :updater
delegate :create_line_item_fees!, :create_order_fees!, :update_order_fees!,
:update_line_item_fees!, :recreate_all_fees!, to: :fee_handler
# Needs to happen before save_permalink is called
before_validation :set_currency
before_validation :generate_order_number, on: :create
before_validation :generate_order_number, if: :new_record?
before_validation :clone_billing_address, if: :use_billing?
before_validation :ensure_customer
@@ -104,8 +103,9 @@ module Spree
validates :email, presence: true,
format: /\A([\w.%+\-']+)@([\w\-]+\.)+(\w{2,})\z/i,
if: :require_email
validates :order_cycle, presence: true, on: :set_distribution_step
validates :distributor, presence: true, on: :set_distribution_step
validates :order_cycle, presence: true, on: :require_distribution
validates :distributor, presence: true, on: :require_distribution
make_permalink field: :number
@@ -290,8 +290,9 @@ module Spree
created_by_id: created_by_id)
end
# FIXME refactor this method and implement validation using validates_* utilities
def generate_order_number
return if number.present?
record = true
while record
random = "R#{Array.new(9){ rand(9) }.join}"
@@ -301,10 +302,6 @@ module Spree
number
end
def shipped_shipments
shipments.shipped
end
def contains?(variant)
find_line_item_by_variant(variant).present?
end
@@ -320,8 +317,7 @@ module Spree
# Creates new tax charges if there are any applicable rates. If prices already
# include taxes then price adjustments are created instead.
def create_tax_charge!
return if state.in?(["cart", "address", "delivery"]) &&
OpenFoodNetwork::FeatureToggle.enabled?(:split_checkout)
return if state.in?(["cart", "address", "delivery"])
clear_legacy_taxes!
@@ -341,11 +337,6 @@ module Spree
complete? || resumed? || awaiting_return? || returned?
end
def credit_cards
credit_card_ids = payments.from_credit_card.pluck(:source_id).uniq
CreditCard.where(id: credit_card_ids)
end
# Finalizes an in progress order after checkout is complete.
# Called after transition to complete state when payments will have been processed
def finalize!
@@ -374,13 +365,6 @@ module Spree
)
end
def deliver_order_confirmation_email
return if subscription.present?
Spree::OrderMailer.confirm_email_for_customer(id).deliver_later(wait: 10.seconds)
Spree::OrderMailer.confirm_email_for_shop(id).deliver_later(wait: 10.seconds)
end
# Helper methods for checkout steps
def paid?
payment_state == 'paid' || payment_state == 'credit_owed'
@@ -442,19 +426,6 @@ module Spree
restart_checkout_flow if state.in?(["payment", "confirmation"])
end
def state_changed(name)
state = "#{name}_state"
return unless persisted?
old_state = __send__("#{state}_was")
state_changes.create(
previous_state: old_state,
next_state: __send__(state),
name: name,
user_id: user_id
)
end
def shipped?
%w(partial shipped).include?(shipment_state)
end
@@ -508,24 +479,6 @@ module Spree
end
end
def refresh_shipment_rates
shipments.map(&:refresh_rates)
end
# Check that line_items in the current order are available from a newly selected distribution
def products_available_from_new_distribution
return if OrderCycleDistributedVariants.new(order_cycle, distributor)
.distributes_order_variants?(self)
errors.add(:base, I18n.t(:spree_order_availability_error))
end
def disallow_guest_order
return unless using_guest_checkout? && registered_email?
errors.add(:email, I18n.t('devise.failure.already_registered'))
end
# After changing line items of a completed order
def update_shipping_fees!
shipments.each do |shipment|
@@ -587,10 +540,6 @@ module Spree
save!
end
def distribution_set?
distributor && order_cycle
end
def shipping_tax
shipment_adjustments.reload.tax.sum(:amount)
end
@@ -627,6 +576,13 @@ module Spree
private
def deliver_order_confirmation_email
return if subscription.present?
Spree::OrderMailer.confirm_email_for_customer(id).deliver_later(wait: 10.seconds)
Spree::OrderMailer.confirm_email_for_shop(id).deliver_later(wait: 10.seconds)
end
def fee_handler
@fee_handler ||= OrderFeesHandler.new(self)
end
@@ -656,38 +612,6 @@ module Spree
self.email = user.email if user
end
# Determine if email is required (we don't want validation errors before we hit the checkout)
def require_email
return true unless (new_record? || cart?) && !checkout_processing
end
def ensure_line_items_present
return if line_items.present?
errors.add(:base, Spree.t(:there_are_no_items_for_this_order)) && (return false)
end
def ensure_available_shipping_rates
return unless shipments.empty? || shipments.any? { |shipment| shipment.shipping_rates.blank? }
errors.add(:base, Spree.t(:items_cannot_be_shipped)) && (return false)
end
def after_cancel
shipments.each(&:cancel!)
payments.checkout.each(&:void!)
OrderMailer.cancel_email(id).deliver_later if send_cancellation_email
update(payment_state: updater.update_payment_state)
end
def after_resume
shipments.each(&:resume!)
payments.void.each(&:resume!)
update(payment_state: updater.update_payment_state)
end
def use_billing?
@use_billing == true || @use_billing == 'true' || @use_billing == '1'
end
@@ -725,7 +649,7 @@ module Spree
return if adjustment.finalized?
adjustment.update_adjustment!(force: true)
updater.update_totals_and_states
update_totals_and_states
end
end
end

View File

@@ -75,9 +75,9 @@ module Spree
before_transition to: :delivery, do: :create_proposed_shipments
before_transition to: :delivery, do: :ensure_available_shipping_rates
before_transition to: :payment, do: :create_tax_charge!
before_transition to: :confirmation, do: :validate_payment_method!
after_transition to: :payment, do: :create_tax_charge!
after_transition to: :complete, do: :finalize!
after_transition to: :resumed, do: :after_resume
after_transition to: :canceled, do: :after_cancel
@@ -96,14 +96,6 @@ module Spree
end
end
def self.find_transition(options = {})
return nil if options.nil? || !options.include?(:from) || !options.include?(:to)
next_event_transitions.detect do |transition|
transition[options[:from].to_sym] == options[:to].to_sym
end
end
def self.next_event_transitions
@next_event_transitions ||= []
end
@@ -136,8 +128,36 @@ module Spree
)
end
def state_changed(name)
state = "#{name}_state"
return unless persisted?
old_state = __send__("#{state}_was")
state_changes.create(
previous_state: old_state,
next_state: __send__(state),
name: name,
user_id: user_id
)
end
private
def after_cancel
shipments.each(&:cancel!)
payments.checkout.each(&:void!)
OrderMailer.cancel_email(id).deliver_later if send_cancellation_email
update(payment_state: updater.update_payment_state)
end
def after_resume
shipments.each(&:resume!)
payments.void.each(&:resume!)
update(payment_state: updater.update_payment_state)
end
def validate_payment_method!
return unless checkout_processing
return if payments.any?

View File

@@ -1,5 +1,7 @@
# frozen_string_literal: true
require "spree/localized_number"
module Spree
class Payment < ApplicationRecord
include Spree::Payment::Processing

View File

@@ -50,9 +50,9 @@ module Spree
scope :by_name, -> { order('spree_payment_methods.name ASC') }
scope :available, lambda { |display_on = 'both'|
where(active: true).
where('spree_payment_methods.display_on=? OR spree_payment_methods.display_on=? OR spree_payment_methods.display_on IS NULL', display_on, '').
where('spree_payment_methods.environment=? OR spree_payment_methods.environment=? OR spree_payment_methods.environment IS NULL', Rails.env, '')
where(active: true)
.where(display_on: [display_on, "", nil])
.where(environment: [Rails.env, "", nil])
}
def self.providers

View File

@@ -28,42 +28,73 @@ module Spree
acts_as_paranoid
searchable_attributes :supplier_id, :primary_taxon_id, :meta_keywords
searchable_associations :supplier, :properties, :primary_taxon, :variants, :master
searchable_attributes :supplier_id, :primary_taxon_id, :meta_keywords, :sku
searchable_associations :supplier, :properties, :primary_taxon, :variants
searchable_scopes :active, :with_properties
has_many :product_properties, dependent: :destroy
has_many :properties, through: :product_properties
has_many :classifications, dependent: :delete_all
has_many :taxons, through: :classifications
belongs_to :tax_category, class_name: 'Spree::TaxCategory'
belongs_to :shipping_category, class_name: 'Spree::ShippingCategory'
belongs_to :supplier, class_name: 'Enterprise', touch: true
belongs_to :primary_taxon, class_name: 'Spree::Taxon', touch: true
has_one :master,
-> { where is_master: true },
class_name: 'Spree::Variant',
dependent: :destroy
has_one :image, class_name: "Spree::Image", as: :viewable, dependent: :destroy
has_many :variants, -> {
where(is_master: false).order("spree_variants.position ASC")
}, class_name: 'Spree::Variant'
has_many :variants_including_master,
-> { order("spree_variants.position ASC") },
class_name: 'Spree::Variant',
dependent: :destroy
has_many :product_properties, dependent: :destroy
has_many :properties, through: :product_properties
has_many :classifications, dependent: :delete_all
has_many :taxons, through: :classifications
has_many :variants, -> { order("spree_variants.position ASC") }, class_name: 'Spree::Variant',
dependent: :destroy
has_many :prices, -> {
order('spree_variants.position, spree_variants.id, currency')
}, through: :variants
has_many :stock_items, through: :variants
has_many :supplier_properties, through: :supplier, source: :properties
has_many :variant_images, -> { order(:position) }, source: :images,
through: :variants
validates :name, presence: true
validates :permalink, presence: true
validates :shipping_category, presence: true
validates :supplier, presence: true
validates :primary_taxon, presence: true
validates :tax_category, presence: true,
if: proc { Spree::Config[:products_require_tax_category] }
validates :variant_unit, presence: true
validates :unit_value, presence:
{ if: ->(p) { %w(weight volume).include?(p.variant_unit) && new_record? } }
validates :variant_unit_scale,
presence: { if: ->(p) { %w(weight volume).include? p.variant_unit } }
validates :variant_unit_name,
presence: { if: ->(p) { p.variant_unit == 'items' } }
validate :validate_image
accepts_nested_attributes_for :variants, allow_destroy: true
accepts_nested_attributes_for :image
accepts_nested_attributes_for :product_properties,
allow_destroy: true,
reject_if: lambda { |pp| pp[:property_name].blank? }
# Transient attributes used temporarily when creating a new product,
# these values are persisted on the product's variant
attr_accessor :price, :display_as, :unit_value, :unit_description
make_permalink order: :name
after_initialize :set_available_on_to_now, if: :new_record?
before_validation :sanitize_permalink
before_save :add_primary_taxon_to_taxons
before_destroy :punch_permalink
after_save :remove_previous_primary_taxon_from_taxons
after_create :ensure_standard_variant
after_save :update_units
scope :with_properties, ->(*property_ids) {
left_outer_joins(:product_properties).
@@ -75,58 +106,6 @@ module Spree
)
}
delegate_belongs_to :master, :sku, :price, :currency, :display_amount, :display_price, :weight,
:height, :width, :depth, :is_master, :cost_currency,
:price_in, :amount_in, :unit_value, :unit_description
delegate :images_attributes=, :display_as=, to: :master
after_create :set_master_variant_defaults
after_save :save_master
delegate :images, to: :master, prefix: true
alias_method :images, :master_images
has_many :variant_images, -> { order(:position) }, source: :images,
through: :variants_including_master
accepts_nested_attributes_for :variants, allow_destroy: true
validates :name, presence: true
validates :permalink, presence: true
validates :price, presence: true, if: proc { Spree::Config[:require_master_price] }
validates :shipping_category, presence: true
validates :supplier, presence: true
validates :primary_taxon, presence: true
validates :tax_category, presence: true,
if: proc { Spree::Config[:products_require_tax_category] }
validates :variant_unit, presence: true
validates :unit_value, presence: { if: ->(p) { %w(weight volume).include? p.variant_unit } }
validates :variant_unit_scale,
presence: { if: ->(p) { %w(weight volume).include? p.variant_unit } }
validates :variant_unit_name,
presence: { if: ->(p) { p.variant_unit == 'items' } }
validate :validate_image_for_master
accepts_nested_attributes_for :product_properties,
allow_destroy: true,
reject_if: lambda { |pp| pp[:property_name].blank? }
make_permalink order: :name
after_initialize :ensure_master
after_initialize :set_available_on_to_now, if: :new_record?
before_validation :sanitize_permalink
before_save :add_primary_taxon_to_taxons
after_save :remove_previous_primary_taxon_from_taxons
after_save :ensure_standard_variant
after_save :update_units
before_destroy :punch_permalink
# -- Joins
scope :with_order_cycles_outer, -> {
joins("
LEFT OUTER JOIN spree_variants AS o_spree_variants
@@ -150,7 +129,7 @@ module Spree
}
scope :with_order_cycles_inner, -> {
joins(variants_including_master: { exchanges: :order_cycle })
joins(variants: { exchanges: :order_cycle })
}
scope :visible_for, lambda { |enterprise|
@@ -283,13 +262,6 @@ module Spree
stock_items.sum(&:count_on_hand)
end
# Master variant may be deleted (i.e. when the product is deleted)
# which would make AR's default finder return nil.
# This is a stopgap for that little problem.
def master
super || variants_including_master.with_deleted.find_by(is_master: true)
end
def properties_including_inherited
# Product properties override producer properties
ps = product_properties.all
@@ -325,7 +297,7 @@ module Spree
touch_distributors
ExchangeVariant.
where('exchange_variants.variant_id IN (?)', variants_including_master.with_deleted.
where('exchange_variants.variant_id IN (?)', variants.with_deleted.
select(:id)).destroy_all
super
@@ -334,39 +306,6 @@ module Spree
private
# ensures the master variant is flagged as such
def set_master_variant_defaults
master.is_master = true
end
# Here we rescue errors when saving master variants (without the need for a
# validates_associated on master) and we get more specific data about the errors
def save_master
if master && (
master.changed? || master.new_record? || (
master.default_price && (
master.default_price.changed? || master.default_price.new_record?
)
)
)
master.save!
end
# If the master cannot be saved, the Product object will get its errors
# and will be destroyed
rescue ActiveRecord::RecordInvalid
master.errors.each do |error|
errors.add error.attribute, error.message
end
raise
end
def ensure_master
return unless new_record?
self.master ||= Variant.new
end
def punch_permalink
# Punch permalink with date prefix
update_attribute :permalink, "#{Time.now.to_i}_#{permalink}"
@@ -379,7 +318,7 @@ module Spree
def update_units
return unless saved_change_to_variant_unit? || saved_change_to_variant_unit_name?
variants_including_master.each(&:update_units)
variants.each(&:update_units)
end
def touch_distributors
@@ -397,11 +336,14 @@ module Spree
end
def ensure_standard_variant
return unless master.valid? && variants.empty?
return unless variants.empty?
variant = master.dup
variant = Spree::Variant.new
variant.product = self
variant.is_master = false
variant.price = price
variant.display_as = display_as
variant.unit_value = unit_value
variant.unit_description = unit_description
variants << variant
end
@@ -413,8 +355,8 @@ module Spree
self.permalink = create_unique_permalink(requested.parameterize)
end
def validate_image_for_master
return if master.images.all?(&:valid?)
def validate_image
return if image.blank? || image.valid?
errors.add(:base, I18n.t('spree.admin.products.image_not_processable'))
end

View File

@@ -63,7 +63,7 @@ module Spree
end
def returnable_inventory
order.shipped_shipments.collect{ |s| s.inventory_units.to_a }.flatten
order.shipments.shipped.collect{ |s| s.inventory_units.to_a }.flatten
end
# Used when Adjustment#update_adjustment! wants to update the related adjustment
@@ -74,7 +74,7 @@ module Spree
private
def must_have_shipped_units
return unless order.nil? || order.shipped_shipments.none?
return unless order.nil? || order.shipments.shipped.none?
errors.add(:order, Spree.t(:has_no_shipped_units))
end

View File

@@ -8,6 +8,8 @@ module Spree
back_end: "back_end"
}.freeze
self.belongs_to_required_by_default = true
acts_as_paranoid
acts_as_taggable
@@ -25,7 +27,7 @@ module Spree
has_and_belongs_to_many :zones, join_table: 'spree_shipping_methods_zones',
class_name: 'Spree::Zone'
belongs_to :tax_category, class_name: 'Spree::TaxCategory'
belongs_to :tax_category, class_name: 'Spree::TaxCategory', optional: true
validates :name, presence: true
validate :distributor_validation

View File

@@ -79,7 +79,7 @@ module Spree
taxons = Spree::Taxon
.select("DISTINCT spree_taxons.id, ents_and_vars.enterprise_id")
.joins(products: :variants_including_master)
.joins(products: :variants)
.joins("
INNER JOIN (#{ents_and_vars.to_sql}) AS ents_and_vars
ON spree_variants.id = ents_and_vars.variant_id")

View File

@@ -13,6 +13,8 @@ module Spree
acts_as_paranoid
self.ignored_columns = [:is_master]
searchable_attributes :sku, :display_as, :display_name
searchable_associations :product, :default_price
searchable_scopes :active, :deleted
@@ -53,10 +55,9 @@ module Spree
localize_number :price, :weight
validate :check_price
validate :check_currency
validates :price, numericality: { greater_than_or_equal_to: 0 },
presence: true,
if: proc { Spree::Config[:require_master_price] }
presence: true
validates :unit_value, presence: true, if: ->(variant) {
%w(weight volume).include?(variant.product&.variant_unit)
@@ -89,7 +90,6 @@ module Spree
scope :with_order_cycles_inner, -> { joins(exchanges: :order_cycle) }
scope :not_master, -> { where(is_master: false) }
scope :in_order_cycle, lambda { |order_cycle|
with_order_cycles_inner.
merge(Exchange.outgoing).
@@ -198,15 +198,7 @@ module Spree
private
# Ensures a new variant takes the product master price when price is not supplied
def check_price
if price.nil? && Spree::Config[:require_master_price]
raise 'No master variant found to infer price' unless product&.master
raise 'Must supply price for variant or master.price for product.' if self == product.master
self.price = product.master.price
end
def check_currency
return unless currency.nil?
self.currency = Spree::Config[:currency]

View File

@@ -96,9 +96,9 @@ module Api
def attachment_urls(attachment, styles)
return unless attachment.variable?
styles.transform_values do |transformation|
styles.index_with do |style|
Rails.application.routes.url_helpers.
url_for(attachment.variant(transformation))
url_for(attachment.variant(style))
end
end
end

View File

@@ -4,18 +4,14 @@ module Api
module Admin
module ForOrderCycle
class SuppliedProductSerializer < ActiveModel::Serializer
attributes :name, :supplier_name, :image_url, :master_id, :variants
attributes :name, :supplier_name, :image_url, :variants
def supplier_name
object.supplier&.name
end
def image_url
object.images.first&.url(:mini)
end
def master_id
object.master.id
object.image&.url(:mini)
end
def variants

View File

@@ -5,7 +5,7 @@ module Api
class ProductSerializer < ActiveModel::Serializer
attributes :id, :name, :sku, :variant_unit, :variant_unit_scale, :variant_unit_name,
:inherits_properties, :on_hand, :price, :available_on, :permalink_live,
:tax_category_id, :import_date, :image_url, :thumb_url, :variants, :master
:tax_category_id, :import_date, :image_url, :thumb_url, :variants
has_one :supplier, key: :producer_id, embed: :id
has_one :primary_taxon, key: :category_id, embed: :id
@@ -19,19 +19,12 @@ module Api
)
end
def master
Api::Admin::VariantSerializer.new(
object.master,
image: thumb_url
)
end
def image_url
object.images.first&.url(:product) || "/noimage/product.png"
object.image&.url(:product) || Spree::Image.default_image_url(:product)
end
def thumb_url
object.images.first&.url(:mini) || "/noimage/mini.png"
object.image&.url(:mini) || Spree::Image.default_image_url(:mini)
end
def on_hand

View File

@@ -15,9 +15,12 @@ module Api
end
def in_open_and_upcoming_order_cycles
OrderManagement::Subscriptions::VariantsList.in_open_and_upcoming_order_cycles?(option_or_assigned_shop,
option_or_assigned_schedule,
object.variant)
OrderManagement::Subscriptions::VariantsList
.in_open_and_upcoming_order_cycles?(
option_or_assigned_shop,
option_or_assigned_schedule,
object.variant
)
end
private

View File

@@ -33,7 +33,7 @@ module Api
end
def image
options[:image] || object.product.images.first&.url(:mini)
options[:image] || object.product.image&.url(:mini)
end
def in_stock

View File

@@ -12,7 +12,7 @@ class Api::ProductSerializer < ActiveModel::Serializer
has_one :primary_taxon, serializer: Api::TaxonSerializer
has_many :taxons, serializer: Api::IdSerializer
has_many :images, serializer: Api::ImageSerializer
has_one :image, serializer: Api::ImageSerializer
has_one :supplier, serializer: Api::IdSerializer
# return an unformatted descripton

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
class Api::VariantSerializer < ActiveModel::Serializer
attributes :id, :is_master, :product_name, :sku,
attributes :id, :product_name, :sku,
:options_text, :unit_value, :unit_description, :unit_to_display,
:display_as, :display_name, :name_to_display,
:price, :on_demand, :on_hand,
@@ -40,7 +40,7 @@ class Api::VariantSerializer < ActiveModel::Serializer
end
def thumb_url
object.product.images.first&.url(:mini) || "/noimage/mini.png"
object.product.image&.url(:mini) || Spree::Image.default_image_url(:mini)
end
def unit_price_price

View File

@@ -19,7 +19,7 @@ class CacheService
# Gets the :updated_at value of the most recently updated record for a given class, and returns
# it as a timestamp, eg: `1583836069`.
def self.latest_timestamp_by_class(cached_class)
cached_class.maximum(:updated_at).to_i
cached_class.maximum(:updated_at).to_f
end
def self.home_stats(statistic, &block)

View File

@@ -1,85 +0,0 @@
# frozen_string_literal: true
# Adapts checkout form data (params) so that the order can be directly saved to the database
module Checkout
class FormDataAdapter
attr_reader :params, :shipping_method_id
def initialize(params, order, current_user)
@params = params.deep_dup.to_h.with_indifferent_access
@order = order
@current_user = current_user
move_payment_source_to_payment_attributes!
fill_in_card_type
set_amount_in_payments_attributes
construct_saved_card_attributes if @params.dig(:order, :existing_card_id)
@shipping_method_id = @params[:order]&.delete(:shipping_method_id)
end
private
# For payment step, filter order parameters to produce the expected
# nested attributes for a single payment and its source,
# discarding attributes for payment methods other than the one selected
def move_payment_source_to_payment_attributes!
return unless @params[:payment_source].present? &&
payment_source_params = delete_payment_source_params!
@params.dig(:order, :payments_attributes).first[:source_attributes] = payment_source_params
end
# Ensures cc_type is always passed to the model by inferring the type when
# the frontend didn't provide it.
def fill_in_card_type
return unless payment_source_attributes
return if payment_source_attributes.dig(:number).blank?
payment_source_attributes[:cc_type] ||= card_brand(payment_source_attributes[:number])
end
def payment_source_attributes
@payment_source_attributes ||=
@params.dig(:order, :payments_attributes)&.first&.dig(:source_attributes)
end
def card_brand(number)
ActiveMerchant::Billing::CreditCard.brand?(number)
end
def delete_payment_source_params!
@params.delete(:payment_source)[
@params.dig(:order, :payments_attributes).first[:payment_method_id].underscore
]
end
def set_amount_in_payments_attributes
return unless @params.dig(:order, :payments_attributes)
@params.dig(:order, :payments_attributes).first[:amount] = @order.total
end
def construct_saved_card_attributes
existing_card_id = @params[:order].delete(:existing_card_id)
return if existing_card_id.blank?
add_to_payment_attributes(existing_card_id)
@params.dig(:order, :payments_attributes).first.delete :source_attributes
end
def add_to_payment_attributes(existing_card_id)
credit_card = Spree::CreditCard.find(existing_card_id)
if credit_card.try(:user_id).blank? || credit_card.user_id != @current_user.try(:id)
raise Spree::Core::GatewayError, I18n.t(:invalid_credit_card)
end
@params.dig(:order, :payments_attributes).first[:source] = credit_card
end
end
end

View File

@@ -30,7 +30,9 @@ module Checkout
def set_customer_terms_and_conditions_accepted_at(params)
return unless params[:order]
@order.customer.update(terms_and_conditions_accepted_at: Time.zone.now) if params[:order][:terms_and_conditions_accepted]
return unless params[:order][:terms_and_conditions_accepted]
@order.customer.update(terms_and_conditions_accepted_at: Time.zone.now)
end
end
end

View File

@@ -18,7 +18,6 @@ class ExchangeProductsRenderer
def exchange_variants(incoming, enterprise)
variants_relation = Spree::Variant.
not_master.
where(product_id: exchange_products(incoming, enterprise).select(&:id))
filter_visible(variants_relation)
@@ -96,7 +95,7 @@ class ExchangeProductsRenderer
return enterprises if enterprises.empty?
enterprises.includes(
supplied_products: [:supplier, :variants, { master: [:images] }]
supplied_products: [:supplier, :variants, :image]
)
end
end

View File

@@ -8,8 +8,8 @@ class ImageImporter
Spree::Image.create(
attachment: { io: file, filename: filename },
viewable_id: product.master.id,
viewable_type: Spree::Variant,
viewable_id: product.id,
viewable_type: Spree::Product,
)
end
end

View File

@@ -24,6 +24,8 @@ class OrderWorkflow
end
def advance_to_payment
return unless order.state.in? ["cart", "address", "delivery"]
advance_to_state("payment", advance_order_options)
end

View File

@@ -1,25 +0,0 @@
# frozen_string_literal: true
module PermittedAttributes
class Checkout
def initialize(params)
@params = params
end
def call
@params.permit(
order: [
:email, :special_instructions,
:existing_card_id, :shipping_method_id,
{ payments_attributes: [
:payment_method_id,
{ source_attributes: PermittedAttributes::PaymentSource.attributes }
],
ship_address_attributes: PermittedAttributes::Address.attributes,
bill_address_attributes: PermittedAttributes::Address.attributes }
],
payment_source: PermittedAttributes::PaymentSource.attributes
)
end
end
end

View File

@@ -11,7 +11,7 @@ module PermittedAttributes
:meta_keywords, :notes, :inherits_properties,
{ product_properties_attributes: [:id, :property_name, :value],
variants_attributes: [PermittedAttributes::Variant.attributes],
images_attributes: [:attachment] }
image_attributes: [:attachment] }
]
end
end

View File

@@ -56,8 +56,9 @@ class ProcessPaymentIntent
attr_reader :order, :payment_intent, :payment
def process_payment
OrderWorkflow.new(order).next if order.state == "payment"
order.process_payments!
return unless order.process_payments!
OrderWorkflow.new(order).complete
end
def ready_for_capture?

View File

@@ -68,12 +68,14 @@ class ProductsRenderer
end
def products_order
if distributor.preferred_shopfront_product_sorting_method == "by_producer" && distributor.preferred_shopfront_producer_order.present?
if (distributor.preferred_shopfront_product_sorting_method == "by_producer") &&
distributor.preferred_shopfront_producer_order.present?
distributor
.preferred_shopfront_producer_order
.split(",").map { |id| "spree_products.supplier_id=#{id} DESC" }
.join(", ") + ", spree_products.name ASC, spree_products.id ASC"
elsif distributor.preferred_shopfront_product_sorting_method == "by_category" && distributor.preferred_shopfront_taxon_order.present?
elsif distributor.preferred_shopfront_product_sorting_method == "by_category" &&
distributor.preferred_shopfront_taxon_order.present?
distributor
.preferred_shopfront_taxon_order
.split(",").map { |id| "spree_products.primary_taxon_id=#{id} DESC" }
@@ -95,7 +97,7 @@ class ProductsRenderer
end
def variants_for_shop_by_id
index_by_product_id variants_for_shop.reject(&:is_master)
index_by_product_id variants_for_shop
end
def index_by_product_id(variants)

View File

@@ -100,7 +100,7 @@ module Sets
end
def create_or_update_variant(product, variant_attributes)
variant = find_model(product.variants_including_master, variant_attributes[:id])
variant = find_model(product.variants, variant_attributes[:id])
if variant.present?
variant.update(variant_attributes.except(:id))
else

View File

@@ -22,7 +22,8 @@ module VariantUnits
end
def product_and_full_name
return "#{product.name} - #{full_name}" unless full_name.start_with? product.name
return product.name if full_name.blank?
return "#{product.name} - #{full_name}" unless full_name.start_with?(product.name)
full_name
end
@@ -51,7 +52,7 @@ module VariantUnits
return display_as if has_attribute?(:display_as) && display_as.present?
return variant.display_as if variant_display_as?
options_text
options_text.to_s
end
def assign_units

View File

@@ -10,14 +10,15 @@
.row
.three.columns.alpha
= f.label :white_label_logo, t('.upload_logo')
%br
217 x 44 pixels
.thirteen.columns
= image_tag @object.white_label_logo_url if @object.white_label_logo.present?
%div
= f.file_field :white_label_logo, accept: "image/*"
%div
- if @object.white_label_logo.present?
%button.button.small{ type: "button", "data-controller": "modal-link", "data-action": "click->modal-link#open", "data-modal-link-target-value": "remove_logo" }
= t('.remove_logo')
%br
= f.file_field :white_label_logo, accept: "image/*"
- if @object.white_label_logo.present?
%button.button.small.red{ type: "button", "data-controller": "modal-link", "data-action": "click->modal-link#open", "data-modal-link-target-value": "remove_logo" }
= t('.remove_logo')
- if @object.white_label_logo.present?
.row
@@ -59,4 +60,4 @@
= custom_tab_form.label :content, t('.custom_tab_content')
.thirteen.columns
= custom_tab_form.hidden_field :content, id: "custom_tab_content"
%trix-editor{ input: "custom_tab_content" }
%trix-editor{ input: "custom_tab_content", "data-controller": "trixeditor" }

View File

@@ -1,17 +0,0 @@
%accordion-heading
.row
.small-8.medium-9.columns
%em
%small
{{ summary() | printArray }}
.small-4.medium-3.columns.text-right
%span.accordion-up
%em
%small
= t :checkout_hide
%i.ofn-i_053-point-up
%span.accordion-down
%em
%small
= t :checkout_expand
%i.ofn-i_052-point-down

View File

@@ -1,4 +0,0 @@
%p
%input{ type: 'checkbox', id: 'accept_terms', ng: { model: "terms_and_conditions_accepted", init: "terms_and_conditions_accepted = #{all_terms_and_conditions_already_accepted?}" } }
%label.small{for: "accept_terms"}
= t('.message_html', terms_and_conditions_link: link_to( t(".terms_and_conditions"), current_order.distributor.terms_and_conditions, target: '_blank'), tos_link: link_to_platform_terms)

View File

@@ -1,2 +0,0 @@
%p.alert-box.info
= t '.message_html', cart: link_to(t('.cart'), "#{main_app.cart_path}#bought-products")

View File

@@ -1,19 +0,0 @@
%section{"ng-show" => "!enabled"}
.row
.small-12.columns.text-center
%h3.pad-top
= t :checkout_headline
.row.pad-top{ "data-controller": "login-modal" }
- if guest_checkout_allowed?
.small-5.columns.text-center
%button.primary.expand{ "data-action": "click->login-modal#call" }
= t :label_login
.small-2.columns.text-center
%p.pad-top= "#{t :action_or}"
.small-5.columns.text-center
%button.neutral-btn.dark.expand{"ng-click" => "enabled = true"}
= t :checkout_as_guest
- else
.small-6.columns.small-centered
%button.primary.expand{ "data-action": "click->login-modal#call" }
= t :label_login

View File

@@ -1,46 +0,0 @@
%fieldset#billing
%ng-form{"ng-controller" => "BillingCtrl", name: "billing"}
%h5{"ng-class" => "{valid: billing.$valid, dirty: billing.$dirty || submitted}"}
%span.right
%label.label.round.alert.right
%i.ofn-i_009-close
%label.label.round.success.right
%i.ofn-i_051-check-big
= t :checkout_billing
%accordion-group{"is-open" => "accordion.billing",
"ng-class" => "{valid: billing.$valid, open: accordion.billing}"}
= render 'checkout/accordion_heading'
- if spree_current_user
.small-12.columns
%label
%input{type: :checkbox, "ng-model" => "Checkout.default_bill_address"}
= t :checkout_default_bill_address
%div{ "ng-controller" => "CountryCtrl" }
= f.fields_for :bill_address, @order.bill_address do |ba|
.row
.small-12.columns
= validated_input t(:address), "order.bill_address.address1", "ofn-focus" => "accordion['billing']"
.row
.small-12.columns
= validated_input t(:address2), "order.bill_address.address2", required: false
.row
.small-6.columns
= validated_input t(:city), "order.bill_address.city"
.small-6.columns
= validated_select t(:state), "order.bill_address.state_id", {}, {"ng-options" => "s.id as s.name for s in countriesById[order.bill_address.country_id].states"}
.row
.small-6.columns
= validated_input t(:postcode), "order.bill_address.zipcode"
.small-6.columns.right
= validated_select t(:country), "order.bill_address.country_id", {}, {"ng-init" => "order.bill_address.country_id = order.bill_address.country_id || #{DefaultCountry.id}", "ng-options" => "c.id as c.name for c in countries"}
.row
.small-12.columns.text-right
%button.primary{"ng-disabled" => "billing.$invalid", "ng-click" => "next($event)"}
= t :next

Some files were not shown because too many files have changed in this diff Show More