I'm getting some very strange results from Shopify API and I'm hoping someone can help me out.
I'm trying to create an order, with a discount. Its actually saving the order, with the discount information... however the amount is ALWAYS wrong
order_params = {
:browser_ip => webhook[:browser_ip],
:buyer_accepts_marketing => webhook[:buyer_accepts_marketing],
:currency => webhook[:currency],
:email => webhook[:email],
:financial_status => webhook[:financial_status],
:landing_site => webhook[:landing_site],
:note => webhook[:note],
:referring_site => webhook[:referring_site],
:line_items => line_items,
:tag => tags,
:transactions => transactions,
:discount_codes => webhook[:discount_codes],
:total_discounts => webhook[:total_discounts],
:shipping_address => webhook[:shipping_address],
:shipping_lines => webhook[:shipping_lines],
:customer_id => #options[:customer_id],
:billing_address => webhook[:billing_address]
}
#shopify_order = ShopifyAPI::Order.create(order_params)
As you can see its created from webhook data. This is giving me back...(truncated)
"reference"=>nil,
"user_id"=>nil,
"subtotal_price"=>"55.00",
"total_discounts"=>"55.00",
"location_id"=>nil,
"source_identifier"=>nil,
"source_url"=>nil,
"processed_at"=>"2017-05-31T15:53:03-04:00",
"device_id"=>nil,
"phone"=>nil,
"browser_ip"=>nil,
"landing_site_ref"=>nil,
"order_number"=>1140,
"discount_codes"=>
[#<ShopifyAPI::Order::DiscountCode:0x007ffbec42ccb0
#attributes={"code"=>"50% OFF", "amount"=>"55.00", "type"=>""},
#persisted=true,
#prefix_options={}>]
So far, so good all data is correct.. then I save and this happens.. the amount discounted is incorrect... it should be £55.
I haven't dug too deep into this, but I'm pretty sure the code needs to be unique.
i.e. you probably already have a Discount Code with the same code 50% OFF with amount: 60.50 defined somewhere else on that shop.
Try using a new, unique discount code and testing with that.
I would suggest creating a new discount code like 50OFF that has amount: 50 with type: percentage, then you can re-use that for orders with a 50% discount.
See the Price Rules reference for more information >
Related
I am successfully writing invoices to Xero, including line item information, thus:
$products_list[] = array(
'Description' => $product_description,
'Quantity' => (float) $row['Quantity'],
'UnitAmount' => (float) $row['List Price'],
'DiscountRate' => $discountPercentage,
'TaxType' => 'OUTPUT2', //20% vat
'TaxAmount' => $calculatedTaxRate, //20% vat
'Name' => $xeroProductName['itemName'],
'ItemCode' => $xeroProductName['itemCode'],
'AccountCode' => $accountCode
);
All is fine except the AccountCode - no matter what I do it simply doesn't get written (neither I think does TaxAmount). I notice in Xero that 'Account' is a dropdown and when an account is selected, the tax amount is calculated.
Any help greatly appreciated.
Andy
This has been driving me nuts for 2 days and I can't find an answer anywhere on Google so would really appreciate a little help..
I have a custom registration form on my website, which sends the data to a fairly standard PHPBB3 user_add process as follows:
$user_row = array(
'username' => request_var('createUsername',''),
'user_password' => phpbb_hash(request_var('createPassword','')),
'user_email' => request_var('createEmail',''),
'group_id' => '2',
'user_timezone' => '1.00',
// 'user_dst' => '0',
'user_lang' => 'en',
'user_type' => $user_type,
'user_actkey' => $user_actkey,
'user_ip' => $user->ip,
'user_regdate' => time(),
'user_inactive_reason' => $user_inactive_reason,
'user_inactive_time' => $user_inactive_time,
);
// Register user...
$user_id = user_add($user_row, $cp_data);
// If creating the user failed, display an error
if ($user_id === false)
{
trigger_error('NO_USER', E_USER_ERROR);
}
That works fine and I'm happy with it, however, I have created a custom profile field in the Admin Control Panel called 'ea_real_name' which I want to hold the user's real name. This corresponds to a field on the registration form called 'createRealName' (sent through as $_POST['createRealName'])
I know that user_add takes an optional field called 'cp_data', but I can't for the life of me work out how to format this data... Should it be an array (something like 'ea_real_name' => request_var('createRealName','') or something else?
PHPBB's wiki for the field is empty (https://wiki.phpbb.com/Custom_profile::submit_cp_field) so not much help...
Thanks! :-)
I was right in my assumption! It's an array with the field name prefixed by pf_.
Finally found an answer here: https://www.phpbb.com/community/viewtopic.php?f=71&t=1638905
$cp_data = array(
'pf_ea_real_name' => request_var('createRealName','')
);
Is the correct way to do it...
I'm trying to make this kind of request:
https://mechanicalturk.amazonaws.com/?Service=AWSMechanicalTurkRequester
&AWSAccessKeyId=[the Requester's Access Key ID]
&Operation=SetHITTypeNotification
&Signature=[signature for this request]
&Timestamp=[your system's local time]
&HITTypeId=T100CN9P324W00EXAMPLE
&Notification.1.Destination=janedoe#example.com
&Notification.1.Transport=Email
&Notification.1.Version=2006-05-05
&Notification.1.EventType=AssignmentSubmitted
based on the documentation here: http://docs.aws.amazon.com/AWSMechTurk/latest/AWSMturkAPI/ApiReference_SetHITTypeNotificationOperation.html
Here's my code:
RTurk.SetHITTypeNotification(:hit_type_id => "3M36IJVRR974ABAC76WQ0TCVKX9SIA", :notification => { :destination => "https://sqs.us-east-1.amazonaws.com/971351813114/MechanicalTurk", :transport => "SQS", :version => "2006-05-05", :event_type => "assignment_accepted" }, :active => true)
and here's the error that I'm seeing:
NoMethodError: undefined method `to_param_hash' for #<Hash:0x007ffe1ed82858>
Anyone know what the to_param_hash error means or how to address it?
Spent a couple hours on this problem. Answering here in case it helps others with the same situation. It turns out that I need to create a Notification object, which makes a lot of sense when you look at how to work with Notifications in RTurk in other contexts. Here's a snippet that works:
n = RTurk::Notification.new("https://sqs.us-east-1.amazonaws.com/971351813114/MechanicalTurk", "SQS", "2006-05-05", "AssignmentAccepted")
a = RTurk.SetHITTypeNotification(:hit_type_id => "3M36IJVRR974ABAC76WQ0TCVKX9SIA", :notification => n, :active => true)
t = RTurk.SendTestEventNotification(:notification => n, :test_event_type => "AssignmentAccepted")
Hope this helps others in the same situation!
I'm building a small webshop. This shop has categories and products. 1 product can have multiple categories.
At the productpage a breadcrumb-path shows the referring category-name (via urlReferrer).
Im trying to get Yii to cache by page with OutputCache, depending on the referrer (the category, since this would change the breadcrump-trail).
Here is my non-working filter:
public function filters() {
return array(
array(
'COutputCache',
'duration' => 3600,
'varyByExpression' => array($this->getReferringCategory()),
'varyByParam' => array('id','slug'),
'dependency' => array(
'class' => 'CDbCacheDependency',
'sql' => 'SELECT MAX(date_updated) FROM product WHERE product_id = '.Yii::app()->request->getParam('id'),
),
)
);
}
Does anybody have a good approach for this?
Best regards, thanks!
'varyByExpression' param should be a PHP expression (it would be evaluated by eval) or PHP callback (would be evaluated by call_user_func_array())
if you use php >=5.4.0, try something like this:
'varyByExpression' => function(){return $this->getReferringCategory();},
Or like this, for older versions:
'varyByExpression' => '$this->getReferringCategory()',
Another noob question that seems like it should be simple:
Thanks to the help received here, I can easily get a sum of selected transactions:
#trip_hash = transactions.sum(:amount_cents, :group => :trip_id)
The issue, however, is that the :amount_cents column represents a raw Money object that needs to be transformed before summing in order to accommodate currency exchange. The Money "composed of" Procs look like this:
composed_of :amount,
:class_name => "Money",
:mapping => [%w(amount_cents cents), %w(currency currency_as_string)],
:constructor => Proc.new { |cents, currency| Money.new(cents || 0, currency || Money.default_currency) },
:converter => Proc.new { |value| value.respond_to?(:to_money) ? value.to_money : raise(ArgumentError, "Can't convert #{value.class} to Money") }
I can easily call:
transactions.map(&:amount).inject(:+)
to get a transformed grand total, but I can't figure out how to do it in the context of the groupings.
Many thanks, again, for the help!
Took a lot of canoodling and reading, but finally figured out the following:
trip_hash = bankroll.transactions.group_by(&:trip_id).map {|tr,t| Hash[tr, t.map(&:amount).inject(:+)]}
=>[{0=>#<Money cents:137693 currency:USD>}, {7=>#<Money cents:-39509 currency:USD>}, {10=>#<Money cents:50009 currency:USD>}]
Map within the map did it! Hashifying makes it view friendly, and it retains the Money object for formatting purposes....