Sha256: accf984e38e1cf1ee409d30cf784b25fd7ec0dad792f38eb45c0875439d14002
Contents?: true
Size: 1.1 KB
Versions: 16
Compression:
Stored size: 1.1 KB
Contents
module Workarea module Admin module BulkVariantSaving def save_variant_on_product(product, attributes: {}, variant: nil) variant ||= product.variants.build variant.sku = attributes[:sku] variant.update_details( attributes[:detail_1_name] => attributes[:detail_1_value], attributes[:detail_2_name] => attributes[:detail_2_value], attributes[:detail_3_name] => attributes[:detail_3_value] ) variant.save! if attributes[:price].present? || attributes[:tax_code].present? pricing = Pricing::Sku.find_or_create_by(id: variant.sku) pricing.tax_code = attributes[:tax_code] price = pricing.prices.first || pricing.prices.build price.regular = attributes[:price] pricing.save! end if attributes[:inventory].present? inventory = Inventory::Sku.find_or_initialize_by(id: variant.sku) inventory.available = attributes[:inventory] inventory.policy = 'standard' if inventory.new_record? inventory.save! end end end end end
Version data entries
16 entries across 16 versions & 1 rubygems