Compare commits

...

380 Commits

Author SHA1 Message Date
Matt-Yorkley
ab143ceaed Merge pull request #5352 from pacodelaluna/change-date-displayed-on-sales-tax-report
Change date displayed on sales_tax reports
2020-05-11 09:56:38 +02:00
Matt-Yorkley
3ca491683a Merge pull request #5317 from Matt-Yorkley/caching-timed-shops
[Caching] Timed caching on shops data
2020-05-09 15:33:26 +02:00
Pau Pérez Fabregat
b85e439b0e Merge pull request #5395 from coopdevs/skip-broken-spec
Skip unreliable caching test
2020-05-08 17:11:12 +02:00
Pau Perez
fa8c1270ce Skip unreliable caching test
This spec failed two times in a row and it's blocking the release.
2020-05-08 16:37:30 +02:00
Pau Pérez Fabregat
09caf88b6c Merge pull request #5396 from coopdevs/fix-brittle-test
Make test not depend on response's order
2020-05-08 16:37:06 +02:00
Pau Perez
b99bcc3c12 Make test not depend on response's order
I'm assuming this is failing in CI due to the order in which the closed
shops are returned.
2020-05-08 15:56:20 +02:00
Pau Perez
ad70a63370 Update all locales with the latest Transifex translations 2020-05-08 12:01:42 +02:00
Pau Pérez Fabregat
60470aaf9f Merge pull request #5332 from coopdevs/add-timestamps-to-oc-schedule
Add timestamps to OC schedule join table
2020-05-08 10:51:43 +02:00
Pau Pérez Fabregat
2cf407ce35 Merge pull request #5349 from openfoodfoundation/transifex
Transifex
2020-05-08 10:20:07 +02:00
Pau Pérez Fabregat
c38c59b0b9 Merge pull request #5223 from luisramos0/def_user
Change default user from spree@example.com to ofn@example.com ❤️
2020-05-08 09:51:31 +02:00
Luis Ramos
424932d61b Merge pull request #5262 from luisramos0/closed_shop_msg
[Mobile] Improve the design of shop page messages (closed shop, private shop and select OC)
2020-05-08 07:52:58 +01:00
Matt-Yorkley
5518ffa856 Ensure validations are called when updating attributes in test 2020-05-07 19:37:43 +02:00
Luis Ramos
dd5041db65 Remove unnecessary default user email and pwd from docker setup
These are now the default values in the app
2020-05-07 18:18:42 +01:00
Luis Ramos
052dbca1ba Merge pull request #5370 from Matt-Yorkley/dont-render-twice
Don't render twice
2020-05-07 18:15:47 +01:00
Matt-Yorkley
86bfd1bebb Add explanatory comments on usages of Timecop.travel 2020-05-07 17:29:58 +02:00
Luis Ramos
468576ee8a Merge pull request #5329 from romale/master
Correct translations
2020-05-07 16:04:24 +01:00
Luis Ramos
c9b60d0f62 Merge pull request #5341 from mathewdbutton/5173-show-outstanding-order-balance-on-orders-page
Show outstanding balance on orders page
2020-05-07 16:03:58 +01:00
Luis Ramos
52b39d04a4 Merge pull request #5359 from mbudm/issue/5108
Add NavigationCheck to order cycles edit form
2020-05-07 14:37:32 +01:00
Matt-Yorkley
01d741509f Fix test of rendered properties AMS
Here the displayed properties that we're testing also rely on shops data (including the list of supplied properties), which is now cached for 15 seconds. We clear that cache entry so we can cleanly test only the caching of the properties AMS array.
2020-05-07 15:20:37 +02:00
Luis Ramos
66fe26fcc5 Merge pull request #5295 from Matt-Yorkley/shopfront-optimising
Enterprise serializer optimisations
2020-05-07 13:08:14 +01:00
Matt-Yorkley
460ab6cdb4 Use #allow instead of #stub 2020-05-07 13:20:30 +02:00
Matt-Yorkley
7457543c2b Adds spec for timed caching on shops data 2020-05-07 13:20:30 +02:00
Matt-Yorkley
6b6ab864ef Improve comment on Fragment Caching 2020-05-07 13:20:30 +02:00
Matt-Yorkley
e73c8232de Improve unit test in cache_service_spec 2020-05-07 13:20:30 +02:00
Matt-Yorkley
37821beb1b Extract home stats caching to method in service 2020-05-07 13:20:30 +02:00
Matt-Yorkley
2292cbaae4 Extract timed enterprise AMS fragment caching options to service 2020-05-07 13:20:28 +02:00
Luis Ramos
987347d5ab Move translation keys to new correct location 2020-05-07 12:18:40 +01:00
Luis Ramos
3c7970f72f Add select oc message when there are multiple OCs 2020-05-07 12:18:40 +01:00
Luis Ramos
d4980893a1 Refactor darker-background directive, extract method 2020-05-07 12:17:43 +01:00
Luis Ramos
0d6d071db2 Remove dead class .shopfront_hidden_message 2020-05-07 12:17:43 +01:00
Luis Ramos
cba9382230 Replace line-height with margin 2020-05-07 12:17:43 +01:00
Luis Ramos
7fcee0fe6d Fix problem in warning sign 2020-05-07 12:17:43 +01:00
Luis Ramos
f3347a8e16 Make teal links appear only when the darker background is activated
This way links in producers, about, etc, where the background is white will still appear as orange, as per design
2020-05-07 12:17:43 +01:00
Luis Ramos
782988b61c Fix with-darker-background class by moving it inside page-view selector and using opacity instead of just grey so that other elements in the page (shadow from element above) can be seen 2020-05-07 12:17:43 +01:00
Luis Ramos
21a1ba2fb5 Move translation keys according to new location in the customer_required partial 2020-05-07 12:17:43 +01:00
Luis Ramos
ba25986756 Fix some css rubocop issues 2020-05-07 12:17:43 +01:00
Luis Ramos
098ad6f250 Merge partial messages back to home partial where it is only used 2020-05-07 12:17:43 +01:00
Luis Ramos
319657d2c5 Move closed shop partial to /messages 2020-05-07 12:17:43 +01:00
Luis Ramos
eb773a813e Extract open shop message to partial 2020-05-07 12:17:43 +01:00
Luis Ramos
5dedbc4231 Extract customer_required message to separate partial 2020-05-07 12:17:43 +01:00
Luis Ramos
84c00fe215 Remove duplicate conditionals already present in ShopHelper#shop_tabs, when these partials are rendered, these conditions will always be true
In the shops partial, by adding the else, we avoid rendering empty space with an empty
products list in case the shop is closed
2020-05-07 12:17:43 +01:00
Luis Ramos
77d7d2b804 Make the background darker only in specific cases 2020-05-07 12:17:43 +01:00
Luis Ramos
b34fb79d69 Move content div to messages partial so that it's not used in the closed shop message (no margin according to design) 2020-05-07 12:17:43 +01:00
Luis Ramos
1c41061f9e If shop is closed show closed shop message partial in the home tab 2020-05-07 12:17:43 +01:00
Luis Ramos
b86081090f Extract closed shop message to a partial 2020-05-07 12:17:43 +01:00
Luis Ramos
dbdbe01d6a Add new style to closed shop message 2020-05-07 12:17:43 +01:00
Luis Ramos
0996c28c09 Memoize helper methods that are called several times in the views 2020-05-07 12:17:43 +01:00
Luis Ramos
5f70ef6e75 Improve style of closed shop message and remove border from message 2020-05-07 12:17:43 +01:00
Luis Ramos
e0b3e9a040 Remove border of message and paddings, add background color, change link color and split message in two lines 2020-05-07 12:17:43 +01:00
Matt-Yorkley
2876b98155 Use time-based caching on rendered AMS data for shops 2020-05-07 13:11:53 +02:00
Matt-Yorkley
545ca85644 Extract caching of homepage stats to service 2020-05-07 13:11:28 +02:00
Luis Ramos
c64ba75e8d Merge pull request #5348 from luisramos0/single_oc_selector
Replace select box with text when only one OC is available for selection
2020-05-07 12:07:19 +01:00
Luis Ramos
56b9737676 Merge pull request #5343 from luisramos0/windows
Make OC selector options color explicitly gray and not white
2020-05-07 11:44:14 +01:00
Luis Ramos
d967d855fc Merge pull request #5319 from Matt-Yorkley/caching-by-class
[Caching] Caching data by class
2020-05-07 11:43:44 +01:00
Luis Ramos
1e9b4516cb Merge pull request #5318 from Matt-Yorkley/caching-api
[Caching] API Action Caching on shop filters
2020-05-07 11:42:52 +01:00
Transifex-Openfoodnetwork
ffebaee9c7 Updating translations for config/locales/tr.yml 2020-05-07 17:34:22 +10:00
Luis Ramos
066f978c59 Update ruby version in GETTING_STARTED 2020-05-06 22:19:43 +01:00
Luis Ramos
d1392d400a Merge pull request #5350 from luisramos0/edit_order_snail
Improve order edit page in data inconsistency scenario (follow up from S2 #4186)
2020-05-06 20:33:40 +01:00
Luis Ramos
20984ac008 Merge pull request #5379 from openfoodfoundation/dependabot/bundler/ddtrace-0.35.1
Bump ddtrace from 0.35.0 to 0.35.1
2020-05-06 20:31:20 +01:00
dependabot-preview[bot]
7f9dfb6142 Bump ddtrace from 0.35.0 to 0.35.1
Bumps [ddtrace](https://github.com/DataDog/dd-trace-rb) from 0.35.0 to 0.35.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/v0.35.0...v0.35.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-05-06 19:20:07 +00:00
Transifex-Openfoodnetwork
6c71259b25 Updating translations for config/locales/en_FR.yml 2020-05-07 03:10:34 +10:00
Transifex-Openfoodnetwork
29a54cbfe4 Updating translations for config/locales/fr.yml 2020-05-07 03:10:22 +10:00
Transifex-Openfoodnetwork
05820c7ef0 Updating translations for config/locales/tr.yml 2020-05-07 00:14:33 +10:00
Transifex-Openfoodnetwork
492f96c90f Updating translations for config/locales/tr.yml 2020-05-07 00:11:28 +10:00
Pau Pérez Fabregat
ace3767eb2 Merge pull request #5333 from coopdevs/add-worker-docker-container
Create a container to run a DJ worker in dev
2020-05-06 16:11:21 +02:00
Luis Ramos
c7c8bfe212 Merge pull request #5347 from luisramos0/hide_oc_selector_for_private_shop
[Mobile] Hide OC selector if shop requires login/customer
2020-05-06 14:31:52 +01:00
Pau Pérez Fabregat
dadc17398f Merge pull request #5371 from Matt-Yorkley/cart-add-error
Cart add error handling
2020-05-06 15:22:06 +02:00
Pau Pérez Fabregat
194c87e805 Merge pull request #5361 from Matt-Yorkley/cart-with-soft-deletion
Cart with soft-deletion
2020-05-06 15:20:35 +02:00
Pau Pérez Fabregat
ead21a97cc Merge pull request #5327 from openfoodfoundation/luisramos0-patch-2
Add link to docker tips wiki page to Docker.md
2020-05-06 14:10:37 +02:00
Pau Pérez Fabregat
a0012e1c5b Merge pull request #5326 from openfoodfoundation/luisramos0-patch-1-1
Add link to Docker.md from GETTING_STARTED.md
2020-05-06 12:31:00 +02:00
Matt-Yorkley
9c24c1cd05 Ensure #caches_action works in test suite 2020-05-06 12:24:33 +02:00
Matt-Yorkley
4aac97c985 Add feature spec for action caching of taxon and properties endpoints 2020-05-06 11:47:51 +02:00
Matt-Yorkley
7e4c00ba3f Ensure caching works in cache tests for API controllers 2020-05-06 11:47:45 +02:00
Pau Pérez Fabregat
65433c6ac6 Merge pull request #5351 from luisramos0/improve_sample_data
Improve ship methods names on sample data
2020-05-06 11:27:34 +02:00
Pau Pérez Fabregat
b3205c5459 Merge pull request #5309 from luisramos0/better-karma
Make dockerfile install node and adapt karma browser config to work inside a docker container
2020-05-06 11:11:00 +02:00
Transifex-Openfoodnetwork
d52db51b29 Updating translations for config/locales/nb.yml 2020-05-06 17:25:07 +10:00
Mathew Button
e088b27a13 Always display the outstanding balance if not zero 2020-05-06 16:45:44 +10:00
Steve Roberts
4573127c59 Add NavigationCheck to order cycles edit form
- Simplify if statements with safe navigation operator
- Simplify order cycle nav check spec
- Rename nav check callback so a comment is not needed and remove unnecessary assignation to $scope
2020-05-06 10:43:21 +10:00
Matt-Yorkley
61d7adaf74 Enable optional caching tag in test metadata 2020-05-05 18:43:09 +02:00
Matt-Yorkley
bdc2d002fa Update karma tests 2020-05-05 17:22:12 +02:00
Matt-Yorkley
13e4411b89 Add error message on cart populate failure and don't keep re-sending the data to the server.
This was triggering many requests to be continuously re-sent in a very problematic way (server-melting), and with no user feedback.
2020-05-05 17:22:10 +02:00
Luis Ramos
c2a9a698f4 Merge pull request #5312 from openfoodfoundation/dependabot/bundler/unicorn-5.5.5
Bump unicorn from 5.5.4 to 5.5.5
2020-05-05 15:24:59 +01:00
Matt-Yorkley
9a7807b134 Don't continuously re-post data on cart error 2020-05-05 16:04:05 +02:00
Luis Ramos
24414b83dd Merge pull request #5325 from oeoeaio/enhancement-5214
Add order number and date/time to order cycles customer report
2020-05-05 14:34:47 +01:00
Matt-Yorkley
4f4b3fb206 Don't render twice 🙈 2020-05-05 15:21:05 +02:00
Matt-Yorkley
6afda87baf Add explanatory comment on soft-deleted variant stock logic 2020-05-05 13:57:50 +02:00
Matt-Yorkley
0a28abbf2d Add additional feature specs for soft-deleted variants in cart 2020-05-05 13:57:50 +02:00
Matt-Yorkley
26ba76cff9 Fix soft-deletion in CartService and update spec 2020-05-05 13:57:50 +02:00
Matt-Yorkley
a3458aa562 Ensure VariantStockLevels can process soft-deleted variants 2020-05-05 13:57:50 +02:00
Matt-Yorkley
0e429da377 Return zero available stock (total_on_hand) for variants that are soft-deleted 2020-05-05 13:57:50 +02:00
Matt-Yorkley
eb51b87bea Add spec for current soft deletion behaviour in OrderCycle#variants_distributed_by scope 2020-05-05 13:57:50 +02:00
Matt-Yorkley
d3de1ce47e Add spec for current soft deletion behaviour in VariantOverride#indexed 2020-05-05 13:57:50 +02:00
Matt-Yorkley
5639b21c77 Add tests for current soft-deleted variant behavior in CartService 2020-05-05 13:57:50 +02:00
Matt-Yorkley
068c8feea7 Merge pull request #5289 from Matt-Yorkley/cart-populate
Cart populate
2020-05-05 13:56:17 +02:00
François Turbelin
6e5cbebf4a Change date value on order_and_distributor_report 2020-05-05 12:27:17 +02:00
François Turbelin
9cfd7db99d Change date displayed on sales_tax reports 2020-05-05 12:27:17 +02:00
Luis Ramos
bcfa8982ef Merge pull request #5364 from openfoodfoundation/dependabot/bundler/ddtrace-0.35.0
Bump ddtrace from 0.34.2 to 0.35.0
2020-05-05 10:58:13 +01:00
Matt-Yorkley
805f91e838 Remove unnecessary #all call 2020-05-05 09:56:08 +02:00
Matt-Yorkley
a3757992b5 Use #tap to destroy and remove before block 2020-05-05 09:55:14 +02:00
dependabot-preview[bot]
7180af2736 Bump ddtrace from 0.34.2 to 0.35.0
Bumps [ddtrace](https://github.com/DataDog/dd-trace-rb) from 0.34.2 to 0.35.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/v0.34.2...v0.35.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-05-04 22:46:59 +00:00
Mathew Button
fe6c810505 Add brackets in view instead of API response 2020-05-04 19:09:18 +10:00
Luis Ramos
44872844ed Make ship methods in sample data have the name of the enterprise so it's easier to distinguish them 2020-05-03 16:36:12 +01:00
Luis Ramos
bf0b941e1c Merge pull request #4935 from coopdevs/data-archiving
Allow data archiving using the :truncate_data task
2020-05-03 12:58:31 +01:00
Luis Ramos
e2b26b2e9c Replace break with if
What we would need would be a continue, not break, so that other units will be processed without halting the cycle through the units
2020-05-03 12:00:23 +01:00
Luis Ramos
92d0a5b735 Change default user from spree@example.com to ofn@example.com 2020-05-03 10:12:43 +01:00
Luis Ramos
8e27ace563 Adapt specs where there is only one OC available to the absence of the OC selector 2020-05-02 20:16:41 +01:00
Transifex-Openfoodnetwork
93881a742e Updating translations for config/locales/en_GB.yml 2020-05-03 05:09:16 +10:00
Luis Ramos
b92e257e44 Fix codeclimate issue 2020-05-02 19:12:47 +01:00
Luis Ramos
fa908d4024 Extract change_order_cycle partial from main enterprise shop view 2020-05-02 19:01:36 +01:00
Luis Ramos
7fd14cf29b Adjust line height of select label and select itself 2020-05-02 19:01:36 +01:00
Luis Ramos
ef0e9dc0ca Replace select box with text when only one OC is available for selection 2020-05-02 19:01:33 +01:00
Luis Ramos
89cb447387 Hide OC selector if shop requires login/customer 2020-05-02 17:56:49 +01:00
Luis Ramos
b568d25446 Update all locales with the latest Transifex translations 2020-05-02 17:08:53 +01:00
Luis Ramos
303464a04e Merge pull request #5297 from openfoodfoundation/transifex
Transifex
2020-05-02 15:40:54 +01:00
Luis Ramos
0662c57d9d Merge pull request #5344 from luisramos0/debug_assets
Move PROFILE debug assets flag to another ENV var
2020-05-02 14:21:15 +01:00
Luis Ramos
acb7e9751b Move debug assets flag to another env var so we go back to having both profile and debug assets disabled by default 2020-05-02 10:42:49 +01:00
Luis Ramos
9ae3ad9279 Move rule on option out of the select rule to fix rubocop issue 2020-05-01 17:43:52 +01:00
Luis Ramos
240e2a36d3 Make option color explicitly gray and not white otherwise we will have options render white on white on some browsers, namely chrome on windows 10 2020-05-01 17:39:12 +01:00
Mathew Button
8087e6b31b Show outstanding balance on orders page
Prior to this change, there was no way of knowing how much was owed (or
in need of refunding) at a glance for each order on the orders index page,
this information was only available by clicking through to an order
payment page

This change adds the outstanding balance for each order
2020-05-01 21:38:20 +10:00
Transifex-Openfoodnetwork
39875308c2 Updating translations for config/locales/en_FR.yml 2020-05-01 04:55:35 +10:00
Transifex-Openfoodnetwork
c424e7b65e Updating translations for config/locales/fr.yml 2020-05-01 04:55:21 +10:00
Pau Perez
9d253e1e3e Create a container to run a DJ worker in dev 2020-04-30 17:52:22 +02:00
Matt-Yorkley
1990417b72 Test values are not fetched from database when cache exists 2020-04-30 17:37:48 +02:00
Matt-Yorkley
7a22f7f783 Move and rename caching spec 2020-04-30 17:37:45 +02:00
Luis Ramos
74c7a01151 Merge pull request #5259 from luchiago/add-extra-social-media-to-emails
Add extra social media to order confirmation email
2020-04-30 15:01:09 +01:00
Matt-Yorkley
f724d1b572 Add feature spec for caching properties and taxons AMS 2020-04-30 15:35:39 +02:00
Luis Ramos
8845260979 Merge pull request #5285 from rmklaus12/5246-missing-translation-orders-list
5246 missing translation orders list
2020-04-30 14:00:26 +01:00
Pau Perez
1903134e13 Add timestamps to OC schedule join table
This is critical to debug bugs related to subscriptions.

Essentially, `has_and_belongs_to_many` doesn't give us the option for
any other column that the foreign keys themselves:

> A has_and_belongs_to_many association creates a direct many-to-many
> connection with another model, with no intervening model.

Source: https://guides.rubyonrails.org/v3.2/association_basics.html#the-has_and_belongs_to_many-association

Note however, that there's no way to update an order_cycle_schedule,
that I can think of but `updated_at` doesn't do any harm.
2020-04-30 15:00:13 +02:00
Pau Pérez Fabregat
4174ea69a1 Merge pull request #5247 from chrishil1/Placeholders_variant
Added placeholders in variant edit page
2020-04-30 12:05:59 +02:00
Pau Pérez Fabregat
676add18c3 Merge pull request #5322 from luisramos0/dead_content
Delete some dead views
2020-04-30 12:02:14 +02:00
Matt-Yorkley
a35f8cdb02 Move cache keys used in views into the cache service 2020-04-30 09:45:15 +02:00
Luis Ramos
8a107bee98 Merge pull request #5235 from luisramos0/mail_methods
Remove smtp config from admin config page
2020-04-29 19:10:02 +01:00
Matt-Yorkley
210029aaff Enable optional caching tag in test metadata 2020-04-29 20:04:54 +02:00
Transifex-Openfoodnetwork
5bc5ef9a9d Updating translations for config/locales/pt_BR.yml 2020-04-30 03:52:57 +10:00
Matt-Yorkley
f2cd122ec8 Update variant_stock_spec for unsaved and soft-deleted cases 2020-04-29 18:29:44 +02:00
Matt-Yorkley
4054bdd722 Add Bugsnag call for "variant with no stock item" case 2020-04-29 17:34:48 +02:00
romale
3a4ef2697c Correct translations
Without it, some labels not translated to other language.
And, please check code:
en.admin.subscription.subscriptions - does not exists
but
en.admin.subscriptions.subscriptions - is exist
2020-04-29 18:27:09 +03:00
Matt-Yorkley
2bdda7de04 Change order of methods for easier reading 2020-04-29 17:22:46 +02:00
Matt-Yorkley
92a881c584 Simplify relation used in #exchanges_supplying 2020-04-29 17:19:16 +02:00
Pau Perez
647a7bdddf Clarify we won't use truncate_date in prod yet
We initially aimed at implementing data archiving in production reusing
this rake task but priorities have changed. It'll be just a refactor for
now.
2020-04-29 17:00:53 +02:00
Pau Perez
e0228f66af Default to archiving data older than 2 years.
This is safer than the current 3 months.
2020-04-29 16:49:43 +02:00
Pau Perez
38ea95ea85 Prevent nil input to turn into 0 2020-04-29 16:49:43 +02:00
Pau Perez
6ceeda7d9e Instrument TruncateData logging start and end 2020-04-29 16:49:43 +02:00
Pau Perez
703706ee0b Replace one-letter variable with full word 2020-04-29 16:49:43 +02:00
Pau Perez
e2a3dd0c6f Delete only return auths. of the deleted orders
They are associated to order and as such we can't remove them all
blindly.
2020-04-29 16:49:43 +02:00
Pau Perez
a3b8638faf Delete sessions older than two weeks
This affects users that are actively purchasing, so 2 weeks data is more
than enough. Others can afford to log in again.
2020-04-29 16:49:43 +02:00
Pau Perez
4f015320a3 Upper case DELETE statement
This keeps it consistent with the rest of the log.
2020-04-29 16:49:43 +02:00
Pau Perez
0f1d57db73 Delete LogEntries older than a month
They are useful for troubleshooting but a month data seems enough.
2020-04-29 16:49:43 +02:00
Pau Perez
5f84c51c13 Delete StateChanges older than a month
They are useful for troubleshooting but a month data seems enough.
2020-04-29 16:49:43 +02:00
Pau Perez
d215c76bc9 Make it even more explicit the action is dangerous
We're yelling at the person to make a backup before proceeding.
2020-04-29 16:49:43 +02:00
Pau Perez
e1a80edb7e Carefully doc how to archive data from an instance 2020-04-29 16:49:43 +02:00
Pau Perez
a4372e4d31 Fix long lines 2020-04-29 16:49:43 +02:00
Pau Perez
b6d3c3039a Fix "Method has too many lines" violation 2020-04-29 16:49:43 +02:00
Pau Perez
f199cb1bea Warn but allow executing :truncate_data in prod 2020-04-29 16:49:43 +02:00
Pau Perez
be123b2a72 Specify how much data to remove in :truncate_data 2020-04-29 16:49:43 +02:00
Pau Perez
60d29d619f Replace :truncate_data definition with new class
And cover it with a test.
2020-04-29 16:49:43 +02:00
Pau Perez
78fd785f0c Extract TruncateData out of :truncate_data task 2020-04-29 16:49:43 +02:00
Pau Pérez Fabregat
f9f4bdae8f Merge pull request #5238 from Matt-Yorkley/moar-performance
Improve Pain Points
2020-04-29 16:36:15 +02:00
Luis Ramos
0f16c43f21 Add link to docker tips wiki page to Docker.md 2020-04-29 14:16:59 +01:00
Luis Ramos
865024fc1f Add link to the docker setup guide to the getting started guide. 2020-04-29 14:05:45 +01:00
Luis Ramos
407d890d23 Merge pull request #5315 from Matt-Yorkley/ordercyles-controller-tweaks
OrderCylesController tweaks
2020-04-29 13:50:10 +01:00
Luis Ramos
0e5d7c1eb1 Add migration to drop dead spree_mail_methods table and some dead mail_methods preferences 2020-04-29 13:34:50 +01:00
Luis Ramos
a38b18bd0d Remove smtp config from admin config page 2020-04-29 13:34:19 +01:00
Rob H
6405c34428 Add order number and date/time to order cycles customer report 2020-04-29 21:20:14 +10:00
Pau Pérez Fabregat
e7df9bb58d Merge pull request #5178 from coopdevs/dont-populate-empty-cart
Dont populate empty cart
2020-04-29 13:08:26 +02:00
Matt-Yorkley
d3af3d3f27 Avoid extra query on stock_items every time #on_demand is called on a variant.
In the case where the variant has not been saved yet, we can use #new_record? here instead of #stock_items.empty?, to avoid an additional query. This can be called a vast number of times per request, in various N+1s. The other case where we need to return here is when a variant has been deleted, so #stock_items will be empty and #stock_item will be nil. Likewise, we can just check that with #deleted? and avoid #stock_items.empty?
2020-04-28 20:54:04 +02:00
Matt-Yorkley
9682544442 Eager-load and update BasicEnterpriseSerializer 2020-04-28 20:10:40 +02:00
Matt-Yorkley
f4bcf6c6d5 Eager-load line_item associations in order 2020-04-28 20:10:40 +02:00
Luis Ramos
e6fa08edfc Delete some dead views 2020-04-28 19:07:19 +01:00
Transifex-Openfoodnetwork
18fc4b7c92 Updating translations for config/locales/ca.yml 2020-04-29 01:13:42 +10:00
Transifex-Openfoodnetwork
612cc45ab7 Updating translations for config/locales/en_FR.yml 2020-04-29 01:13:35 +10:00
Transifex-Openfoodnetwork
16e289bf37 Updating translations for config/locales/en_GB.yml 2020-04-29 01:13:29 +10:00
Transifex-Openfoodnetwork
b54c6fcb26 Updating translations for config/locales/nb.yml 2020-04-29 01:13:26 +10:00
Transifex-Openfoodnetwork
8365c66add Updating translations for config/locales/fil_PH.yml 2020-04-29 01:13:22 +10:00
Transifex-Openfoodnetwork
5590671c23 Updating translations for config/locales/fr.yml 2020-04-29 01:13:19 +10:00
Luis Ramos
9e43661127 Merge pull request #5153 from luisramos0/bye_bye_ga
Bye bye Google Analytics
2020-04-28 16:09:16 +01:00
Matt-Yorkley
ec581dccb8 Use class-based caching for queries in EnterpriseInjectionData 2020-04-28 15:11:59 +02:00
Matt-Yorkley
4d098448f5 Cache rendered AMS arrays in darkswarm layout based on latest timestamps of rendered object classes 2020-04-28 15:11:59 +02:00
Matt-Yorkley
53ebe10483 Fix issue with generic primary taxon in product factory changing which taxons are correctly counted as being in open order cycles. 2020-04-28 15:11:59 +02:00
Matt-Yorkley
eb5f8b85ff Touch primary taxon when a product's primary_taxon is changed 2020-04-28 15:11:59 +02:00
Matt-Yorkley
1b18808d21 Touch ShippingMethod when it's assigned to a new distributor 2020-04-28 15:11:59 +02:00
Matt-Yorkley
6ef345c5d8 Touch taxon when a taxon is applied to a product 2020-04-28 15:11:59 +02:00
Matt-Yorkley
a25a75bbe8 Ensure action caching includes GET params
By default the auto-generated action cache keys looks like this:
`views/0.0.0.0:3000/api/order_cycles/1/properties`

With this change the cache keys now look like this:
`views/0.0.0.0:3000/api/order_cycles/1/properties?distributor=3`
2020-04-28 15:11:14 +02:00
Matt-Yorkley
ea1ec1a1c6 Use ActionCaching in OrderCyclesController (taxons and properties) 2020-04-28 15:11:12 +02:00
Matt-Yorkley
975afb3152 Enable use of Action Caching in the API 🎉
See: https://guides.rubyonrails.org/api_app.html#adding-other-modules
2020-04-28 15:11:00 +02:00
Kristina Lim
265871932f Merge pull request #5146 from coopdevs/dev-mode-profiling-settings
Add PROFILE var to set production-like settings
2020-04-28 20:31:13 +08:00
Kristina Lim
c34570e96e Merge pull request #5313 from kristinalim/fix/mirror_db_script_bucket
Fix script for syncing public/ in AWS bucket to local
2020-04-28 20:28:05 +08:00
Matt-Yorkley
ac166f3590 Add CacheService 2020-04-28 14:15:16 +02:00
Matt-Yorkley
e4985a9d51 Avoid needlessly fetching the current user records (for authentication and API key checks)
These endpoints are absolutely public, and don't need the current user at any point.
2020-04-28 14:06:02 +02:00
Matt-Yorkley
eb7de18298 Return early (before hitting the DB) in complex product list rendering if we already know the order cycle is closed 2020-04-28 13:51:25 +02:00
Matt-Yorkley
67a7140642 Memoize distributor and order_cycle in Api::OrderCyclesController 2020-04-28 13:48:07 +02:00
Luis Ramos
868929eed3 Merge pull request #4993 from luisramos0/move_ent_fees
Change engine routes to better work with specs in rails 4
2020-04-28 11:48:41 +01:00
Transifex-Openfoodnetwork
8e6d53f6c6 Updating translations for config/locales/nb.yml 2020-04-28 17:59:10 +10:00
Robin Klaus
f072e9d9c2 Add missing translations on order list page 2020-04-28 16:47:39 +10:00
Kristina Lim
7c985f39ab Fix script for syncing public/ in AWS bucket to local 2020-04-28 13:22:48 +08:00
Kristina Lim
efb83c2f95 Merge pull request #5250 from mkllnk/mirror-db-script
Add cache to mirror_db script
2020-04-28 13:18:29 +08:00
Matt-Yorkley
74e81b078f Avoid N+1s in Order#cap_quantity_at_stock! 2020-04-28 01:11:28 +02:00
Matt-Yorkley
3fa2b3161f Avoid N+1s when using OrderCycle#exchanges_supplying 2020-04-28 01:10:07 +02:00
Matt-Yorkley
fe2bf8d531 Eager-load variants and stock items when doing stock checks on multiple variants 2020-04-28 01:05:42 +02:00
Matt-Yorkley
eb858159ce Eager-load :default_price on variants 2020-04-28 01:04:22 +02:00
Matt-Yorkley
43869fc140 Replace fired events with clearer method call
The 'spree.cart.add' event has no listeners in spree_core on in ofn. The 'spree.order.contents_changed' just has a single listener that calls `order.update_distribution_charge`.
2020-04-28 00:56:18 +02:00
Matt-Yorkley
a5c4364f92 Fetch (or create) current_order only once 2020-04-28 00:52:09 +02:00
dependabot-preview[bot]
02775d033d Bump unicorn from 5.5.4 to 5.5.5
Bumps [unicorn](https://yhbt.net/unicorn/) from 5.5.4 to 5.5.5.

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-04-27 20:50:56 +00:00
Luis Ramos
6559b4d3a4 Make dockerfile install node and adapt karma browser config to work inside a docker container 2020-04-27 19:05:11 +01:00
Luis Ramos
d851aa5106 Add model definition to migration to make migration more resilient 2020-04-27 18:40:56 +01:00
Luis Ramos
c5b9727177 Remove ga_cookies_preference from DB 2020-04-27 18:40:56 +01:00
Luis Ramos
248b0016d4 Remove trackers and google analytics 2020-04-27 18:40:33 +01:00
Luis Ramos
d8d6bad11c Remove config and sections related to google analytics in the cookies banner and cookies page 2020-04-27 18:40:00 +01:00
Luis Ramos
ab16931d70 Merge pull request #5257 from luisramos0/stripe_sca_payments_last
StripeSCA - reuse better method to fetch last payment of an order to avoid nasty bugs in the future
2020-04-27 18:34:35 +01:00
Matt-Yorkley
e33de8a20e Update specs and refactor a bit 2020-04-27 19:27:07 +02:00
Matt-Yorkley
468cb3f57e Remove obviously private methods from the public interface in CartService
These methods are not called from anywhere in the app, only in a couple of tests in cart_service_spec.
2020-04-27 19:27:07 +02:00
Matt-Yorkley
1152f307e2 Eager-load associated line_items data in #update_distribution_charge! 2020-04-27 19:27:07 +02:00
Matt-Yorkley
25525d4f75 Use guard clause in each block 2020-04-27 19:27:07 +02:00
Matt-Yorkley
a759d8c7c7 Avoid N+1s for variants and for line_items of variants 2020-04-27 19:27:07 +02:00
Matt-Yorkley
b3242041e5 Return earlier (before scoping process, if possible) 2020-04-27 19:27:07 +02:00
Matt-Yorkley
106bb7a27f Rename some variables and add comments for clarity in cart_service 2020-04-27 19:27:07 +02:00
Matt-Yorkley
2334ab6d00 Delete some dead code in cart_service
This Bugsnag error was added a year ago and hasn't been seen
2020-04-27 19:27:07 +02:00
Matt-Yorkley
11af5dffdc Memoize scoper in cart_service
Avoids fetching all of the hub's variant overrides from the db every time it's initialized.
2020-04-27 19:27:07 +02:00
Matt-Yorkley
3ce7e96777 Add some debounce and an onwheel hack to product add to basket field
Debounce ensures we don't get a million requests if the up/down buttons are clicked rapidly. The onwheel hack adds some protection against scrolling triggering the quantity up/down. See: https://stackoverflow.com/a/51076231
2020-04-27 19:27:07 +02:00
Transifex-Openfoodnetwork
670fff9d36 Updating translations for config/locales/es_CR.yml 2020-04-28 02:38:07 +10:00
Transifex-Openfoodnetwork
171ba09663 Updating translations for config/locales/fr.yml 2020-04-28 01:40:44 +10:00
Transifex-Openfoodnetwork
65c9c287e8 Updating translations for config/locales/en_FR.yml 2020-04-28 01:37:49 +10:00
Transifex-Openfoodnetwork
4332734f27 Updating translations for config/locales/ca.yml 2020-04-28 01:37:44 +10:00
Transifex-Openfoodnetwork
340f669506 Updating translations for config/locales/en_GB.yml 2020-04-28 01:37:36 +10:00
Transifex-Openfoodnetwork
3b7ad0ef4e Updating translations for config/locales/ca.yml 2020-04-27 23:49:48 +10:00
Luis Ramos
6e23f5bdac Merge pull request #5233 from luisramos0/stripe_sca_bo
[StripeSCA] Fix card payments in the Backoffice
2020-04-27 13:00:24 +01:00
Luis Ramos
8b5378e673 Merge pull request #5251 from luisramos0/Issue4654
Change Result of PriceSack Calculation from Integers to Floats, clone #4812
2020-04-27 12:36:18 +01:00
Transifex-Openfoodnetwork
ba32e2d676 Updating translations for config/locales/fil_PH.yml 2020-04-27 18:08:38 +10:00
Pau Pérez Fabregat
74c4722cfe Merge pull request #5286 from rmklaus12/4966-missing-translation-admin-prod-list
4966 missing translation admin prod list
2020-04-27 09:28:57 +02:00
Luis Ramos
b3eda9fecb Merge pull request #5256 from dacook/5190-fix-order-sorting
Fix sorting of orders list
2020-04-26 14:24:00 +01:00
Pau Perez
c224df9b6a Do not trigger an orderChanged with null quantity
When loading the page $watchGroup calls the listener function for every
listed line item but with a set variant and null quantity and
max_quantity. There's no point on computing an order change when there
was none.

This saves an empty request on the second most used endpoint of the app,
specially busy when users are placing orders.
2020-04-24 15:54:46 +02:00
Luis Ramos
b9c86d54b0 Merge pull request #5261 from luisramos0/search-iphone
[Mobile] Make search box font size be 16px so that no zoom happens on iphone
2020-04-24 11:30:26 +01:00
Transifex-Openfoodnetwork
cebba4dd43 Updating translations for config/locales/en_GB.yml 2020-04-24 18:22:49 +10:00
Matt-Yorkley
43ba73ac19 Avoid expensive queries for supplied product properties if enterprise is not a supplier 2020-04-23 21:51:39 +02:00
Matt-Yorkley
728326c2a5 Eager-load :properties on supplied products in enterprise_shopfront_serializer 2020-04-23 21:48:41 +02:00
Transifex-Openfoodnetwork
8bcc9456d8 Updating translations for config/locales/en_FR.yml 2020-04-24 04:30:04 +10:00
Transifex-Openfoodnetwork
5f51b21fe9 Updating translations for config/locales/fr.yml 2020-04-24 04:29:52 +10:00
Luis Ramos
2984829790 Merge pull request #5253 from luisramos0/edit_order
Make edit order page work even if inventory_items dont have a corresponding line_item in the order
2020-04-23 19:27:31 +01:00
Luis Ramos
f366aa2605 Merge pull request #5290 from openfoodfoundation/dependabot/bundler/mini_racer-0.2.10
Bump mini_racer from 0.2.9 to 0.2.10
2020-04-23 18:53:14 +01:00
Matt-Yorkley
bf16a10129 Update all locales with the latest Transifex translations 2020-04-23 19:05:22 +02:00
Matt-Yorkley
43836d2b30 Merge pull request #5292 from openfoodfoundation/transifex
Transifex
2020-04-23 18:53:36 +02:00
Pau Pérez Fabregat
82156e32e0 Merge pull request #4920 from luisramos0/api_var_ctrl
Bring Spree::Variant#active from Spree so that we can improve it
2020-04-23 17:35:49 +02:00
Matt-Yorkley
69cf7dff2c Memoize :active in enterprise serializers that call it multiple times 2020-04-23 13:17:44 +02:00
Pau Pérez Fabregat
a8ca471cd2 Merge pull request #5189 from Matt-Yorkley/mobile-buttons
[Mobile UX] Style updates on buttons
2020-04-23 12:56:49 +02:00
Luis Ramos
aa52cf8bf0 Merge pull request #5254 from chrishil1/missing_translation_save_as_default
Added missing translation to column dropdown
2020-04-23 11:08:33 +01:00
Luis Ramos
ac6501c5d8 Merge pull request #5195 from luisramos0/prod_helper
Delete dead code from several places...
2020-04-23 11:07:44 +01:00
Luis Ramos
568e570b4b Move method to more generic helper to use it in mailers 2020-04-23 16:08:10 +10:00
Luis Ramos
42be6c905f Added spec for OrderPaymentFinder 2020-04-23 16:08:10 +10:00
Luis Ramos
d482cccefe Use OrderPaymentFinder methods instead of payments.last and payments.pending.last 2020-04-23 16:08:10 +10:00
Luis Ramos
52becf6abc Extract payment method logic from OrderPaymentFinder into the orders helper 2020-04-23 16:08:10 +10:00
Transifex-Openfoodnetwork
15319d66e2 Updating translations for config/locales/es_CR.yml 2020-04-23 12:27:58 +10:00
Robin Klaus
d8f4df4bcc Fixed missing translation, added keys to en.yml file 2020-04-23 09:58:47 +10:00
dependabot-preview[bot]
240d4a7802 Bump mini_racer from 0.2.9 to 0.2.10
Bumps [mini_racer](https://github.com/discourse/mini_racer) from 0.2.9 to 0.2.10.
- [Release notes](https://github.com/discourse/mini_racer/releases)
- [Changelog](https://github.com/rubyjs/mini_racer/blob/master/CHANGELOG)
- [Commits](https://github.com/discourse/mini_racer/compare/v0.2.9...v0.2.10)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-04-22 19:41:50 +00:00
Luis Ramos
3dff11e405 Merge pull request #5182 from luisramos0/nokogiri
Bump Nokogiri
2020-04-22 20:40:04 +01:00
Pau Perez
2d9b41729e Use memory cache-store when profiling
Or you want see any change when playing fragment-caching or other caching
strategies.
2020-04-22 17:56:56 +02:00
Pau Perez
de8d8e658c Add PROFILE var to set production-like settings
I took this from a recent newsletter I read. Sometimes replication
performance issues locally is actually slower than production due to dev
mode settings (code reloading, etc.), heavy de-only gems and the asset
pipeline.

The PROFILE env var switches these settings all at the same time,
giving us an environment closer to production, essential for reliable
profiling. Then, rack-mini-profiler is going to be more accurate.

Apparently it's something
[RubyGems](b026df86ae/config/environments/development.rb (L72-L92))
and
[CodeTriage](a3c957647d)
both use.
2020-04-22 17:53:17 +02:00
Pau Pérez Fabregat
a7013b5542 Merge pull request #5241 from Matt-Yorkley/remove-old-migrations
Remove old migrations!
2020-04-22 17:01:01 +02:00
Maikel
24fe7e8878 Merge pull request #5280 from openfoodfoundation/transifex
Transifex
2020-04-22 16:08:57 +10:00
Maikel
eb94c5a5bd Merge pull request #5283 from Matt-Yorkley/customer-tags
Fix disappearing tags issue
2020-04-22 16:03:17 +10:00
Matt-Yorkley
4ef61b642e Fix disappearing tags issue 2020-04-22 01:33:38 +02:00
Luis Ramos
23f4faf192 Merge pull request #4841 from luisramos0/kill_rabl
Hide broken product taxons field, remove last rabl template and rabl itself
2020-04-21 18:49:12 +01:00
Transifex-Openfoodnetwork
becd57f7a4 Updating translations for config/locales/fr.yml 2020-04-21 22:52:47 +10:00
Transifex-Openfoodnetwork
2e4b224d48 Updating translations for config/locales/en_FR.yml 2020-04-21 22:42:53 +10:00
Transifex-Openfoodnetwork
2b210bd096 Updating translations for config/locales/fr.yml 2020-04-21 22:42:34 +10:00
Matt-Yorkley
53183b8598 Eager-load properties in inject_enterprise_and_relatives 2020-04-21 11:13:20 +02:00
Pau Perez
91306d5ce4 Update all locales with the latest Transifex translations 2020-04-21 10:13:00 +02:00
Pau Pérez Fabregat
e20e19f963 Merge pull request #5244 from coopdevs/include-deleted-variants-and-products
Include deleted products in OC mailer
2020-04-20 20:46:21 +02:00
Luis Ramos
2ab07bc6a9 Make search box font size be 16px so that no zoom happens on iphone 2020-04-18 18:50:25 +01:00
Luis Ramos
15e56b21ae Merge pull request #5229 from chrishil1/missing_translation
Added missing translations to enterprise_relationship page
2020-04-18 18:15:54 +01:00
Luis Ramos
629db3ae4d Merge pull request #5230 from chrishil1/missing_translation_2
Add product translations to admin order creation
2020-04-18 18:15:01 +01:00
Luis Ramos
43274ecb4f Remove dead code
Dead since https://github.com/openfoodfoundation/openfoodnetwork/pull/3305
2020-04-18 14:47:33 +01:00
Luis Ramos
437c7367db Remove dead code 2020-04-18 14:37:07 +01:00
Lucas Hiago
acfe0c540a Create instagram css property and apply 2020-04-18 10:06:14 -03:00
Lucas Hiago
ac2ab34e11 Add connect with us footer to customer order confirmation email 2020-04-18 10:06:06 -03:00
Lucas Hiago
41c0204cfa Update instagram and linkedin links 2020-04-18 10:05:59 -03:00
Luis Ramos
910cc99c2f Add spec to cover orders_controller watch sortOptions 2020-04-18 10:23:02 +01:00
David Cook
a0a361673a Fix sorting of orders
(wrong copied function call)
2020-04-18 15:03:39 +10:00
jeffrey s hill md
70005a99a3 Added missing translations 2020-04-17 17:02:37 -05:00
Luis Ramos
8f8dce4bab Do not render inventory items in the shipment that dont have a line item in the order 2020-04-17 20:23:29 +01:00
Luis Ramos
8973a1b76c Merging 6 specs in one takes around 1 minute of execution time 2020-04-17 20:18:13 +01:00
Luis Ramos
c1b28543c6 Extract print ticket spec to a separate file 2020-04-17 20:07:45 +01:00
Luis Ramos
c33352904a Make spec a bit more resilient 2020-04-17 18:48:20 +01:00
Luis Ramos
8bd3062b16 Fix rubocop issues 2020-04-17 18:17:54 +01:00
jeffrey s hill md
ed91c179cd Changed translation paths 2020-04-17 12:04:27 -05:00
Luis Ramos
c7fb85a715 Replace background with members with before with let statements 2020-04-17 17:34:36 +01:00
Luis Ramos
e901615b61 Make spec simpler 2020-04-17 16:56:56 +01:00
Pau Perez
d8e6d98912 Preload line item's option_values
This fixes an N+1 with the query

```sql
SELECT "spree_option_values".* FROM "spree_option_values"
INNER JOIN "spree_option_types"
  ON "spree_option_types"."id" = "spree_option_values"."option_type_id"
INNER JOIN "spree_option_values_line_items"
  ON "spree_option_values"."id" = "spree_option_values_line_items"."option_value_id"
WHERE "spree_option_values_line_items"."line_item_id" = 1679
ORDER BY spree_option_types.position asc
```
2020-04-17 17:34:53 +02:00
Luis Ramos
c455dfb609 Make some specs faster by going directly to the order edit page and move incomplete order spec to a specific context 2020-04-17 16:28:27 +01:00
Pau Perez
63eb0980eb Memoize result of line items query
No need to fetch twice what we just loaded from DB.
2020-04-17 17:27:21 +02:00
Pau Perez
06ead827d8 Split long method 2020-04-17 17:27:21 +02:00
Pau Perez
6dd4a866e5 Address some Rubocop violations 2020-04-17 17:25:35 +02:00
Pau Perez
04c962432a Skip deleted default_scope in OC notification
This fixes the RuntimeError we get when accessing deleted variants due
to the variant being nil.

https://github.com/rails/rails/issues/11036 is still an open Rails bug,
as some people mention in https://github.com/rails/rails/pull/21550.

The issue is that `includes` doesn't respect `unscoped`. I found
a potential solution for the entire app in
https://github.com/rails/rails/issues/11036#issuecomment-302133116 but
our friend @markets has a gem,
https://github.com/markets/unscoped_associations, that solves that too.
2020-04-17 17:25:34 +02:00
Luis Ramos
d96d6b2337 Split orders_spec in two: tests for orders list page and tests for orders edit page 2020-04-17 15:21:03 +01:00
Luis Ramos
9147518422 Remove some unnecessary code 2020-04-17 14:51:06 +01:00
Luis Ramos
d23397f250 Move float test to a separate context 2020-04-17 14:49:09 +01:00
blainebillings
993a684e44 Add Price Sack Spec for Float Amounts 2020-04-17 14:43:28 +01:00
blainebillings
427dc54945 Change Result of PriceSack Calculation from Integers to Floats 2020-04-17 14:43:28 +01:00
Luis Ramos
ffceff3f0a Update GETTING_STARTED.md
Update link to osx catalina setup guide in wiki
2020-04-17 11:41:02 +01:00
Maikel Linke
b5d159e163 Add cache to mirror_db script
Also added some better error handling around image syncing.
2020-04-17 16:09:22 +10:00
Maikel Linke
4658a53aeb Update translations from Transifex 2020-04-17 15:37:54 +10:00
Maikel
3bc834435d Merge pull request #5152 from Matt-Yorkley/missing-indexes
Add missing indexes to spree_orders and spree_products
2020-04-17 15:16:03 +10:00
Maikel
9111ff1a38 Merge pull request #5211 from openfoodfoundation/transifex
Transifex
2020-04-17 14:24:26 +10:00
Maikel
b0eac1ecaa Merge branch 'master' into missing-indexes 2020-04-17 14:17:32 +10:00
Maikel
2e31f234d6 Merge pull request #5196 from Matt-Yorkley/customers-performance
Admin Customers performance
2020-04-17 13:28:39 +10:00
Maikel
e29a81cacc Merge pull request #5186 from oeoeaio/customer-totals-inventory-sku
Take sku overrides into account in customer totals report
2020-04-17 13:27:43 +10:00
Maikel
a672af1a79 Merge pull request #5237 from luisramos0/master_with_change
Clone of #5176
2020-04-17 13:27:14 +10:00
Maikel Linke
75207247e6 Correct database commands 2020-04-17 12:52:05 +10:00
Maikel Linke
8af40f4675 Format and indent migration message
It's much clearer to read this way:

```
==  OldMigrationsRemoved: migrating ===========================================
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

      You haven't updated your dev environment in a long time!
      Legacy migration files before 2019 have now been removed.
      Run `rails db:schema:load` before running `rails db:migrate`.

```
2020-04-17 12:47:49 +10:00
Maikel Linke
63ac6c5088 Remove superfluous conditional
A migration's `up` method is only run when the migration needs to be
applied. The only case we could have a higher version number is when a
migration with a higher version got merged before the current one. And
in that case, we still want this migration to fail, because it hasn't
been applied yet.
2020-04-17 12:40:54 +10:00
jeffrey s hill md
d8444dcf3c Added placeholders 2020-04-16 14:59:41 -05:00
Matt-Yorkley
71c7c35679 Remove old migrations! 🎉 2020-04-16 13:44:18 +02:00
Maikel
f282ff805d Merge pull request #5172 from kristinalim/feature/5170-increase_locale_chars_in_spree_users
Increase max characters for locale in spree_users
2020-04-16 18:18:45 +10:00
Transifex-Openfoodnetwork
2f7dc9a578 Updating translations for config/locales/es.yml 2020-04-16 17:09:44 +10:00
chrishil1
a9829ba5d9 Update _enterprise_relationship.html.haml 2020-04-15 17:01:22 -05:00
Luis Ramos
8532fa16cd Merge pull request #5202 from luisramos0/improve_checkout_js
Improve Checkout error handling in JS
2020-04-15 22:25:05 +01:00
chrishil1
c3f01be580 Fixed display all required tag 2020-04-15 19:00:35 +01:00
Luis Ramos
fcc746a1b7 Fix long lines in payments_controller_spec 2020-04-15 16:18:17 +01:00
Luis Ramos
8f7b3df9b5 Make payment controller authorize stripe_sca payments before processing them or advancing order workflow (that also calls payment.process) 2020-04-15 16:07:34 +01:00
jeffrey s hill md
e23045b19e Add product translations 2020-04-14 14:15:57 -05:00
jeffrey s hill md
5e1dea61a8 added missing translations to enterprise_relationship page 2020-04-14 11:20:56 -05:00
Luis Ramos
cedf1b26f2 If no flash is sent from the server, show the generic error 2020-04-14 14:31:34 +01:00
Luis Ramos
47a93568dc Make code simpler by extracting methods 2020-04-14 13:55:20 +01:00
Luis Ramos
62471bf2ab Clear Loading spinner when exception is caught 2020-04-14 13:50:38 +01:00
Luis Ramos
cdf5bcb7eb Improve unexpected error handling and add test cases for it 2020-04-14 13:44:58 +01:00
Luis Ramos
7414047b92 Switch from old success/error to modern then/catch structure
Catch() will get a few more errors then errors()

Also, add try/catch inside catch to detect any errors parsing the
response error payload
2020-04-14 13:04:28 +01:00
Pau Pérez Fabregat
4ef5dfe430 Merge pull request #5199 from openfoodfoundation/dependabot/bundler/rubocop-rails-2.5.2
Bump rubocop-rails from 2.5.1 to 2.5.2
2020-04-14 10:17:59 +02:00
Pau Pérez Fabregat
e58a1d080f Merge pull request #5205 from openfoodfoundation/dependabot/bundler/ddtrace-0.34.2
Bump ddtrace from 0.34.1 to 0.34.2
2020-04-14 10:17:06 +02:00
Luis Ramos
357a88fa22 Merge pull request #4786 from luisramos0/stripe_sca_extra_subs_fix
Make StripeSCA (with new authorize/purchase workflow) work with Subscriptions again
2020-04-13 17:21:53 +01:00
Rob H
f71045b3f2 Improve naming of variables in VariantOverridesIndexed for readability 2020-04-13 22:24:25 +10:00
Rob H
dcdd3f2444 Modify interface of VariantOverridesIndexed#indexed
Stop using keyword args and accept variant_ids instead of line_items
2020-04-13 22:11:58 +10:00
Rob H
6820919552 Rename VariantOverrides class to VariantOverridesIndexed 2020-04-13 21:56:37 +10:00
Rob H
4a4173bdc0 Move VariantOverrides class to app/services 2020-04-13 21:54:10 +10:00
Rob H
9a7e782102 Only load up variant overrides for relevant hubs 2020-04-13 12:07:17 +10:00
Transifex-Openfoodnetwork
9fa892346e Updating translations for config/locales/es_CR.yml 2020-04-13 10:30:00 +10:00
Transifex-Openfoodnetwork
7341912390 Updating translations for config/locales/pt_BR.yml 2020-04-12 07:14:21 +10:00
Transifex-Openfoodnetwork
d0c797b797 Updating translations for config/locales/es_CR.yml 2020-04-12 07:12:21 +10:00
Transifex-Openfoodnetwork
cb2e17d7dc Updating translations for config/locales/es_CR.yml 2020-04-12 07:09:21 +10:00
Transifex-Openfoodnetwork
147654df41 Updating translations for config/locales/es_CR.yml 2020-04-12 07:05:59 +10:00
Rob H
14cf168e3b Take sku overrides into account in customer totals report 2020-04-11 16:05:15 +10:00
dependabot-preview[bot]
c3ee7b7c64 Bump ddtrace from 0.34.1 to 0.34.2
Bumps [ddtrace](https://github.com/DataDog/dd-trace-rb) from 0.34.1 to 0.34.2.
- [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/v0.34.1...v0.34.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-04-10 19:19:13 +00:00
Matt-Yorkley
a6414b6dbe Make sure taggable_type is 'Customer' when querying customer tags 2020-04-10 20:14:14 +02:00
Matt-Yorkley
4c41c84cc1 Refactor tag rules loading for customers
Fixes N+1 queries on customer tags
2020-04-10 10:12:32 +02:00
Matt-Yorkley
e53f733966 Eager-load addresses in customer serializer 2020-04-10 08:20:15 +02:00
Matt-Yorkley
2a8809e6e8 Eager-load default card in customer serializer 2020-04-10 08:20:15 +02:00
Matt-Yorkley
31a54e49c5 Allow User#default_card to work with eager-loading 2020-04-10 08:20:13 +02:00
dependabot-preview[bot]
0fabde8849 Bump rubocop-rails from 2.5.1 to 2.5.2
Bumps [rubocop-rails](https://github.com/rubocop-hq/rubocop-rails) from 2.5.1 to 2.5.2.
- [Release notes](https://github.com/rubocop-hq/rubocop-rails/releases)
- [Changelog](https://github.com/rubocop-hq/rubocop-rails/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop-hq/rubocop-rails/compare/v2.5.1...v2.5.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-04-09 19:21:30 +00:00
Luis Ramos
314fed063d Merge property with property_decorator both in our codebase 2020-04-09 19:09:22 +01:00
Luis Ramos
0d5c08c363 Remove dead code, there's no Spree::Money in app/models/spree and the Spree::Money in lib/spree already has a class_eval with this function 2020-04-09 19:06:05 +01:00
Luis Ramos
59f56cb0f6 Remove before delivery method in checkout controller, this differentiator is never used in OFN, only in Spree frontend code 2020-04-09 17:32:28 +01:00
Matt-Yorkley
cf712e9478 Select only enterprise id 2020-04-09 17:41:13 +02:00
Luis Ramos
2ff8356c63 Delete dead code from products helper 2020-04-09 16:33:17 +01:00
Luis Ramos
4aad80c134 Update message for capybara with new upgrade blocker 2020-04-09 13:39:40 +01:00
Luis Ramos
71ffa6b178 Upgrade nokogiri as much as possible (it's not an explicit dependency of OFN and we dont need to control the version now, so I remove it from Gemfile) 2020-04-09 13:39:40 +01:00
Luis Ramos
e3de71668a Depend on a spree version in which spree_core doesnt depend on deface AND remove deface from list of dependencies 2020-04-09 13:39:40 +01:00
Matt-Yorkley
538e4e54d2 Set cart buttons to fixed width and expand when screen is too small 2020-04-08 11:19:14 +02:00
Matt-Yorkley
1ddbabd841 Adjust colours of primary buttons to use (bright) orange instead of (warning) red 2020-04-08 10:57:33 +02:00
Matt-Yorkley
0414f4984d Align buttons left and right on cart page 2020-04-08 10:55:55 +02:00
Matt-Yorkley
9c421e146e Remove arrows from cart and checkout buttons 2020-04-08 10:23:18 +02:00
Kristina Lim
e6cd33ee57 Increase max characters for locale in spree_users
There are many locales that have six (6) characters.
2020-04-07 15:08:49 +08:00
Matt-Yorkley
8a544f3ab3 Add missing indexes to spree_orders and spree_products 2020-04-04 10:12:15 +02:00
Luis Ramos
635ea9c505 Fix some long lines on variant_decorator 2020-03-30 11:21:47 +01:00
Luis Ramos
fbbe586996 Avoid rails 3 bug where the first where clause is overriden by a second where clause
Co-Authored-By: Maikel <maikel@email.org.au>
2020-03-30 11:21:47 +01:00
Luis Ramos
a5184cce9d Make method a bit more readable and add comment with details 2020-03-30 11:21:47 +01:00
Luis Ramos
69b57544f1 Bring Spree::Variant#active so that we can make it return just variants without includes
This makes the variants returned not readonly in rails 4 and thus fixes a spec in Spree::VariantsController#destroy
2020-03-30 11:21:47 +01:00
Matt-Yorkley
e014e6c1a4 Ensure perform_deliveries is correctly set when testing user confirmation emails 2020-03-24 13:12:20 +00:00
Luis Ramos
9994bc75ca Adapt reports controller to handle routes of reports in the order_management engine differently 2020-03-20 11:07:23 +00:00
Luis Ramos
3f5a964dec Move enterprise_fee_summaries_spec to order_management engine, moving
translation keys for the views and adapting some routes
2020-03-20 11:07:23 +00:00
Luis Ramos
b4befea606 Fix namespace in spec 2020-03-20 11:07:23 +00:00
Luis Ramos
58465c4645 Adapt routes placeholder in the new catalog engine to make it similar to the other engines 2020-03-20 11:07:23 +00:00
Luis Ramos
0b05312f19 Move cookies spec to web engine and adapt routes to the fact they are now normal main apps routes 2020-03-20 11:07:23 +00:00
Luis Ramos
e209452f8b Make engine routes just prepend to apps routes instead of creating engine routes
This makes things a bit simpler in terms of routing, we avoid a problem running specs and we can still have the engine routes separated in specific files
2020-03-20 11:07:23 +00:00
Luis Ramos
a8078b22f8 Move enterprise fees summaries controller and views to ordermanagement engine 2020-03-20 11:07:23 +00:00
Luis Ramos
da837ff100 Remove rabl dependency 🎉 2020-03-17 15:51:50 +00:00
Luis Ramos
da2598282b Can be object or {}, it's what the injector is doing, not related to rabl any more 2020-03-17 15:51:26 +00:00
Luis Ramos
0308f1465d Remove taxons/search action and respective rabl view
This is dead code
2020-03-17 15:51:26 +00:00
Luis Ramos
a6e4893287 Remove taxons list field from product edit form.
It is not working and it's not used in any other place in the app, there's the product category already (product.primary_taxon_id)
2020-03-17 15:51:25 +00:00
Luis Ramos
26769b4150 Add StripeSCA payment authorize and use it both subs_confirm job as well as on teh checkout stripe redirect 2020-03-16 20:04:59 +00:00
Luis Ramos
84745e4ccb Add stripe payment setup spec and make minor tweaks to the code itself.
Also, add a missing . to card_set? that eanbles it! If the card was
already set, it would anyway set the default card. Now it will use the
defined card if there is one already.
2020-03-16 20:03:12 +00:00
Luis Ramos
aac7a5e559 Adapt PaymentSetup spec to new version and remove some private method testing (payment) as well as some tests testing order.pending_payments logic 2020-03-16 20:03:12 +00:00
Luis Ramos
0a2941ed96 Extract StripePaymentSetup from PaymentSetup 2020-03-16 20:03:12 +00:00
655 changed files with 7915 additions and 10648 deletions

1
.gitignore vendored
View File

@@ -31,6 +31,7 @@ public/system
public/stylesheets
public/images
public/spree
public/assets
config/abr.yml
config/initializers/feature_toggle.rb
NERD_tree*

View File

@@ -88,7 +88,6 @@ Layout/LineLength:
- app/models/spree/tax_rate_decorator.rb
- app/models/spree/taxon_decorator.rb
- app/models/spree/user.rb
- app/models/spree/variant_decorator.rb
- app/models/subscription.rb
- app/models/variant_override.rb
- app/models/variant_override_set.rb
@@ -156,7 +155,6 @@ Layout/LineLength:
- spec/controllers/spree/admin/orders/customer_details_controller_spec.rb
- spec/controllers/spree/admin/orders_controller_spec.rb
- spec/controllers/spree/admin/payment_methods_controller_spec.rb
- spec/controllers/spree/admin/payments_controller_spec.rb
- spec/controllers/spree/admin/products_controller_spec.rb
- spec/controllers/spree/admin/reports_controller_spec.rb
- spec/controllers/spree/admin/variants_controller_spec.rb
@@ -181,7 +179,6 @@ Layout/LineLength:
- spec/features/admin/image_settings_spec.rb
- spec/features/admin/multilingual_spec.rb
- spec/features/admin/order_cycles_spec.rb
- spec/features/admin/orders_spec.rb
- spec/features/admin/overview_spec.rb
- spec/features/admin/payment_method_spec.rb
- spec/features/admin/product_import_spec.rb
@@ -377,7 +374,6 @@ Metrics/AbcSize:
- app/helpers/spree/admin/base_helper.rb
- app/helpers/spree/admin/zones_helper.rb
- app/helpers/spree/orders_helper.rb
- app/mailers/producer_mailer.rb
- app/models/calculator/flat_percent_per_item.rb
- app/models/column_preference.rb
- app/models/enterprise.rb
@@ -468,7 +464,6 @@ Metrics/BlockLength:
- spec/factories/shipping_method_factory.rb
- spec/factories/subscription_factory.rb
- spec/factories/variant_factory.rb
- spec/features/admin/orders_spec.rb
- spec/features/consumer/shopping/embedded_shopfronts_spec.rb
- spec/lib/open_food_network/group_buy_report_spec.rb
- spec/models/tag_rule/discount_order_spec.rb
@@ -574,7 +569,6 @@ Metrics/MethodLength:
- app/helpers/spree/admin/navigation_helper.rb
- app/helpers/spree/admin/base_helper.rb
- app/jobs/subscription_placement_job.rb
- app/mailers/producer_mailer.rb
- app/models/column_preference.rb
- app/models/enterprise.rb
- app/models/enterprise_relationship.rb
@@ -680,7 +674,6 @@ Metrics/ModuleLength:
- engines/order_management/spec/services/order_management/subscriptions/estimator_spec.rb
- engines/order_management/spec/services/order_management/subscriptions/form_spec.rb
- engines/order_management/spec/services/order_management/subscriptions/proxy_order_syncer_spec.rb
- engines/order_management/spec/services/order_management/subscriptions/payment_setup_spec.rb
- engines/order_management/spec/services/order_management/subscriptions/summarizer_spec.rb
- engines/order_management/spec/services/order_management/subscriptions/validator_spec.rb
- engines/order_management/spec/services/order_management/subscriptions/variants_list_spec.rb

View File

@@ -173,7 +173,6 @@ Naming/MethodParameterName:
Naming/PredicateName:
Exclude:
- 'spec/**/*'
- 'app/mailers/producer_mailer.rb'
- 'app/models/enterprise.rb'
- 'app/models/enterprise_relationship.rb'
- 'app/models/order_cycle.rb'
@@ -630,7 +629,6 @@ Style/FrozenStringLiteralComment:
- 'app/jobs/subscription_placement_job.rb'
- 'app/jobs/welcome_enterprise_job.rb'
- 'app/mailers/enterprise_mailer.rb'
- 'app/mailers/producer_mailer.rb'
- 'app/mailers/spree/base_mailer_decorator.rb'
- 'app/mailers/spree/order_mailer_decorator.rb'
- 'app/mailers/spree/user_mailer.rb'
@@ -855,7 +853,6 @@ Style/FrozenStringLiteralComment:
- 'app/validators/date_time_string_validator.rb'
- 'app/validators/distributors_validator.rb'
- 'app/validators/integer_array_validator.rb'
- 'app/views/spree/admin/taxons/search.rabl'
- 'config.ru'
- 'engines/order_management/app/controllers/order_management/application_controller.rb'
- 'engines/order_management/app/services/order_management/reports/enterprise_fee_summary/authorizer.rb'

View File

@@ -52,3 +52,5 @@ The default admin user is 'ofn@example.com' with 'ofn123' password.
Check the app in the browser at `http://localhost:3000`.
You will then get the trace of the containers in the terminal. You can stop the containers using Ctrl-C in the terminal.
You can find some useful tips and commands [here](https://github.com/openfoodfoundation/openfoodnetwork/wiki/Docker:-useful-tips-and-commands).

View File

@@ -27,6 +27,9 @@ RUN sh -c "echo 'deb https://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main'
apt-get update && \
apt-get install -yqq --no-install-recommends postgresql-client-9.5 libpq-dev
# Install node
RUN apt-get install -y nodejs
# Install Chrome
RUN wget --quiet -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
sh -c "echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' >> /etc/apt/sources.list.d/google-chrome.list" && \

View File

@@ -2,6 +2,8 @@
This is a general guide to setting up an Open Food Network development environment on your local machine.
The fastest way to make it work locally is to use Docker, see the [Docker setup guide](DOCKER.md).
The following guides are located in the wiki and provide more OS-specific step-by-step instructions:
- [Ubuntu Setup Guide][ubuntu]
@@ -11,7 +13,7 @@ The following guides are located in the wiki and provide more OS-specific step-b
### Dependencies
* Rails 3.2.x
* Ruby 2.1.9
* Ruby 2.3.7
* PostgreSQL database
* PhantomJS (for testing)
* See Gemfile for a list of gems required
@@ -58,10 +60,10 @@ Now, your dreams of spinning up a development server can be realised:
bundle exec rails server
To login as Spree default user, use:
To login as the default user, use:
email: spree@example.com
password: spree123
email: ofn@example.com
password: ofn123
### Testing
@@ -118,7 +120,7 @@ $ createdb open_food_network_test --owner=ofn
If these commands succeed, you should be able to [continue the setup process](#get-it-running).
[developer-wiki]: https://github.com/openfoodfoundation/openfoodnetwork/wiki
[sierra]: https://github.com/openfoodfoundation/openfoodnetwork/wiki/Development-Environment-Setup%3A-macOS-%28Sierra%2C-HighSierra-and-Mojave%29
[sierra]: https://github.com/openfoodfoundation/openfoodnetwork/wiki/Development-Environment-Setup%3A-macOS-%28Sierra%2C-HighSierra%2C-Mojave-and-Catalina%29
[el-capitan]: https://github.com/openfoodfoundation/openfoodnetwork/wiki/Development-Environment-Setup:-OS-X-(El-Capitan)
[ubuntu]: https://github.com/openfoodfoundation/openfoodnetwork/wiki/Development-Environment-Setup:-Ubuntu
[wiki]: https://github.com/openfoodfoundation/openfoodnetwork/wiki

View File

@@ -9,8 +9,6 @@ gem 'rails-i18n', '~> 3.0.0'
gem 'rails_safe_tasks', '~> 1.0'
gem "activerecord-import"
# Patched version. See http://rubysec.com/advisories/CVE-2015-5312/.
gem 'nokogiri', '>= 1.6.7.1'
gem "catalog", path: "./engines/catalog"
gem "order_management", path: "./engines/order_management"
@@ -55,7 +53,6 @@ gem 'aws-sdk'
gem 'bugsnag'
gem 'db2fog'
gem 'haml'
gem 'rabl'
gem 'redcarpet'
gem 'sass', "~> 3.3"
gem 'sass-rails', '~> 3.2.3'
@@ -70,7 +67,6 @@ gem 'angularjs-file-upload-rails', '~> 2.4.1'
gem 'blockenspiel'
gem 'custom_error_message', github: 'jeremydurham/custom-err-msg'
gem 'dalli'
gem 'deface', '1.0.2'
gem 'diffy'
gem 'figaro'
gem 'geocoder'
@@ -98,7 +94,7 @@ gem 'test-unit', '~> 3.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'compass-rails'
gem 'mini_racer', '0.2.9'
gem 'mini_racer', '0.2.10'
gem 'uglifier', '>= 1.0.3'
@@ -125,7 +121,7 @@ group :test, :development do
# Pretty printed test output
gem 'atomic'
gem 'awesome_print'
gem 'capybara', '>= 2.18.0' # 3.0 requires nokogiri 1.8
gem 'capybara', '>= 2.18.0' # 3.0 requires rack 1.6 that only works with Rails 4.2
gem 'database_cleaner', '0.7.1', require: false
gem "factory_bot_rails", require: false
gem 'fuubar', '~> 2.5.0'

View File

@@ -23,7 +23,7 @@ GIT
GIT
remote: https://github.com/openfoodfoundation/spree.git
revision: 8a8585a43cd04d1a50dc65227f337a91b18d66d5
revision: e10ca1f689b1658040b081939b7523f6fb68895a
branch: 2-0-4-stable
specs:
spree_core (2.0.4)
@@ -32,14 +32,13 @@ GIT
awesome_nested_set (= 2.1.5)
aws-sdk (~> 1.11.1)
cancan (~> 1.6.10)
deface (>= 0.9.1)
ffaker (~> 1.16)
highline (= 1.6.18)
httparty (~> 0.11)
json (>= 1.7.7)
kaminari (~> 0.14.1)
money (= 5.1.1)
paperclip (~> 3.0)
paperclip (~> 3.4.1)
paranoia (~> 1.3)
rails (~> 3.2.14)
ransack (= 0.7.2)
@@ -167,7 +166,6 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.10.0)
colorize (0.8.1)
combine_pdf (1.0.16)
ruby-rc4 (>= 0.1.5)
compass (1.0.3)
@@ -198,14 +196,9 @@ GEM
activerecord (>= 3.2.0, < 5.0)
fog (~> 1.0)
rails (>= 3.2.0, < 5.0)
ddtrace (0.34.1)
ddtrace (0.35.1)
msgpack
debugger-linecache (1.2.0)
deface (1.0.2)
colorize (>= 0.5.8)
nokogiri (~> 1.6.0)
polyglot
rails (>= 3.1)
delayed_job (4.1.8)
activesupport (>= 3.0, < 6.1)
delayed_job_active_record (4.1.4)
@@ -238,7 +231,7 @@ GEM
railties (>= 3.0.0)
faraday (1.0.0)
multipart-post (>= 1.2, < 3)
ffaker (1.22.1)
ffaker (1.32.1)
ffi (1.12.2)
figaro (1.1.1)
thor (~> 0.14)
@@ -449,9 +442,9 @@ GEM
method_source (0.9.2)
mime-types (1.25.1)
mini_mime (1.0.1)
mini_portile2 (2.1.0)
mini_racer (0.2.9)
libv8 (>= 6.9.411)
mini_portile2 (2.4.0)
mini_racer (0.2.10)
libv8 (> 7.3)
momentjs-rails (2.20.1)
railties (>= 3.1)
money (5.1.1)
@@ -461,8 +454,8 @@ GEM
multi_xml (0.6.0)
multipart-post (2.1.1)
newrelic_rpm (3.18.1.330)
nokogiri (1.6.8.1)
mini_portile2 (~> 2.1.0)
nokogiri (1.10.9)
mini_portile2 (~> 2.4.0)
oauth2 (1.4.4)
faraday (>= 0.8, < 2.0)
jwt (>= 1.0, < 3.0)
@@ -483,7 +476,7 @@ GEM
parallel (1.19.1)
paranoia (1.3.4)
activerecord (~> 3.1)
parser (2.7.0.5)
parser (2.7.1.0)
ast (~> 2.4.0)
paypal-sdk-core (0.2.10)
multi_json (~> 1.0)
@@ -502,8 +495,6 @@ GEM
byebug (>= 9.0, < 9.1)
pry (~> 0.10)
public_suffix (4.0.3)
rabl (0.8.4)
activesupport (>= 2.3.14)
rack (1.4.7)
rack-cache (1.11.0)
rack (>= 0.4)
@@ -596,7 +587,7 @@ GEM
rexml
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-rails (2.5.1)
rubocop-rails (2.5.2)
activesupport
rack (>= 1.1)
rubocop (>= 0.72.0)
@@ -656,7 +647,7 @@ GEM
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.7.0)
unicorn (5.5.4)
unicorn (5.5.5)
kgio (~> 2.6)
raindrops (~> 0.7)
unicorn-rails (2.2.1)
@@ -715,7 +706,6 @@ DEPENDENCIES
db2fog
ddtrace
debugger-linecache
deface (= 1.0.2)
delayed_job_active_record
delayed_job_web
devise (~> 2.2.5)
@@ -742,10 +732,9 @@ DEPENDENCIES
kaminari (~> 0.14.1)
knapsack
letter_opener (>= 1.4.1)
mini_racer (= 0.2.9)
mini_racer (= 0.2.10)
momentjs-rails
newrelic_rpm (~> 3.0)
nokogiri (>= 1.6.7.1)
oauth2 (~> 1.4.4)
ofn-qz!
oj
@@ -754,7 +743,6 @@ DEPENDENCIES
paperclip (~> 3.4.1)
pg (~> 0.21.0)
pry-byebug (>= 3.4.3)
rabl
rack-mini-profiler (< 3.0.0)
rack-rewrite
rack-ssl

View File

@@ -29,7 +29,7 @@ angular.module("admin.enterprises")
# from a directive "nav-check" in the page - if we pass it here it will be called in the test suite,
# and on all new uses of this contoller, and we might not want that.
enterpriseNavCallback = ->
if $scope.enterprise_form != undefined && $scope.enterprise_form.$dirty
if $scope.enterprise_form?.$dirty
t('admin.unsaved_confirm_leave')
# Register the NavigationCheck callback

View File

@@ -1,5 +1,5 @@
angular.module('admin.orderCycles')
.controller 'AdminEditOrderCycleCtrl', ($scope, $controller, $filter, $location, $window, OrderCycle, Enterprise, EnterpriseFee, StatusMessage, Schedules, RequestMonitor, ocInstance) ->
.controller 'AdminEditOrderCycleCtrl', ($scope, $controller, $filter, $location, $window, OrderCycle, Enterprise, EnterpriseFee, StatusMessage, Schedules, RequestMonitor, NavigationCheck, ocInstance) ->
$controller('AdminOrderCycleBasicCtrl', {$scope: $scope, ocInstance: ocInstance})
order_cycle_id = $location.absUrl().match(/\/admin\/order_cycles\/(\d+)/)[1]
@@ -18,5 +18,12 @@ angular.module('admin.orderCycles')
$scope.submit = ($event, destination) ->
$event.preventDefault()
NavigationCheck.clear()
StatusMessage.display 'progress', t('js.saving')
OrderCycle.update(destination, $scope.order_cycle_form)
warnAboutUnsavedChanges = ->
if $scope.order_cycle_form?.$dirty
t('admin.unsaved_confirm_leave')
NavigationCheck.register(warnAboutUnsavedChanges)

View File

@@ -67,7 +67,7 @@ angular.module("admin.orders").controller "ordersCtrl", ($scope, $timeout, Reque
return unless sort && sort.predicate != ""
$scope.sorting = sort.getSortingExpr()
$scope.fetchProducts()
$scope.fetchResults()
, true
$scope.capturePayment = (order) ->

View File

@@ -0,0 +1,11 @@
Darkswarm.directive "darkerBackground", ->
restrict: "A"
link: (scope, elm, attr)->
toggleClass = (value) ->
elm.closest('.page-view').toggleClass("with-darker-background", value)
toggleClass(true)
# if an OrderCycle is selected, disable darker background
scope.$watch 'order_cycle.order_cycle_id', (newvalue, oldvalue) ->
toggleClass(false) if newvalue

View File

@@ -5,5 +5,9 @@ Darkswarm.directive "shopVariant", ->
scope:
variant: '='
controller: ($scope, Cart) ->
$scope.$watchGroup ['variant.line_item.quantity', 'variant.line_item.max_quantity'], ->
$scope.$watchGroup [
'variant.line_item.quantity',
'variant.line_item.max_quantity'
], (new_value, old_value) ->
return if old_value[0] == null && new_value[0] == null
Cart.adjust($scope.variant.line_item)

View File

@@ -1,4 +1,4 @@
Darkswarm.factory 'Cart', (CurrentOrder, Variants, $timeout, $http, $modal, $rootScope, $resource, localStorageService) ->
Darkswarm.factory 'Cart', (CurrentOrder, Variants, $timeout, $http, $modal, $rootScope, $resource, localStorageService, RailsFlashLoader) ->
# Handles syncing of current cart/order state to server
new class Cart
dirty: false
@@ -50,7 +50,7 @@ Darkswarm.factory 'Cart', (CurrentOrder, Variants, $timeout, $http, $modal, $roo
@popQueue() if @update_enqueued
.error (response, status)=>
@scheduleRetry(status)
RailsFlashLoader.loadFlash({error: t('js.cart.add_to_cart_failed')})
@update_running = false
compareAndNotifyStockLevels: (stockLevels) =>
@@ -87,13 +87,6 @@ Darkswarm.factory 'Cart', (CurrentOrder, Variants, $timeout, $http, $modal, $roo
max_quantity: li.max_quantity
{variants: variants}
scheduleRetry: (status) =>
console.log "Error updating cart: #{status}. Retrying in 3 seconds..."
$timeout =>
console.log "Retrying cart update"
@orderChanged()
, 3000
saved: =>
@dirty = false
$(window).unbind "beforeunload"

View File

@@ -14,15 +14,28 @@ Darkswarm.factory 'Checkout', ($injector, CurrentOrder, ShippingMethods, StripeE
submit: =>
Loading.message = t 'submitting_order'
$http.put('/checkout.json', {order: @preprocess()}).success (data, status)=>
Navigation.go data.path
.error (response, status)=>
if response.path
Navigation.go response.path
else
Loading.clear()
@errors = response.errors
RailsFlashLoader.loadFlash(response.flash)
$http.put('/checkout.json', {order: @preprocess()})
.then (response) =>
Navigation.go response.data.path
.catch (response) =>
try
@handle_checkout_error_response(response)
catch error
@loadFlash(error: t("checkout.failed")) # inform the user about the unexpected error
throw error # generate a BugsnagJS alert
handle_checkout_error_response: (response) =>
if response.data.path
Navigation.go response.data.path
else
throw response unless response.data.flash
@errors = response.data.errors
@loadFlash(response.data.flash)
loadFlash: (flash) =>
Loading.clear()
RailsFlashLoader.loadFlash(flash)
# Rails wants our Spree::Address data to be provided with _attributes
preprocess: ->

View File

@@ -1,6 +1,6 @@
Darkswarm.factory 'OrderCycle', ($resource, orderCycleData) ->
class OrderCycle
@order_cycle = orderCycleData # Object or {} due to RABL
@order_cycle = orderCycleData # Object or {}
@push_order_cycle: (callback) ->
new $resource("/shop/order_cycle").save {order_cycle_id: @order_cycle.order_cycle_id}, (order_data)->
OrderCycle.order_cycle.orders_close_at = order_data.orders_close_at

View File

@@ -8,4 +8,4 @@
%hr
%div.menu_item.text-center
%input.fullwidth.orange{ type: "button", ng: { value: "saved() ? 'Saved': 'Saving'", show: "saved() || saving", disabled: "saved()" } }
%input.fullwidth.red{ type: "button", value: 'Save As Default', ng: { show: "!saved() && !saving", click: "saveColumnPreferences(action)"} }
%input.fullwidth.red{ type: "button", :value => t('admin.column_save_as_default').html_safe, ng: { show: "!saved() && !saving", click: "saveColumnPreferences(action)"} }

View File

@@ -6,6 +6,8 @@
min: 0,
placeholder: "0",
"ofn-disable-scroll" => true,
"ng-debounce" => "500",
onwheel: "this.blur()",
"ng-model" => "variant.line_item.quantity",
"ofn-on-hand" => "{{variant.on_demand && 9999 || variant.on_hand }}",
"ng-disabled" => "!variant.on_demand && variant.on_hand == 0",

View File

@@ -9,6 +9,8 @@
"ng-model" => "variant.line_item.quantity",
placeholder: "{{::'shop_variant_quantity_min' | t}}",
"ofn-disable-scroll" => true,
"ng-debounce" => "500",
onwheel: "this.blur()",
"ofn-on-hand" => "{{variant.on_demand && 9999 || variant.on_hand }}",
name: "variants[{{::variant.id}}]", id: "variants_{{::variant.id}}"}
%span.bulk-input
@@ -19,6 +21,8 @@
"ng-model" => "variant.line_item.max_quantity",
placeholder: "{{::'shop_variant_quantity_max' | t}}",
"ofn-disable-scroll" => true,
"ng-debounce" => "500",
onwheel: "this.blur()",
min: "{{variant.line_item.quantity}}",
name: "variant_attributes[{{::variant.id}}][max_quantity]",
id: "variants_{{::variant.id}}_max"}

View File

@@ -9,6 +9,9 @@
input#search {
@include medium-input(rgba(0, 0, 0, 0.3), #777, $clr-brick);
// avoid zoom on iphone, see issue #4535
font-size: 1rem;
}
// ordering

View File

@@ -49,7 +49,7 @@ ordercycle {
border-radius: 0.25em 0 0 0.25em;
float: left;
font-size: 1em;
line-height: 1.5em;
line-height: 1.3em;
padding: 0.5em 0.75em;
height: 2.35em;
@@ -60,6 +60,15 @@ ordercycle {
}
select {
background-image: url('/assets/white-caret.svg');
}
p {
text-align: left;
}
select,
p {
width: inherit;
display: inline-block;
color: $white;
@@ -67,10 +76,9 @@ ordercycle {
border: 0;
margin-bottom: 0;
font-size: 1em;
line-height: 1.5em;
line-height: 1.3em;
padding: 0.5em 1.25em 0.5em 0.75em;
height: 2.35em;
background-image: url('/assets/white-caret.svg');
background-size: 30px auto;
border-radius: 0 0.25em 0.25em 0;
min-width: 13em;
@@ -80,6 +88,10 @@ ordercycle {
}
}
option {
color: $grey-700;
}
@media all and (max-width: 1024px) {
float: none;
margin-right: 1em;

View File

@@ -38,14 +38,15 @@ $med-drk-grey: #444;
$dark-grey: #333;
$light-grey: #ddd;
$light-grey-transparency: rgba(0, 0, 0, .1);
$very-light-grey-transparency: rgba(0, 0, 0, .05);
$black: #000;
$white: #fff;
$grey-050: #f7f7f7;
$grey-400: #bbb;
$grey-500: #999;
$grey-600: #777;
$grey-650: #666;
$grey-700: #555;
$grey-800: #333;
@@ -54,6 +55,7 @@ $teal-400: #4cb5c5;
$teal-500: #0096ad;
$orange-400: #ff9466;
$orange-450: #f4704c;
$orange-500: #f27052;
$orange-600: #d7583a;

View File

@@ -114,7 +114,16 @@
margin-bottom: 0px;
}
.shopfront-message {
.select-oc-message {
margin-top: 1rem;
.highlighted {
color: $red-700;
font-weight: bold;
}
}
.open-shop-message {
a {
color: #0096ad;
@@ -125,21 +134,44 @@
}
}
.shopfront_closed_message, .shopfront_hidden_message {
padding: 15px;
border-radius: 5px;
.closed-shop-header {
background-color: $grey-650;
color: $white;
h4 {
color: $white;
}
p {
margin: 1rem 0 0.4rem;
}
.message {
display: inline-block;
}
}
.shopfront_closed_message {
border: 2px solid #eb4c46;
}
.warning-sign {
margin: 0 10px 0 5px;
display: inline-block;
.shopfront_closed_message {
margin: 2em 0em;
}
strong {
color: $grey-650;
display: block;
position: relative;
text-align: center;
width: 23px;
}
.shopfront_hidden_message {
border: 2px solid #db4;
margin: 2em 0em;
.rectangle {
background-color: $white;
border-radius: 4px;
color: $grey-650;
height: 23px;
position: absolute;
top: 27px;
transform: rotate(-315deg);
width: 23px;
}
}
}

View File

@@ -76,9 +76,9 @@
// content revealed in accordion
.page-view {
margin-bottom: 5em;
background: none;
border: none;
padding-bottom: 5em;
.content {
padding: 1.25em 0;
@@ -121,5 +121,13 @@
margin-bottom: 2px;
}
}
&.with-darker-background {
background-color: $very-light-grey-transparency;
a {
color: $teal-500;
}
}
}
}

View File

@@ -115,3 +115,14 @@
height: 36px;
}
}
.links {
.button {
padding: 1.125rem 0 1.1875rem;
width: 210px;
@media all and (max-width: 480px) {
width: 100%;
}
}
}

View File

@@ -64,13 +64,13 @@
.button.primary, button.primary {
font-family: $body-font;
background: $clr-brick;
background: $orange-450;
color: white;
}
.button.primary:hover, .button.primary:active, .button.primary:focus, button.primary:hover, button.primary:active, button.primary:focus {
background: $clr-brick-bright;
text-shadow: 0 1px 0 $clr-brick;
background: $orange-400;
text-shadow: 0 1px 0 $orange-450;
}
button.success, .button.success {

View File

@@ -138,6 +138,10 @@ a {
&.ms {
background-color: #000 !important;
}
&.ig {
background-color: #fb3958 !important;
}
}
.sidebar .soc-btn {

View File

@@ -17,8 +17,9 @@ module Admin
respond_to do |format|
format.html
format.json do
tag_rule_mapping = TagRule.mapping_for(Enterprise.where(id: params[:enterprise_id]))
render_as_json @collection, tag_rule_mapping: tag_rule_mapping
render_as_json @collection,
tag_rule_mapping: tag_rule_mapping,
customer_tags: customer_tags_by_id
end
end
end
@@ -64,8 +65,13 @@ module Admin
def collection
return Customer.where("1=0") unless json_request? && params[:enterprise_id].present?
enterprise = Enterprise.managed_by(spree_current_user).find_by_id(params[:enterprise_id])
Customer.of(enterprise)
Customer.of(managed_enterprise_id).
includes(:bill_address, :ship_address, user: :credit_cards)
end
def managed_enterprise_id
@managed_enterprise_id ||= Enterprise.managed_by(spree_current_user).
select('enterprises.id').find_by_id(params[:enterprise_id])
end
def load_managed_shops
@@ -80,5 +86,28 @@ module Admin
def ams_prefix_whitelist
[:subscription]
end
def tag_rule_mapping
TagRule.mapping_for(Enterprise.where(id: managed_enterprise_id))
end
# Fetches tags for all customers of the enterprise and returns a hash indexed by customer_id
def customer_tags_by_id
customer_tags = ::ActsAsTaggableOn::Tag.
joins(:taggings).
includes(:taggings).
where(taggings:
{ taggable_type: 'Customer',
taggable_id: Customer.of(managed_enterprise_id),
context: 'tags' })
customer_tags.each_with_object({}) do |tag, indexed_hash|
tag.taggings.each do |tagging|
customer_id = tagging.taggable_id
indexed_hash[customer_id] ||= []
indexed_hash[customer_id] << tag.name
end
end
end
end
end

View File

@@ -1,9 +1,13 @@
module Admin
class EnterpriseRelationshipsController < ResourceController
def index
@my_enterprises = Enterprise.managed_by(spree_current_user).by_name
@all_enterprises = Enterprise.by_name
@enterprise_relationships = EnterpriseRelationship.by_name.involving_enterprises @my_enterprises
@my_enterprises = Enterprise.
includes(:shipping_methods, :payment_methods).
managed_by(spree_current_user).by_name
@all_enterprises = Enterprise.includes(:shipping_methods, :payment_methods).by_name
@enterprise_relationships = EnterpriseRelationship.
includes(:parent, :child).
by_name.involving_enterprises @my_enterprises
end
def create

View File

@@ -1,11 +1,18 @@
module Api
class OrderCyclesController < Api::BaseController
include EnterprisesHelper
respond_to :json
include ApiActionCaching
skip_authorization_check
skip_before_filter :authenticate_user, :ensure_api_key, only: [:taxons, :properties]
caches_action :taxons, :properties,
expires_in: CacheService::FILTERS_EXPIRY,
cache_path: proc { |controller| controller.request.url }
def products
return render_no_products unless order_cycle.open?
products = ProductsRenderer.new(
distributor,
order_cycle,
@@ -15,7 +22,7 @@ module Api
render json: products
rescue ProductsRenderer::NoProducts
render status: :not_found, json: ''
render_no_products
end
def taxons
@@ -35,6 +42,10 @@ module Api
private
def render_no_products
render status: :not_found, json: ''
end
def product_properties
Spree::Property.
joins(:products).
@@ -70,11 +81,11 @@ module Api
end
def distributor
Enterprise.find_by_id(params[:distributor])
@distributor ||= Enterprise.find_by_id(params[:distributor])
end
def order_cycle
OrderCycle.find_by_id(params[:id])
@order_cycle ||= OrderCycle.find_by_id(params[:id])
end
def customer

View File

@@ -14,10 +14,6 @@ class BaseController < ApplicationController
helper 'spree/base'
# Spree::Core::ControllerHelpers declares helper_method get_taxonomies, so we need to
# include Spree::ProductsHelper so that method is available on the controller
include Spree::ProductsHelper
before_filter :set_locale
before_filter :check_order_cycle_expiry

View File

@@ -4,24 +4,24 @@ class CartController < BaseController
before_filter :check_authorization
def populate
order = current_order(true)
# Without intervention, the Spree::Adjustment#update_adjustable callback is called many times
# during cart population, for both taxation and enterprise fees. This operation triggers a
# costly Spree::Order#update!, which only needs to be run once. We avoid this by disabling
# callbacks on Spree::Adjustment and then manually invoke Spree::Order#update! on success.
Spree::Adjustment.without_callbacks do
cart_service = CartService.new(current_order(true))
cart_service = CartService.new(order)
if cart_service.populate(params.slice(:products, :variants, :quantity), true)
fire_event('spree.cart.add')
fire_event('spree.order.contents_changed')
current_order.cap_quantity_at_stock!
current_order.update!
order.update_distribution_charge!
order.cap_quantity_at_stock!
order.update!
variant_ids = variant_ids_in(cart_service.variants_h)
render json: { error: false,
stock_levels: VariantsStockLevels.new.call(current_order, variant_ids) },
stock_levels: VariantsStockLevels.new.call(order, variant_ids) },
status: :ok
else
render json: { error: true }, status: :precondition_failed

View File

@@ -133,13 +133,6 @@ class CheckoutController < Spree::StoreController
@order.ship_address = finder.ship_address
end
def before_delivery
return if params[:order].present?
packages = @order.shipments.map(&:to_package)
@differentiator = Spree::Stock::Differentiator.new(@order, packages)
end
def before_payment
current_order.payments.destroy_all if request.put?
end
@@ -153,10 +146,12 @@ class CheckoutController < Spree::StoreController
end
def valid_payment_intent_provided?
params["payment_intent"]&.starts_with?("pi_") &&
@order.state == "payment" &&
@order.payments.last.state == "pending" &&
@order.payments.last.response_code == params["payment_intent"]
return false unless params["payment_intent"]&.starts_with?("pi_")
last_payment = OrderPaymentFinder.new(@order).last_payment
@order.state == "payment" &&
last_payment&.state == "pending" &&
last_payment&.response_code == params["payment_intent"]
end
def handle_redirect_from_stripe

View File

@@ -18,9 +18,9 @@ class HomeController < BaseController
private
# Cache the value of the query count for 24 hours
def cached_count(key, query)
Rails.cache.fetch("home_stats_count_#{key}", expires_in: 1.day, race_condition_ttl: 10) do
# Cache the value of the query count
def cached_count(statistic, query)
CacheService.home_stats(statistic) do
query.count
end
end

View File

@@ -4,10 +4,6 @@ module Spree
after_filter :initialize_mail_settings
def update
if params[:smtp_password].blank?
params.delete(:smtp_password)
end
params.each do |name, value|
next unless Spree::Config.has_preference? name

View File

@@ -29,6 +29,8 @@ module Spree
return
end
authorize_stripe_sca_payment
if @order.completed?
@payment.process!
flash[:success] = flash_message_for(@payment, :successfully_created)
@@ -93,7 +95,7 @@ module Spree
available(:back_end).
select{ |pm| pm.has_distributor? @order.distributor }
@payment_method = if @payment && @payment.payment_method
@payment_method = if @payment&.payment_method
@payment.payment_method
else
@payment_methods.first
@@ -124,6 +126,13 @@ module Spree
def load_payment
@payment = Payment.find(params[:id])
end
def authorize_stripe_sca_payment
return unless @payment.payment_method.class == Spree::Gateway::StripeSCA
@payment.authorize!
raise Spree::Core::GatewayError, I18n.t('authorization_failure') unless @payment.pending?
end
end
end
end

View File

@@ -1,66 +0,0 @@
module Spree
module Admin
module Reports
class EnterpriseFeeSummariesController < BaseController
before_filter :load_report_parameters
before_filter :load_permissions
def new; end
def create
return respond_to_invalid_parameters unless @report_parameters.valid?
@report_parameters.authorize!(@permissions)
@report = report_klass::ReportService.new(@permissions, @report_parameters)
renderer.render(self)
rescue ::Reports::Authorizer::ParameterNotAllowedError => e
flash[:error] = e.message
render_report_form
end
private
def respond_to_invalid_parameters
flash[:error] = I18n.t("invalid_filter_parameters", scope: i18n_scope)
render_report_form
end
def i18n_scope
"order_management.reports.enterprise_fee_summary"
end
def render_report_form
render action: :new
end
def report_klass
OrderManagement::Reports::EnterpriseFeeSummary
end
def load_report_parameters
@report_parameters = report_klass::Parameters.new(params[:report] || {})
end
def load_permissions
@permissions = report_klass::Permissions.new(spree_current_user)
end
def report_renderer_klass
case params[:report_format]
when "csv"
report_klass::Renderers::CsvRenderer
when nil, "", "html"
report_klass::Renderers::HtmlRenderer
else
raise Reports::UnsupportedReportFormatException
end
end
def renderer
@renderer ||= report_renderer_klass.new(@report)
end
end
end
end
end

View File

@@ -298,11 +298,20 @@ module Spree
end
def url_for_report(report)
public_send("#{report}_admin_reports_url".to_sym)
if report_in_order_management_engine?(report)
main_app.public_send("new_order_management_reports_#{report}_url".to_sym)
else
public_send("#{report}_admin_reports_url".to_sym)
end
rescue NoMethodError
url_for([:new, :admin, :reports, report.to_s.singularize])
end
# List of reports that have been moved to the Order Management engine
def report_in_order_management_engine?(report)
report == :enterprise_fee_summary
end
def timestamp
Time.zone.now.strftime("%Y%m%d")
end

View File

@@ -3,14 +3,6 @@ module Spree
class TaxonsController < Spree::Admin::BaseController
respond_to :html, :json, :js
def search
@taxons = if params[:ids]
Spree::Taxon.where(id: params[:ids].split(','))
else
Spree::Taxon.limit(20).search(name_cont: params[:q]).result
end
end
def create
@taxonomy = Taxonomy.find(params[:taxonomy_id])
@taxon = @taxonomy.taxons.build(params[:taxon])

View File

@@ -47,7 +47,7 @@ module InjectionHelper
enterprises_and_relatives = current_distributor.
relatives_including_self.
activated.
includes(address: [:state, :country]).
includes(:properties, address: [:state, :country], supplied_products: :properties).
all
inject_json_ams "enterprises",

View File

@@ -0,0 +1,7 @@
# frozen_string_literal: true
module OrderHelper
def last_payment_method(order)
OrderPaymentFinder.new(order).last_payment&.payment_method
end
end

View File

@@ -13,7 +13,7 @@ module ShopHelper
end
def require_customer?
current_distributor.require_login? && !user_is_related_to_distributor?
@require_customer ||= current_distributor.require_login? && !user_is_related_to_distributor?
end
def user_is_related_to_distributor?
@@ -48,6 +48,6 @@ module ShopHelper
end
def no_open_order_cycles?
@order_cycles && @order_cycles.empty?
@no_open_order_cycles ||= @order_cycles&.empty?
end
end

View File

@@ -0,0 +1,13 @@
# frozen_string_literal: true
module Spree
module ProductsHelper
def product_has_variant_unit_option_type?(product)
product.option_types.any? { |option_type| variant_unit_option_type? option_type }
end
def variant_unit_option_type?(option_type)
Spree::Product.all_variant_unit_option_types.include? option_type
end
end
end

View File

@@ -1,23 +0,0 @@
module Spree
ProductsHelper.class_eval do
# Return the price of the variant, overriding sprees price diff capability.
# This will allways return the variant price as if the show_variant_full_price is set.
def variant_price_diff(variant)
"(#{Spree::Money.new(variant.price)})"
end
def product_has_variant_unit_option_type?(product)
product.option_types.any? { |option_type| variant_unit_option_type? option_type }
end
def variant_unit_option_type?(option_type)
Spree::Product.all_variant_unit_option_types.include? option_type
end
def product_variant_unit_options
[[I18n.t(:weight), 'weight'],
[I18n.t(:volume), 'volume'],
[I18n.t(:items), 'items']]
end
end
end

View File

@@ -57,16 +57,28 @@ class SubscriptionConfirmJob
return true unless order.payment_required?
setup_payment!(order)
return false if order.errors.present?
return false if order.errors.any?
authorize_payment!(order)
return false if order.errors.any?
order.process_payments!
return false if order.errors.present?
return false if order.errors.any?
true
end
def setup_payment!(order)
OrderManagement::Subscriptions::PaymentSetup.new(order).call!
return if order.errors.any?
OrderManagement::Subscriptions::StripePaymentSetup.new(order).call!
end
def authorize_payment!(order)
return if order.subscription.payment_method.class != Spree::Gateway::StripeSCA
OrderManagement::Subscriptions::StripeScaPaymentAuthorize.new(order).call!
end
def send_confirmation_email(order)

View File

@@ -1,41 +1,58 @@
# frozen_string_literal: true
class ProducerMailer < Spree::BaseMailer
include I18nHelper
def order_cycle_report(producer, order_cycle)
@producer = producer
@coordinator = order_cycle.coordinator
@order_cycle = order_cycle
line_items = line_items_from(@order_cycle, @producer)
@grouped_line_items = line_items.group_by(&:product_and_full_name)
@receival_instructions = @order_cycle.receival_instructions_for @producer
@total = total_from_line_items(line_items)
@tax_total = tax_total_from_line_items(line_items)
I18n.with_locale valid_locale(@producer.owner) do
order_cycle_subject = I18n.t('producer_mailer.order_cycle.subject', producer: producer.name)
subject = "[#{Spree::Config.site_name}] #{order_cycle_subject}"
with_unscoped_products_and_variants do
load_data
return unless has_orders?(order_cycle, producer)
I18n.with_locale(owner_locale) do
return unless orders?(order_cycle, producer)
mail(
to: @producer.contact.email,
from: from_address,
subject: subject,
reply_to: @coordinator.contact.email,
cc: @coordinator.contact.email
)
mail(
to: @producer.contact.email,
from: from_address,
subject: subject,
reply_to: @coordinator.contact.email,
cc: @coordinator.contact.email
)
end
end
end
private
def has_orders?(order_cycle, producer)
def owner_locale
valid_locale(@producer.owner)
end
def load_data
@coordinator = @order_cycle.coordinator
line_items = line_items_from(@order_cycle, @producer)
@grouped_line_items = line_items.group_by(&:product_and_full_name)
@receival_instructions = @order_cycle.receival_instructions_for(@producer)
@total = total_from_line_items(line_items)
@tax_total = tax_total_from_line_items(line_items)
end
def subject
order_cycle_subject = I18n.t('producer_mailer.order_cycle.subject', producer: @producer.name)
"[#{Spree::Config.site_name}] #{order_cycle_subject}"
end
def orders?(order_cycle, producer)
line_items_from(order_cycle, producer).any?
end
def line_items_from(order_cycle, producer)
Spree::LineItem.
includes(variant: { option_values: :option_type }).
@line_items ||= Spree::LineItem.
includes(:option_values, variant: [:product, { option_values: :option_type }]).
from_order_cycle(order_cycle).
sorted_by_name_and_unit_value.
merge(Spree::Product.in_supplier(producer)).
@@ -49,4 +66,22 @@ class ProducerMailer < Spree::BaseMailer
def tax_total_from_line_items(line_items)
Spree::Money.new line_items.sum(&:included_tax)
end
# This hack makes ActiveRecord skip the default_scope (deleted_at IS NULL)
# when eager loading associations. Further details:
# https://github.com/rails/rails/issues/11036
def with_unscoped_products_and_variants
variant_default_scopes = Spree::Variant.default_scopes
product_default_scopes = Spree::Product.default_scopes
Spree::Variant.default_scopes = []
Spree::Product.default_scopes = []
return_value = yield
Spree::Variant.default_scopes = variant_default_scopes
Spree::Product.default_scopes = product_default_scopes
return_value
end
end

View File

@@ -2,6 +2,7 @@ Spree::OrderMailer.class_eval do
helper HtmlHelper
helper CheckoutHelper
helper SpreeCurrencyHelper
helper OrderHelper
include I18nHelper
def cancel_email(order_or_order_id, resend = false)

View File

@@ -1,6 +1,7 @@
class SubscriptionMailer < Spree::BaseMailer
helper CheckoutHelper
helper ShopMailHelper
helper OrderHelper
include I18nHelper
def confirmation_email(order)

View File

@@ -0,0 +1,21 @@
# frozen_string_literal: true
# API controllers inherit from ActionController::Metal to keep them slim and fast.
# This concern adds the minimum requirements needed to use Action Caching in the API.
module ApiActionCaching
extend ActiveSupport::Concern
included do
include ActionController::Caching
include ActionController::Caching::Actions
include AbstractController::Layouts
# These configs are not assigned to the controller automatically with ActionController::Metal
self.cache_store = Rails.configuration.cache_store
self.perform_caching = true
# ActionController::Caching asks for a controller's layout, but they're not used in the API
layout false
end
end

View File

@@ -40,9 +40,18 @@ module VariantStock
# Checks whether this variant is produced on demand.
def on_demand
# A variant that has not been saved yet, doesn't have a stock item
# A variant that has not been saved yet or has been soft-deleted doesn't have a stock item
# This provides a default value for variant.on_demand using Spree::StockLocation.backorderable_default
return Spree::StockLocation.first.backorderable_default if stock_items.empty?
return Spree::StockLocation.first.backorderable_default if new_record? || deleted?
# This can be removed unless we have seen this error in Bugsnag recently
if stock_item.nil?
Bugsnag.notify(
RuntimeError.new("Variant #stock_item called, but the stock_item does not exist!"),
object: as_json
)
return Spree::StockLocation.first.backorderable_default
end
stock_item.backorderable?
end

View File

@@ -57,8 +57,8 @@ class ContentConfiguration < Spree::Preferences::FileConfiguration
# Other
preference :footer_facebook_url, :string, default: "https://www.facebook.com/OpenFoodNet"
preference :footer_twitter_url, :string, default: "https://twitter.com/OpenFoodNet"
preference :footer_instagram_url, :string, default: ""
preference :footer_linkedin_url, :string, default: "http://www.linkedin.com/groups/Open-Food-Foundation-4743336"
preference :footer_instagram_url, :string, default: "https://www.instagram.com/openfoodnetworkuk/"
preference :footer_linkedin_url, :string, default: "https://www.linkedin.com/company/openfoodnetwork/"
preference :footer_googleplus_url, :string, default: ""
preference :footer_pinterest_url, :string, default: ""
preference :footer_email, :string, default: "hello@openfoodnetwork.org"

View File

@@ -1,5 +1,5 @@
class DistributorShippingMethod < ActiveRecord::Base
self.table_name = "distributors_shipping_methods"
belongs_to :shipping_method, class_name: Spree::ShippingMethod
belongs_to :shipping_method, class_name: Spree::ShippingMethod, touch: true
belongs_to :distributor, class_name: Enterprise, touch: true
end

View File

@@ -16,7 +16,8 @@ class OrderCycle < ActiveRecord::Base
has_many :suppliers, source: :sender, through: :cached_incoming_exchanges, uniq: true
has_many :distributors, source: :receiver, through: :cached_outgoing_exchanges, uniq: true
has_and_belongs_to_many :schedules, join_table: 'order_cycle_schedules'
has_many :schedules, through: :order_cycle_schedules
has_many :order_cycle_schedules
has_paper_trail meta: { custom_data: proc { |order_cycle| order_cycle.schedule_ids.to_s } }
attr_accessor :incoming_exchanges, :outgoing_exchanges
@@ -240,7 +241,8 @@ class OrderCycle < ActiveRecord::Base
end
def exchanges_supplying(order)
exchanges.supplying_to(order.distributor).with_any_variant(order.variants.map(&:id))
variant_ids_relation = Spree::LineItem.in_orders(order).select(:variant_id)
exchanges.supplying_to(order.distributor).with_any_variant(variant_ids_relation)
end
def coordinated_by?(user)

View File

@@ -0,0 +1,6 @@
# frozen_string_literal: true
class OrderCycleSchedule < ActiveRecord::Base
belongs_to :schedule
belongs_to :order_cycle
end

View File

@@ -4,18 +4,6 @@ class ProducerProperty < ActiveRecord::Base
default_scope { order("#{table_name}.position") }
scope :ever_sold_by, ->(shop) {
joins(producer: { supplied_products: { variants: { exchanges: :order_cycle } } }).
merge(Exchange.outgoing).
merge(Exchange.to_enterprise(shop)).
select('DISTINCT producer_properties.*')
}
scope :currently_sold_by, ->(shop) {
ever_sold_by(shop).
merge(OrderCycle.active)
}
def property_name
property.name if property
end

View File

@@ -1,7 +1,8 @@
class Schedule < ActiveRecord::Base
has_and_belongs_to_many :order_cycles, join_table: 'order_cycle_schedules'
has_paper_trail meta: { custom_data: proc { |schedule| schedule.order_cycle_ids.to_s } }
has_many :order_cycles, through: :order_cycle_schedules
has_many :order_cycle_schedules, dependent: :destroy
has_many :coordinators, uniq: true, through: :order_cycles
attr_accessible :name, :order_cycle_ids

View File

@@ -14,7 +14,6 @@ Spree::AppConfiguration.class_eval do
preference :privacy_policy_url, :string, default: nil
preference :cookies_consent_banner_toggle, :boolean, default: false
preference :cookies_policy_matomo_section, :boolean, default: false
preference :cookies_policy_ga_section, :boolean, default: false
# Tax Preferences
preference :products_require_tax_category, :boolean, default: false

View File

@@ -17,9 +17,9 @@ module Spree
order_amount = line_items_for(object).map { |x| x.price * x.quantity }.sum
if order_amount < min
cost = preferred_normal_amount.to_i
cost = preferred_normal_amount.to_f
elsif order_amount >= min
cost = preferred_discount_amount.to_i
cost = preferred_discount_amount.to_f
end
cost

View File

@@ -1,5 +1,6 @@
Spree::Classification.class_eval do
belongs_to :product, class_name: "Spree::Product", touch: true
belongs_to :taxon, class_name: "Spree::Taxon", touch: true
before_destroy :dont_destroy_if_primary_taxon

View File

@@ -1,6 +0,0 @@
Spree::Money.class_eval do
# return the currency symbol (on it's own) for the current default currency
def self.currency_symbol
Money.new(0, Spree::Config[:currency]).symbol
end
end

View File

@@ -210,7 +210,7 @@ Spree::Order.class_eval do
end
def cap_quantity_at_stock!
line_items.each(&:cap_quantity_at_stock!)
line_items.includes(variant: :stock_items).all.each(&:cap_quantity_at_stock!)
end
def set_distributor!(distributor)
@@ -237,7 +237,10 @@ Spree::Order.class_eval do
with_lock do
EnterpriseFee.clear_all_adjustments_on_order self
line_items.each do |line_item|
loaded_line_items =
line_items.includes(variant: :product, order: [:distributor, :order_cycle]).all
loaded_line_items.each do |line_item|
if provided_by_order_cycle? line_item
OpenFoodNetwork::EnterpriseFeeCalculator.new.create_line_item_adjustments_for line_item
end
@@ -263,7 +266,11 @@ Spree::Order.class_eval do
end
def line_item_variants
line_items.map(&:variant)
if line_items.loaded?
line_items.map(&:variant)
else
line_items.includes(:variant).map(&:variant)
end
end
# Show already bought line items of this order cycle

View File

@@ -12,7 +12,7 @@ Spree::Product.class_eval do
has_many :option_types, through: :product_option_types, dependent: :destroy
belongs_to :supplier, class_name: 'Enterprise', touch: true
belongs_to :primary_taxon, class_name: 'Spree::Taxon'
belongs_to :primary_taxon, class_name: 'Spree::Taxon', touch: true
delegate_belongs_to :master, :unit_value, :unit_description
delegate :images_attributes=, :display_as=, to: :master

View File

@@ -2,11 +2,16 @@ module Spree
class Property < ActiveRecord::Base
has_many :product_properties, dependent: :destroy
has_many :products, through: :product_properties
has_many :producer_properties
attr_accessible :name, :presentation
validates :name, :presentation, presence: true
scope :sorted, -> { order(:name) }
def property
self
end
end
end

View File

@@ -1,27 +0,0 @@
module Spree
Property.class_eval do
has_many :producer_properties
scope :applied_by, ->(enterprise) {
select('DISTINCT spree_properties.*').
joins(:product_properties).
where('spree_product_properties.product_id IN (?)', enterprise.supplied_product_ids)
}
scope :ever_sold_by, ->(shop) {
joins(products: { variants: { exchanges: :order_cycle } }).
merge(Exchange.outgoing).
merge(Exchange.to_enterprise(shop)).
select('DISTINCT spree_properties.*')
}
scope :currently_sold_by, ->(shop) {
ever_sold_by(shop).
merge(OrderCycle.active)
}
def property
self
end
end
end

View File

@@ -11,6 +11,10 @@ module Spree
end
def total_on_hand
# Associated stock_items no longer exist if the variant has been soft-deleted. A variant
# may still be in an active cart after it's deleted, so this will mark it as out of stock.
return 0 if @variant.deleted?
stock_items.sum(&:count_on_hand)
end

View File

@@ -125,7 +125,12 @@ module Spree
end
def default_card
credit_cards.where(is_default: true).first
# Don't re-fetch associated cards from the DB if they're already eager-loaded
if credit_cards.loaded?
credit_cards.to_a.find(&:is_default)
else
credit_cards.where(is_default: true).first
end
end
# Checks whether the specified user is a superadmin, with full control of the

View File

@@ -16,7 +16,8 @@ Spree::Variant.class_eval do
has_many :variant_overrides
has_many :inventory_items
attr_accessible :unit_value, :unit_description, :images_attributes, :display_as, :display_name, :import_date
attr_accessible :unit_value, :unit_description, :images_attributes,
:display_as, :display_name, :import_date
accepts_nested_attributes_for :images
validates :unit_value, presence: true, if: ->(variant) {
@@ -53,13 +54,23 @@ Spree::Variant.class_eval do
}
scope :visible_for, lambda { |enterprise|
joins(:inventory_items).where('inventory_items.enterprise_id = (?) AND inventory_items.visible = (?)', enterprise, true)
joins(:inventory_items).
where(
'inventory_items.enterprise_id = (?) AND inventory_items.visible = (?)',
enterprise,
true
)
}
scope :not_hidden_for, lambda { |enterprise|
return where("1=0") if enterprise.blank?
joins("LEFT OUTER JOIN (SELECT * from inventory_items WHERE enterprise_id = #{sanitize enterprise.andand.id}) AS o_inventory_items ON o_inventory_items.variant_id = spree_variants.id")
joins("
LEFT OUTER JOIN (SELECT *
FROM inventory_items
WHERE enterprise_id = #{sanitize enterprise.andand.id})
AS o_inventory_items
ON o_inventory_items.variant_id = spree_variants.id")
.where("o_inventory_items.id IS NULL OR o_inventory_items.visible = (?)", true)
}
@@ -68,7 +79,8 @@ Spree::Variant.class_eval do
scope :stockable_by, lambda { |enterprise|
return where("1=0") if enterprise.blank?
joins(:product).where(spree_products: { id: Spree::Product.stockable_by(enterprise).pluck(:id) })
joins(:product).
where(spree_products: { id: Spree::Product.stockable_by(enterprise).pluck(:id) })
}
# Define sope as class method to allow chaining with other scopes filtering id.
@@ -85,7 +97,19 @@ Spree::Variant.class_eval do
]
end
# We override in_stock? to avoid depending on the non-overridable method Spree::Stock::Quantifier.can_supply?
def self.active(currency = nil)
# "where(id:" is necessary so that the returned relation has no includes
# The relation without includes will not be readonly and allow updates on it
where("spree_variants.id in (?)", joins(:prices).
where(deleted_at: nil).
where('spree_prices.currency' =>
currency || Spree::Config[:currency]).
where('spree_prices.amount IS NOT NULL').
select("spree_variants.id"))
end
# We override in_stock? to avoid depending
# on the non-overridable method Spree::Stock::Quantifier.can_supply?
# VariantStock implements can_supply? itself which depends on overridable methods
def in_stock?(quantity = 1)
can_supply?(quantity)

View File

@@ -1,4 +1,12 @@
class Api::Admin::BasicEnterpriseSerializer < ActiveModel::Serializer
attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :category,
:payment_method_ids, :shipping_method_ids, :producer_profile_only, :permalink
def payment_method_ids
object.payment_methods.map(&:id)
end
def shipping_method_ids
object.shipping_methods.map(&:id)
end
end

View File

@@ -6,7 +6,7 @@ class Api::Admin::CustomerSerializer < ActiveModel::Serializer
has_one :bill_address, serializer: Api::AddressSerializer
def tag_list
object.tag_list.join(",")
customer_tag_list.join(",")
end
def name
@@ -14,7 +14,7 @@ class Api::Admin::CustomerSerializer < ActiveModel::Serializer
end
def tags
object.tag_list.map do |tag|
customer_tag_list.map do |tag|
tag_rule_map = options[:tag_rule_mapping].andand[tag]
tag_rule_map || { text: tag, rules: nil }
end
@@ -25,4 +25,12 @@ class Api::Admin::CustomerSerializer < ActiveModel::Serializer
object.user.default_card.present?
end
private
def customer_tag_list
return object.tag_list unless options[:customer_tags]
options[:customer_tags].andand[object.id] || []
end
end

View File

@@ -3,7 +3,7 @@ class Api::Admin::OrderSerializer < ActiveModel::Serializer
:edit_path, :state, :payment_state, :shipment_state,
:payments_path, :ready_to_ship, :ready_to_capture, :created_at,
:distributor_name, :special_instructions,
:item_total, :adjustment_total, :payment_total, :total
:item_total, :adjustment_total, :payment_total, :total, :display_outstanding_balance
has_one :distributor, serializer: Api::Admin::IdSerializer
has_one :order_cycle, serializer: Api::Admin::IdSerializer
@@ -16,6 +16,12 @@ class Api::Admin::OrderSerializer < ActiveModel::Serializer
object.distributor.andand.name
end
def display_outstanding_balance
return "" if object.outstanding_balance.zero?
object.display_outstanding_balance.to_s
end
def edit_path
return '' unless object.id

View File

@@ -62,10 +62,14 @@ module Api
end
def supplied_taxons
return [] unless enterprise.is_primary_producer
ids_to_objs data.supplied_taxons[enterprise.id]
end
def supplied_properties
return [] unless enterprise.is_primary_producer
(product_properties + producer_properties).uniq do |property_object|
property_object.property.presentation
end
@@ -113,7 +117,7 @@ module Api
end
def active
data.active_distributor_ids.andand.include? enterprise.id
@active ||= data.active_distributor_ids.andand.include? enterprise.id
end
# Map svg icons.

View File

@@ -18,7 +18,8 @@ module Api
end
def active
enterprise.ready_for_checkout? && OrderCycle.active.with_distributor(enterprise).exists?
@active ||=
enterprise.ready_for_checkout? && OrderCycle.active.with_distributor(enterprise).exists?
end
def pickup
@@ -73,12 +74,16 @@ module Api
end
def supplied_taxons
return [] unless enterprise.is_primary_producer
ActiveModel::ArraySerializer.new(
enterprise.supplied_taxons, each_serializer: Api::TaxonSerializer
)
end
def supplied_properties
return [] unless enterprise.is_primary_producer
(product_properties + producer_properties).uniq do |property_object|
property_object.property.presentation
end
@@ -118,7 +123,7 @@ module Api
private
def product_properties
enterprise.supplied_products.flat_map(&:properties)
enterprise.supplied_products.includes(:properties).flat_map(&:properties)
end
def producer_properties

View File

@@ -0,0 +1,62 @@
# frozen_string_literal: true
class CacheService
HOME_STATS_EXPIRY = 1.day.freeze
FILTERS_EXPIRY = 30.seconds.freeze
SHOPS_EXPIRY = 15.seconds.freeze
def self.cache(cache_key, options = {})
Rails.cache.fetch cache_key.to_s, options do
yield
end
end
# Yields a cached query, expired by the most recently updated record for a given class.
# E.g: if *any* Spree::Taxon record is updated, all keys based on Spree::Taxon will auto-expire.
def self.cached_data_by_class(cache_key, cached_class)
Rails.cache.fetch "#{cache_key}-#{cached_class}-#{latest_timestamp_by_class(cached_class)}" do
yield
end
end
# 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
end
def self.home_stats(statistic)
Rails.cache.fetch("home_stats_count_#{statistic}",
expires_in: HOME_STATS_EXPIRY,
race_condition_ttl: 10) do
yield
end
end
module FragmentCaching
# Rails' caching in views is called "Fragment Caching" and uses some slightly different logic.
# Note: keys supplied here are actually prepended with "views/" under the hood.
def self.ams_all_taxons_key
"inject-all-taxons-#{CacheService.latest_timestamp_by_class(Spree::Taxon)}"
end
def self.ams_all_properties_key
"inject-all-properties-#{CacheService.latest_timestamp_by_class(Spree::Property)}"
end
def self.ams_shops
[
"shops/index/inject_enterprises",
{ expires_in: SHOPS_EXPIRY }
]
end
def self.ams_shop(enterprise)
[
"enterprises/shop/inject_enterprise_shopfront-#{enterprise.id}",
{ expires_in: SHOPS_EXPIRY }
]
end
end
end

View File

@@ -15,28 +15,53 @@ class CartService
@distributor, @order_cycle = distributor_and_order_cycle
@order.with_lock do
variants = read_variants from_hash
attempt_cart_add_variants variants
overwrite_variants variants unless !overwrite
variants_data = read_variants from_hash
attempt_cart_add_variants variants_data
overwrite_variants variants_data if overwrite
end
valid?
end
def attempt_cart_add_variants(variants)
variants.each do |v|
if varies_from_cart(v)
attempt_cart_add(v[:variant_id], v[:quantity], v[:max_quantity])
private
def attempt_cart_add_variants(variants_data)
loaded_variants = indexed_variants(variants_data)
variants_data.each do |variant_data|
loaded_variant = loaded_variants[variant_data[:variant_id].to_i]
if loaded_variant.deleted?
remove_deleted_variant(loaded_variant)
next
end
next unless varies_from_cart(variant_data, loaded_variant)
attempt_cart_add(loaded_variant, variant_data[:quantity], variant_data[:max_quantity])
end
end
def attempt_cart_add(variant_id, quantity, max_quantity = nil)
def indexed_variants(variants_data)
@indexed_variants ||= begin
variant_ids_in_data = variants_data.map{ |v| v[:variant_id] }
Spree::Variant.with_deleted.where(id: variant_ids_in_data).
includes(:default_price, :stock_items, :product).
index_by(&:id)
end
end
def remove_deleted_variant(variant)
line_item_for_variant(variant).andand.destroy
end
def attempt_cart_add(variant, quantity, max_quantity = nil)
quantity = quantity.to_i
max_quantity = max_quantity.to_i if max_quantity
variant = Spree::Variant.find(variant_id)
OpenFoodNetwork::ScopeVariantToHub.new(@distributor).scope(variant)
return unless quantity > 0
return unless quantity > 0 && valid_variant?(variant)
scoper.scope(variant)
return unless valid_variant?(variant)
cart_add(variant, quantity, max_quantity)
end
@@ -66,25 +91,12 @@ class CartService
end
end
private
def scoper
@scoper ||= OpenFoodNetwork::ScopeVariantToHub.new(@distributor)
end
def read_variants(data)
@variants_h = read_products_hash(data) +
read_variants_hash(data)
end
def read_products_hash(data)
# This is most probably dead code, this bugsnag notification will confirm it
notify_bugsnag(data) if data[:products].present?
(data[:products] || []).map do |_product_id, variant_id|
{ variant_id: variant_id, quantity: data[:quantity] }
end
end
def notify_bugsnag(data)
Bugsnag.notify(RuntimeError.new("CartService.populate called with products hash"),
data: data.as_json)
@variants_h = read_variants_hash(data)
end
def read_variants_hash(data)
@@ -110,8 +122,9 @@ class CartService
[@order.distributor, @order.order_cycle]
end
def varies_from_cart(variant_data)
li = line_item_for_variant_id variant_data[:variant_id]
# Returns true if the saved cart differs from what's in the posted data, otherwise false
def varies_from_cart(variant_data, loaded_variant)
li = line_item_for_variant loaded_variant
li_added = li.nil? && (variant_data[:quantity].to_i > 0 || variant_data[:max_quantity].to_i > 0)
li_quantity_changed = li.present? && li.quantity.to_i != variant_data[:quantity].to_i
@@ -143,8 +156,8 @@ class CartService
false
end
def line_item_for_variant_id(variant_id)
order.find_line_item_by_variant Spree::Variant.find(variant_id)
def line_item_for_variant(variant)
order.find_line_item_by_variant variant
end
def variant_ids_in_cart

View File

@@ -12,11 +12,8 @@ module Checkout
def path
return unless stripe_payment_method?
payment = @order.pending_payments.last
return unless payment&.checkout?
payment.authorize!
raise unless payment.pending?
payment = OrderManagement::Subscriptions::StripeScaPaymentAuthorize.new(@order).call!
raise if @order.errors.any?
field_with_url(payment) if url?(field_with_url(payment))
end

View File

@@ -1,14 +1,28 @@
# frozen_string_literal: true
module OrderPaymentFinder
def self.last_payment_method(order)
# `max_by` avoids additional database queries when payments are loaded
# already. There is usually only one payment and this shouldn't cause
# any overhead compared to `order(:created_at).last`. Using `last`
# without order is not deterministic.
#
# We are not using `updated_at` because all payments are touched when the
# order is updated and then all payments have the same `updated_at` value.
order.payments.max_by(&:created_at)&.payment_method
class OrderPaymentFinder
def initialize(order)
@order = order
end
def last_payment
last(@order.payments)
end
def last_pending_payment
last(@order.pending_payments)
end
private
# `max_by` avoids additional database queries when payments are loaded
# already. There is usually only one payment and this shouldn't cause
# any overhead compared to `order(:created_at).last`. Using `last`
# without order is not deterministic.
#
# We are not using `updated_at` because all payments are touched when the
# order is updated and then all payments have the same `updated_at` value.
def last(payments)
payments.max_by(&:created_at)
end
end

View File

@@ -0,0 +1,36 @@
# frozen_string_literal: true
# Produces mappings of variant overrides by distributor id and variant id
# The primary use case for data structured in this way is for injection into
# the initializer of the OpenFoodNetwork::ScopeVariantToHub class
class VariantOverridesIndexed
def initialize(variant_ids, distributor_ids)
@variant_ids = variant_ids
@distributor_ids = distributor_ids
end
def indexed
scoped_variant_overrides.each_with_object(hash_of_hashes) do |variant_override, indexed|
indexed[variant_override.hub_id][variant_override.variant] = variant_override
end
end
private
attr_reader :variant_ids, :distributor_ids
def scoped_variant_overrides
VariantOverride
.joins(:variant)
.preload(:variant)
.where(
hub_id: distributor_ids,
variant_id: variant_ids,
)
end
def hash_of_hashes
Hash.new { |hash, key| hash[key] = {} }
end
end

View File

@@ -5,10 +5,10 @@ require 'open_food_network/scope_variant_to_hub'
class VariantsStockLevels
def call(order, requested_variant_ids)
variant_stock_levels = variant_stock_levels(order.line_items)
variant_stock_levels = variant_stock_levels(order.line_items.includes(variant: :stock_items))
order_variant_ids = variant_stock_levels.keys
missing_variants = Spree::Variant.includes(:stock_items).
missing_variants = Spree::Variant.with_deleted.includes(:stock_items).
where(id: (requested_variant_ids - order_variant_ids))
missing_variants.each do |missing_variant|

View File

@@ -6,6 +6,7 @@
%td
%ul
%li{"ng-repeat" => "permission in enterprise_relationship.permissions"}
to {{ EnterpriseRelationships.permission_presentation(permission.name) }}
= t 'admin_enterprise_relationships_to'
{{ EnterpriseRelationships.permission_presentation(permission.name) }}
%td.actions
%a.delete-enterprise-relationship.icon-trash.no-text{'ng-click' => 'delete(enterprise_relationship)'}

View File

@@ -13,7 +13,8 @@
%div{"ng-repeat" => "permission in EnterpriseRelationships.all_permissions"}
%label
%input{type: "checkbox", "ng-model" => "permissions[permission]"}
to {{ EnterpriseRelationships.permission_presentation(permission) }}
= t 'admin_enterprise_relationships_to'
{{ EnterpriseRelationships.permission_presentation(permission) }}
%td.actions
%input{type: "button", value: t(:admin_enterprise_relationships_button_create), "ng-click" => "create()"}
.errors {{ EnterpriseRelationships.create_errors }}

View File

@@ -31,5 +31,4 @@
//= f.submit "Purchase", class: "button", "ofn-focus" => "accordion['payment']"
%a.button.secondary{href: main_app.cart_url}
%i.ofn-i_008-caret-left
= t :checkout_back_to_cart

View File

@@ -0,0 +1,24 @@
%div{"ng-controller" => "OrderCycleChangeCtrl", "ng-cloak" => true}
%closing
%div{"ng-if" => "OrderCycle.selected()"}
= t :enterprises_next_closing
%strong {{ OrderCycle.orders_close_at() | date_in_words }}
%div{"ng-if" => "!OrderCycle.selected()"}
= t :enterprises_choose
.order-cycle-select
.select-label
%span= t :enterprises_ready_for
- if oc_select_options.count == 1
%p
= oc_select_options.first[:time]
- else
%select.select2.avenir#order_cycle_id{"ng-model" => "order_cycle.order_cycle_id",
"ofn-change-order-cycle" => true,
"disabled" => require_customer?,
"ng-options" => "oc.id as oc.time for oc in #{oc_select_options.to_json}"}
- if oc_select_options.count > 1
%option{value: "", disabled: "", selected: ""}= t :shopping_oc_select

View File

@@ -6,7 +6,8 @@
= current_distributor.logo.url
- content_for :injection_data do
= inject_enterprise_shopfront(@enterprise)
- cache(*CacheService::FragmentCaching.ams_shop(@enterprise)) do
= inject_enterprise_shopfront(@enterprise)
%shop.darkswarm
- if @shopfront_layout == 'embedded'
@@ -17,26 +18,7 @@
%a.close{ ng: { click: "alert.close()" } } &times;
- content_for :order_cycle_form do
%div{"ng-controller" => "OrderCycleChangeCtrl", "ng-cloak" => true}
%closing
%div{"ng-if" => "OrderCycle.selected()"}
= t :enterprises_next_closing
%strong {{ OrderCycle.orders_close_at() | date_in_words }}
%div{"ng-if" => "!OrderCycle.selected()"}
= t :enterprises_choose
.order-cycle-select
.select-label
%span= t :enterprises_ready_for
%select.select2.avenir#order_cycle_id{"ng-model" => "order_cycle.order_cycle_id",
"ofn-change-order-cycle" => true,
"disabled" => require_customer?,
"ng-options" => "oc.id as oc.time for oc in #{oc_select_options.to_json}"}
- if oc_select_options.count > 1
%option{value: "", disabled: "", selected: ""}= t :shopping_oc_select
= render partial: "change_order_cycle"
- content_for :ordercycle_sidebar do
.show-for-large-up.large-4.columns

View File

@@ -48,12 +48,13 @@
= inject_current_hub
= inject_current_user
= inject_rails_flash
= inject_taxons
= inject_properties
- cache CacheService::FragmentCaching.ams_all_taxons_key do
= inject_taxons
- cache CacheService::FragmentCaching.ams_all_properties_key do
= inject_properties
= inject_current_order
= inject_currency_config
= yield :injection_data
= render "layouts/bugherd_script"
= render "layouts/matomo_tag"
= render 'spree/shared/google_analytics'

View File

@@ -1,11 +0,0 @@
%h2
%i.ofn-i_040-hub>
= t :modal_hubs
%h5
= t :modal_hubs_abstract
%p
= t :modal_hubs_content1
%p
= t :modal_hubs_content2
%a.close-reveal-modal{"ng-click" => "$close()"}
%i.ofn-i_009-close

View File

@@ -1,9 +0,0 @@
%h2
%i.ofn-i_035-groups
= t :modal_groups
%p
= t :modal_groups
%p
= t :modal_groups
%a.close-reveal-modal{"ng-click" => "$close()"}
%i.ofn-i_009-close

View File

@@ -1,17 +0,0 @@
%h2
= t :modal_how
%h5
= t :modal_how_shop
%p
= t :modal_how_shop_explained
%h5
= t :modal_how_pickup
%p
= t :modal_how_pickup_explained
%h5
= t :modal_how
%p
= t :modal_how
%a.button.neutral-btn.dark{:href => "http://www.openfoodnetwork.org" , :target => "_blank" } Open Food Network
%a.close-reveal-modal{"ng-click" => "$close()"}
%i.ofn-i_009-close

View File

@@ -1,7 +0,0 @@
%h2
%i.ofn-i_036-producers
= t :modal_producers
%p
= t :modal_producers_explained
%a.close-reveal-modal{"ng-click" => "$close()"}
%i.ofn-i_009-close

View File

@@ -18,7 +18,7 @@
%a.soc-btn.li{href: ContentConfig.footer_linkedin_url}
LinkedIn
-if ContentConfig.footer_instagram_url.present?
%a.soc-btn.tw{href: ContentConfig.footer_instagram_url}
%a.soc-btn.ig{href: ContentConfig.footer_instagram_url}
Instagram
%table.column{:align => "left"}
%tr

View File

@@ -1,21 +0,0 @@
- if require_customer?
.row.footer-pad
.small-12.columns
.shopfront_hidden_message
= t '.require_customer_login'
- if spree_current_user.nil?
= t '.require_login_html',
{login: ('<a auth="login">' + t('.login') + '</a>').html_safe,
signup: ('<a auth="signup">' + t('.signup') + '</a>').html_safe,
contact: link_to(t('.contact'), '#contact'),
enterprise: current_distributor.name}
- else
= t '.require_customer_html',
{contact: link_to(t('.contact'), '#contact'),
enterprise: current_distributor.name}
- elsif current_distributor.preferred_shopfront_message.present?
.row
.small-12.columns
.shopfront-message
= current_distributor.preferred_shopfront_message.html_safe

View File

@@ -0,0 +1,21 @@
.row.closed-shop-header
.small-12.columns
.content{ "darker-background" => true }
%h4
.warning-sign
.rectangle
%strong !
.message
= t :shopping_oc_closed
%p
= render partial: "shopping_shared/next_order_cycle"
= render partial: "shopping_shared/last_order_cycle"
.row
.small-12.columns
.content
.shopfront_closed_message
- if shopfront_closed_message?
= current_distributor.preferred_shopfront_closed_message.html_safe
- else
= t :shopping_oc_closed_description

View File

@@ -0,0 +1,19 @@
.content{ "darker-background" => true }
.row.footer-pad
.small-12.columns
%strong
= t '.require_customer_login'
%p
- if spree_current_user.nil?
%p
= t '.require_login_html',
{login: ('<a auth="login">' + t('.login') + '</a>').html_safe,
signup: ('<a auth="signup">' + t('.signup') + '</a>').html_safe}
%p
= t '.require_login_2_html',
{contact: link_to(t('.contact'), '#contact'),
enterprise: current_distributor.name}
- else
= t '.require_customer_html',
{contact: link_to(t('.contact'), '#contact'),
enterprise: current_distributor.name}

View File

@@ -0,0 +1,5 @@
.content
.row
.small-12.columns
.open-shop-message
= current_distributor.preferred_shopfront_message.html_safe

View File

@@ -0,0 +1,3 @@
.content.footer-pad{ "darker-background" => true, "ng-controller" => "ProductsCtrl", "ng-show" => "order_cycle.order_cycle_id == null" }
.select-oc-message
= t '.select_oc_html'

View File

@@ -1,4 +1,2 @@
- if most_recently_closed = OrderCycle.most_recently_closed_for(@distributor)
(
= t :shopping_oc_last_closed, distance_of_time: distance_of_time_in_words_to_now(most_recently_closed.orders_close_at)
)

View File

@@ -1,4 +1,2 @@
- if next_oc = OrderCycle.first_opening_for(@distributor)
(
= t :shopping_oc_next_open, distance_of_time: distance_of_time_in_words_to_now(next_oc.orders_open_at)
)

View File

@@ -1,7 +1,7 @@
- content_for :injection_data do
= inject_current_order_cycle
- unless no_open_order_cycles?
- unless no_open_order_cycles? || require_customer?
%ordercycle{"ng-controller" => "OrderCycleCtrl", "ng-cloak" => true,
"ng-class" => "{'requires-selection': !OrderCycle.selected()}"}
%form.custom

View File

@@ -2,5 +2,12 @@
.order-cycle-bar.hide-for-large-up
= render partial: "shopping_shared/order_cycles"
.content
= render partial: 'shop/messages'
- if require_customer?
= render partial: "shop/messages/customer_required"
- else
- if no_open_order_cycles?
= render partial: "shop/messages/closed_shop"
- else
= render partial: "shop/messages/open_shop"

View File

@@ -2,23 +2,11 @@
.order-cycle-bar.hide-for-large-up
= render partial: "shopping_shared/order_cycles"
.row
.small-12.columns
- if no_open_order_cycles?
.content
%h4
%i.ofn-i_012-warning
= t :shopping_oc_closed
%small
%em
= render partial: "shopping_shared/next_order_cycle"
= render partial: "shopping_shared/last_order_cycle"
%p
= t :shopping_oc_closed_description
- if no_open_order_cycles?
= render partial: "shop/messages/closed_shop"
- if shopfront_closed_message?
.shopfront_closed_message
= current_distributor.preferred_shopfront_closed_message.html_safe
- unless require_customer?
- else
.row
.small-12.columns
= render partial: "shop/messages/select_oc"
= render partial: "shop/products/form"

View File

@@ -2,7 +2,8 @@
= t :shops_title
- content_for :injection_data do
= inject_enterprises(@enterprises)
- cache(*CacheService::FragmentCaching.ams_shops) do
= inject_enterprises(@enterprises)
#panes
#shops.pane

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