Permalink
Browse files

Merge branch 'master' into feature/stripe-ruby

  • Loading branch information...
2 parents d5af9cb + 34de99e commit d53452572263990fa825ade520335983d933ed59 @Jellyfishboy committed Oct 21, 2016
@@ -1,5 +1,4 @@
//= require jquery
-//= require jquery.turbolinks
//= require jquery_ujs
//= require admin/soca
//= require jquery.scrollTo/jquery.scrollTo.min
@@ -10,4 +9,3 @@
//= require trado.admin
//= require trado.misc
//= require trado.ready
-//= require turbolinks
@@ -39,10 +39,11 @@ def update
unless @delivery_service_price.orders.empty?
Store.inactivate!(@delivery_service_price)
@old_delivery_service_price = @delivery_service_price
- @delivery_service_price = @old_delivery_service_price.delivery_service.prices.build(params[:delivery_service_price])
+ @delivery_service_price = @old_delivery_service_price.delivery_service.prices.new
end
+ @delivery_service_price.attributes = params[:delivery_service_price]
- if @delivery_service_price.update(params[:delivery_service_price])
+ if @delivery_service_price.save
flash_message :success, 'Delivery service price was successfully updated.'
redirect_to admin_delivery_service_delivery_service_prices_url
else
@@ -36,10 +36,11 @@ def update
unless @delivery_service.orders.empty?
Store.inactivate!(@delivery_service)
@old_delivery_service = @delivery_service
- @delivery_service = DeliveryService.new(params[:delivery_service])
+ @delivery_service = DeliveryService.new
end
+ @delivery_service.attributes = params[:delivery_service]
- if @delivery_service.update(params[:delivery_service])
+ if @delivery_service.save
if @old_delivery_service
@old_delivery_service.active_prices.each do |price|
new_price = price.dup
@@ -40,11 +40,17 @@ def update
unless @sku.orders.empty?
Store.inactivate!(@sku)
@old_sku = @sku
- @sku = Sku.new(params[:sku])
- @sku.product_id = @old_sku.product.id
+ @sku = Sku.new
+ params[:sku].delete(:variants_attributes)
+ # change sku form to still pass the code and stock but cant edit if already have orders
+ @sku.stock = @old_sku.stock
+ @sku.code = @old_sku.code
+ ###
end
+ @sku.attributes = params[:sku]
+ @sku.product_id = @old_sku.product.id if @old_sku
- if @sku.update(params[:sku])
+ if @sku.save
if @old_sku
@old_sku.stock_adjustments.each do |sa|
new_stock_adjustment = sa.dup
@@ -56,7 +62,7 @@ def update
new_variant.sku_id = @sku.id
new_variant.save!
end
- CartItem.where('sku_id = ?', @old_sku.id).destroy_all
+ CartItem.where(sku_id: @old_sku.id).destroy_all
end
render json: { row: render_to_string(partial: 'admin/products/skus/single', locals: { sku: @sku }), sku_id: @sku.id }, status: 200
else
@@ -4,10 +4,10 @@
<a href="#" data-product-id="<%= @product.id %>" data-attachment-id="<%= attachment.id %>" class="show-attachment label label-blue">
<i class="icon-search"></i>
</a>
- <%= link_to edit_admin_product_attachment_path(attachment.attachable, attachment), remote: true, :class => "edit-attachment label label-green" do %>
+ <%= link_to edit_admin_product_attachment_path(product_id: attachment.attachable.id, id: attachment.id), remote: true, :class => "edit-attachment label label-green" do %>
<i class="icon-pencil"></i>
<% end %>
- <a href="#" data-url="<%= admin_product_attachment_path(attachment.attachable, attachment) %>" class="<%= Store.class_name_id(attachment) %>-delete label label-red">
+ <a href="#" data-url="<%= admin_product_attachment_path(product_id: attachment.attachable.id, id: attachment.id) %>" class="<%= Store.class_name_id(attachment) %>-delete label label-red">
<i class="icon-remove"></i>
</a>
</div>
@@ -6,10 +6,10 @@
<td><%= Store::Price.new(price: sku.cost_value).single %></td>
<td><%= Store::Price.new(price: sku.price).single %></td>
<td class="table-actions">
- <%= link_to edit_admin_product_sku_path(sku.product, sku), remote: true, :class => 'edit-sku-button' do %>
+ <%= link_to edit_admin_product_sku_path(product_id: sku.product.id, id: sku.id), remote: true, :class => 'edit-sku-button' do %>
<i class="icon-pencil"></i>
<% end %>
- <%= link_to admin_product_sku_path(sku.product, sku), remote: true, :class => "#{Store.class_name_id(sku)}-delete" do %>
+ <%= link_to admin_product_sku_path(product_id: sku.product.id, id: sku.id), remote: true, :class => "#{Store.class_name_id(sku)}-delete" do %>
<i class="icon-remove"></i>
<% end %>
</td>
@@ -1,4 +1,8 @@
<div class="price">
- <%= range ? "<span class='range-prefix'>from</span> #{single_price}".html_safe : single_price %>
- <% unless gross.nil? %><span class="tax-suffix"><%= "#{gross} inc #{Store.settings.tax_name}" %></span><% end %>
+ <% if Store.settings.tax_breakdown %>
+ <%= range ? "<span class='range-prefix'>from</span> #{net_price}".html_safe : net_price %>
+ <span class="tax-suffix"><%= "#{gross_price} inc #{Store.settings.tax_name}" %></span>
+ <% else %>
+ <%= range ? "<span class='range-prefix'>from</span> #{gross_price}".html_safe : gross_price %>
+ <% end %>
</div>
@@ -1,4 +1,8 @@
<div class="price">
- <%= single_price %>
- <% unless gross.nil? %><span class="tax-suffix"><%= "#{gross} inc #{Store.settings.tax_name}" %></span><% end %>
+ <% if Store.settings.tax_breakdown %>
+ <%= net_price %>
+ <span class="tax-suffix"><%= "#{gross_price} inc #{Store.settings.tax_name}" %></span>
+ <% else %>
+ <%= gross_price %>
+ <% end %>
</div>
@@ -74,7 +74,7 @@
</div>
<div class="payment-choices">
<div>
- <%= paypal_form_tag(f) if Modulatron4000.paypal? %>
+ <%= paypal_checkout_fields(f) if Modulatron4000.paypal? %>
</div>
<%= stripe_checkout_fields(f) if Modulatron4000.stripe? %>
</div>
View
@@ -24,24 +24,8 @@ def initialize data
# @return [Decimal] price
def price
@price = @price.nil? ? 0 : @price
- price_ting = tax_type == 'gross' ? taxify(@price) : @price
- return price_ting
- end
-
- # If the store setting is set to show tax breakdown
- # Return a decimal value of the gross price
- #
- # @return [Decimal] price
- def gross_price
- Store.settings.tax_breakdown ? taxify(@price || 0) : nil
- end
-
- # If the record count for a product is more than one
- # Return true to display different HTML markup
- #
- # @return [boolean]
- def range_price
- count.nil? || count < 2 ? false : true
+ taxed_price = tax_type == 'gross' ? taxify(@price) : @price
+ return taxed_price
end
# Convert a price into an integer
@@ -56,14 +40,14 @@ def singularize
# @return [String] formatted price
def single
format(price)
- end
+ end
# Renders the DOM elements for a product with more than one SKU and thereby more than one price
# If product has only one SKU, just show price as standard, however ignoring the Inc VAT value when store tax breakdown is turned on
#
# @return [String] HTML elements
def range
- Renderer.render partial: 'shared/price/range', locals: { single_price: single, range: range_price, gross: format(gross_price) }, format: [:html]
+ Renderer.render partial: 'shared/price/range', locals: { net_price: net_price, range: range_price, gross_price: gross_price }, format: [:html]
end
# Render the markup when displaying the net and gross price if tax breakdown set to true
@@ -72,7 +56,7 @@ def range
#
# @return [String] HTML for both net and gross prices
def markup
- Renderer.render partial: 'shared/price/single', locals: { single_price: single, gross: format(gross_price) }, format: [:html]
+ Renderer.render partial: 'shared/price/single', locals: { net_price: net_price, gross_price: gross_price }, format: [:html]
end
private
@@ -93,5 +77,27 @@ def format price
def taxify price
(price * Store.tax_rate) + price
end
+
+ # If the record count for a product is more than one
+ # Return true to display different HTML markup
+ #
+ # @return [boolean]
+ def range_price
+ count.nil? || count < 2 ? false : true
+ end
+
+ # Returns net price value
+ #
+ # @return [Decimal] price
+ def net_price
+ format(@price)
+ end
+
+ # Returns gross price value
+ #
+ # @return [Decimal] price
+ def gross_price
+ format(taxify(@price))
+ end
end
end

0 comments on commit d534525

Please sign in to comment.