-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP #1037 Add Quantity to Customer and Add Query or Create Variant … #1055
base: develop
Are you sure you want to change the base?
WIP #1037 Add Quantity to Customer and Add Query or Create Variant … #1055
Conversation
c9025c9
to
66062a8
Compare
66062a8
to
d225183
Compare
6d7b1dc
to
e791bba
Compare
e791bba
to
4017c3f
Compare
2a83fdb
to
2db9e20
Compare
0a60d0e
to
ca377d5
Compare
4d16186
to
00231bc
Compare
@Regene27 It seems there's a misunderstanding regarding the use of before_action, load_, and lazy loading (memoization) techniques. Please come to the Bookmebus office so we can clarify and resolve the issues in this PR. |
00231bc
to
2d6222b
Compare
…in Subscription
2d6222b
to
ce0dd33
Compare
if request.xhr? | ||
@variant = @product.variants.build | ||
|
||
render :show, layout: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
render layout: false instead and create a new.html.erb in the view.
|
||
render :show, layout: false | ||
else | ||
redirect_to new_billing_product_variant_url(@product) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will redirect to itself and then it will end up with a loop redirect
var productSku = $(productSelector).val(); | ||
|
||
$.ajax({ | ||
url: '/en/billing/products/' + productSku + '/variants/new', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass the URL from the Rails. Don't construct the URL in the js
RSpec.describe SpreeCmCommissioner::SkuGenerator do | ||
let(:product) { create(:product, name: "Waste Collection") } | ||
let(:option_types) { [create(:option_type, name: "Month"), create(:option_type, name: "Due Date"), create(:option_type, name: "Payment Method")] } | ||
let(:option_values) { [create(:option_value, name: "1", option_type: option_types[0]), create(:option_value, name: "1", option_type: option_types[1]), create(:option_value, name: "pre-paid", option_type: option_types[2])] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
align this properly
def generate_sku | ||
return if @variant_params.nil? || @variant_params.blank? | ||
|
||
option_values = @variant_params[:option_value_ids].map { |id| Spree::OptionValue.find(id) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Spree::OptionValue.find(@variant_params[:option_value_ids) instead.
option_values = @variant_params[:option_value_ids].map { |id| Spree::OptionValue.find(id) } | ||
sku_parts = [product.name] | ||
|
||
option_values.each do |option_value| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the map method instead.
attr_reader :variant | ||
|
||
def initialize(variant_params, current_vendor) | ||
@product = Spree::Product.find_by(id: variant_params[:product_id]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the find method instead and create a method called product with
@product ||= Spree::Product.find(variant_params[:product_id])
@current_vendor = current_vendor | ||
end | ||
|
||
def find_or_create_variant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename find_or_create_variant to variant instead and merge the implementation of the find_variant_by_sku and create_variant. No need to have find_variant_by_sku and create_variant methods.
|
||
def variant_sku | ||
sku_generator = SpreeCmCommissioner::SkuGenerator.new(@product, @variant_params) | ||
sku_generator.generate_sku |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memoize this method.
@@ -0,0 +1,37 @@ | |||
module SpreeCmCommissioner | |||
class VariantCreator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apply the same concept here.
end | ||
|
||
def create_variant | ||
@variant = @product.variants.build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inconsistent code.
simplescreenrecorder-2024-01-29_17.15.26.mp4