Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/classes/woo/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(company_id:, store_url:, consumer_key:, consumer_secret:)
consumer_key,
consumer_secret,
wp_api: true,
version: 'wc/v1',
version: 'wc/v2',
query_string_auth: true
)
end
Expand Down
9 changes: 9 additions & 0 deletions app/classes/woo/orders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ def fetch(orders_path:, customer_id: nil, order_status: 'processing')

# Fetch only order that are 'processing'
response = woo_get('orders', status: order_status)

logger.info "json: \n\n #{response.to_s}\n\n'"

return unless response

response.each do |order|
Expand All @@ -17,6 +20,12 @@ def fetch(orders_path:, customer_id: nil, order_status: 'processing')
logger.info "Order #{order['id']} status set to 'on-hold'"
next unless status

#changing the postnord_service_point_id to carrier_agent_id form metadata
carrier_agent_id = order['meta_data'].select {|meta| meta["key"] == '_woo_carrier_agent_id'}
unless carrier_agent_id.empty?
order["shipping_lines"][0]["postnord_service_point_id"] = carrier_agent_id[0]["value"]
end

# Check if order already is in Pupesoft
@pupe_draft = SalesOrder::Draft.find_by(laatija: 'WooCommerce', asiakkaan_tilausnumero: order['id'])
@pupe_order = SalesOrder::Order.find_by(laatija: 'WooCommerce', asiakkaan_tilausnumero: order['id'])
Expand Down
21 changes: 18 additions & 3 deletions app/classes/woo/products.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ def products
end

def product_hash(product)
#get the images of the product
images = []
product_images = product.attachments
#where(kayttotarkoitus: "Tuotekuva")
unless product_images.empty?
product_images.each do |image|
image_hash = {src: "https://kuvamakia.devlab.fi/view.php?id="+image.tunnus.to_s}.compact.to_h
images.append(image_hash)
end
end

defaults = {
name: product.nimitys,
slug: product.tuoteno,
Expand All @@ -60,6 +71,11 @@ def product_hash(product)
status: 'pending',
}

unless images.empty?
logger.info "Images #{images}"
defaults.merge!({ images: images})
end

from_keywords = Keyword::WooField.all.pluck(:selite, :selitetark).map do |selite, selitetark|
selite = selite.to_sym

Expand All @@ -85,9 +101,8 @@ def get_sku(sku)

def create_product(product)
response = woo_post('products', product_hash(product))

return 0 unless response && response['id']

logger.info "Response #{response.to_s}"
#return 0 unless response && response['id']
logger.info "Tuote #{product.tuoteno} #{product.nimitys} lisätty verkkokauppaan"

1
Expand Down