Class: SkuTranslationsController
Instance Method Summary
collapse
#accessible_company_ids_from_tenant_and_user, #application_mode_from_hostname, #current_company_id_from_accessible_company_ids, #current_tenant_from_user, #current_user_and_locale_from_token
Instance Method Details
#index ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/controllers/sku_translations_controller.rb', line 6
def index
offset = params[:offset].to_i || 0
limit = params[:limit].to_i || 10
partner = EdiPartner.find(params[:edi_partner_id]).partner
product_id = params[:product_id]
unless product_id
return render json: {
data: [],
metadata: {
total: 0,
limit: limit,
offset: offset
}
}
end
product = ProductMaster.find(product_id)
records = EdiSkuTranslation.table_data(
product_id: product.id,
offset: offset,
limit: limit,
partner: partner
)
total = product.skus.count
render json: {
data: records,
metadata: {
total: total,
limit: limit,
offset: offset
}
}
end
|
#update_from_table_edits ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/controllers/sku_translations_controller.rb', line 40
def update_from_table_edits
edi_partner = EdiPartner.find(params[:edi_partner_id])
partner = edi_partner.partner
update_from_table_edits_params[:rows_edits].each do |row_edits|
row_hash = row_edits[:rowHash]
edits = row_edits[:edits]
sku_translation = if row_hash[:sku_translation_id]
EdiSkuTranslation.find(row_hash[:sku_translation_id])
else
EdiSkuTranslation.new(
sku_id: row_hash[:sku_id],
customer_supplier_id: partner.id,
translation_type: partner.entity_type,
creation_date: Time.now,
created_by: current_user.email.first(20)
)
end
new_customer_supplier_item_no = edits[:customer_supplier_item_no] || row_hash[:customer_supplier_item_no].to_s
new_customer_supplier_description = edits[:customer_supplier_description] || row_hash[:customer_supplier_description].to_s
new_customer_supplier_item_color = edits[:customer_supplier_item_color] || row_hash[:customer_supplier_item_color].to_s
new_customer_supplier_item_size = edits[:customer_supplier_item_size] || row_hash[:customer_supplier_item_size].to_s
new_customer_supplier_item_style = edits[:customer_supplier_item_style] || row_hash[:customer_supplier_item_style].to_s
new_customer_supplier_item_dimension = edits[:customer_supplier_item_dimension] || row_hash[:customer_supplier_item_dimension].to_s
sku_translation.update!(
customer_supplier_item_no: new_customer_supplier_item_no,
customer_supplier_description: new_customer_supplier_description,
customer_supplier_item_color: new_customer_supplier_item_color,
customer_supplier_item_size: new_customer_supplier_item_size,
customer_supplier_item_style: new_customer_supplier_item_style,
customer_supplier_item_dimension: new_customer_supplier_item_dimension,
active:
new_customer_supplier_item_no.present? ||
new_customer_supplier_description.present? ||
new_customer_supplier_item_color.present? ||
new_customer_supplier_item_size.present? ||
new_customer_supplier_item_style.present? ||
new_customer_supplier_item_dimension.present?,
modification_date: Time.now,
modified_by: current_user.email.first(20)
)
end
end
|