The entirety of this code works on other machines with PHP v 7.3 but my production machine is 7.4. Every time i go to print out the order creation data it just comes up blank. Trying to insert anything into the array using short syntax is just not working at all any ideas why. This little chunk is the offender in question and when printing out order creation data I don't get anything.
$order_creation_data = array(
'order' => array(
'email' => $email,
'fulfillment_status' => $shopify_fufillment_status,
'financial_status' => 'paid',
)
);
$shopify_address_build_array = array(
'first_name' => $shopify_customer_default_address['first_name'],
'last_name' => $shopify_customer_default_address['last_name'],
'address1' => $shopify_customer_default_address['address1'],
'address2' => $shopify_customer_default_address['address2'],
'phone' => $shopify_customer_default_address['phone'],
'city' => $shopify_customer_default_address['city'],
'province' => $shopify_customer_default_address['province'],
'country_code' => $shopify_customer_default_address['country_code'],
'zip' => $shopify_customer_default_address['zip'],
);
$order_creation_data['order']['billing_address'] = $shopify_address_build_array;
$order_creation_data['order']['shipping_address'] = $shopify_address_build_array;
Related
I go through this documentation "https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/journalentry"
And tried to add journal entry with line having customer as shown in the below code:
$journal_entry_create['TxnDate'] = date('Y-m-d');
$journal_entry_line = array(
'Amount' => $amount,
'DetailType' => 'JournalEntryLineDetail',
'JournalEntryLineDetail' => array(
'PostingType' => Credit,
'Entity' => array(
'Type' => 'Customer',
'EntityRef' => array(
'type' => 'Customer',
'value' => "2",
'name' => 'Abc'
)
),
'AccountRef' => array(
'name' => 'Account Name',
'value' => '1'
),
)
);
$journal_entry_lines[] = $journal_entry_line;
$journal_entry_create['Line'] = $journal_entry_lines;
$journal_entry_receipt_create = QBJournalEntry::create($journal_entry_create);
$journal_entry_receipt_create_result = $dataService->Add($journal_entry_receipt_create);
Without EntityRef its working fine but when I add EntityRef its giving me error "Message: Passed array has no key for 'Value' when contructing an ReferenceType"
Only just came across this problem myself. They did fix this issue but didn't seem to document it at all or tell anyone. Found the fix in the source code. You need to use "JournalEntryEntity" instead of "Entity" under "JournalEntryLineDetail", like so:
'JournalEntryLineDetail' => array(
'PostingType' => "Credit",
'JournalEntryEntity' => array(
'Type' => 'Customer',
'EntityRef' => array(
'value' => "2"
)
),
'AccountRef' => array(
'name' => 'Account Name',
'value' => '1'
),
)
Also I used the FacadeHelper from the V3 of the PHP SDK (I'm not sure if it'll work with the method you were using):
use QuickBooksOnline\API\Facades\FacadeHelper;
...
$journal_entry_receipt_create = FacadeHelper::reflectArrayToObject('JournalEntry', $journal_entry_create);
$journal_entry_receipt_create_result = $dataService->Add($journal_entry_receipt_create);
I know this is probably too late for you OP but hopefully it helps someone else!
I am creating a new address using shippo api using test token and when i give the array of address and click create it gives me 500 error. I am doing everything according to the docs given by shippo here is my code that I am using. The request I am sending is through ajax.
require_once ABSPATH . '/shippo/shippo/lib/Shippo';
Shippo::setApiKey("test_token");
$address = Shippo_Address::
create(
array(
'object_purpose' => 'QUOTE',
'name' => 'John Smith',
'company' => 'Initech',
'street1' => '6512 Greene Rd.',
'city' => 'Woodridge',
'state' => 'IL',
'zip' => '60517',
'country' => 'US',
'phone' => '773 353 2345',
'email' => 'jmercouris#iit.com',
'metadata' => 'Customer ID 23424'
));
var_dump($address);
I am confuse that what is it that I am doing wrong or missing?
I try to make a web application for my thesis.
Actually it is almost finished but I still have to find a way to store the likes of users in a database. I collect user information and try to see if there is a relation between movies that he or she like and user data elements that are saved in different SNSs. For single information it already save the things the way it should be. The problem is, that facebook work with arrays and objects and I am not able to find a way to save all the likes in a single string (and then save it in a database).
// Insert or update user data to the database
$fbUserData = array(
'oauth_provider' => 'facebook',
//basic profile
'oauth_uid' => $fbUserProfile['id'],
'first_name' => $fbUserProfile['first_name'],
'last_name' => $fbUserProfile['last_name'],
'picture' => $fbUserProfile['picture']['url'],
'email' => $fbUserProfile['email'],
'link' => $fbUserProfile['link'],
'age_range' => $fbUserProfile['age_range']['min'],
'currency' => $fbUserProfile['currency']['user_currency'],
'devices' => $fbUserProfile['devices'],//['hardware']
'gender' => $fbUserProfile['gender'],
'install_type' => $fbUserProfile['install_type'],
'installed' => $fbUserProfile['installed'],
'is_shared_login' => $fbUserProfile['is_shared_login'],
'is_verified' => $fbUserProfile['is_verified'],
'locale' => $fbUserProfile['locale'],
'name_format' => $fbUserProfile['name_format'],
'payment_pricepoints' => $fbUserProfile['payment_pricepoints'], //credits?
'security_settings' => $fbUserProfile['security_settings']['secure_browsing']['enabled'],
'test_group' => $fbUserProfile['test_group'],
'timezone' => $fbUserProfile['timezone'],
'updated_time' => $fbUserProfile['updated_time'],
'verified' => $fbUserProfile['verified'],
'video_upload_limits' => $fbUserProfile['video_upload_limits']['size'],
'viewer_can_send_gift' => $fbUserProfile['viewer_can_send_gift'],
//extended permissions
'relationship_status' => $fbUserProfile['relationship_status'],
'hometown' => $fbUserProfile['hometown']['name'],
'languages' => $fbUserProfile['languages'][0]['name'].",".$fbUserProfile['languages'][1]['name'].",".$fbUserProfile['languages'][2]['name'].",".$fbUserProfile['languages'][3]['name'].",".$fbUserProfile['languages'][4]['name'],
//'likes' => $fbUserProfile['likes'][0]['name'].",".$fbUserProfile['likes'][1]['name']
'favorite_athletes' => $fbUserProfile['favorite_athletes'][0]['name'].",".$fbUserProfile['favorite_athletes'][1]['name'].",".$fbUserProfile['favorite_athletes'][2]['name'].",".$fbUserProfile['favorite_athletes'][3]['name'].",".$fbUserProfile['favorite_athletes'][4]['name'].",".$fbUserProfile['favorite_athletes'][5]['name'].",".$fbUserProfile['favorite_athletes'][6]['name'],
);
$userData = $user->checkUser($fbUserData);
//print
echo $userData['languages'];
echo $userData['favorite_athletes'];
As you can see for languages, likes, favorite_athletes I coded it in the ugly way now to read the profile and store it. The problem is that some people have over 100 likes, and it is of course not handy to code it in this way. When I use the
for each it always bug...
If you're just interested in concatenating arrays for a single table then use PHPs implode function http://php.net/manual/en/function.implode.php
combined with an array map as mentioned here
How to use implode on an array of stdClass objects?
alternatively normalise your database as mentioned in a comment
'favorite_athletes' => implode(",", array_map(function($x) { return $x['name'];},$fbUserProfile['favorite_athletes']));
'likes' => implode(",", array_map(function($x){ return $x['name']}, $fbUserProfile['likes']['data']));
// Insert or update user data to the database
$fbUserData = array(
'oauth_provider' => 'facebook',
//basic profile
'oauth_uid' => $fbUserProfile['id'],
'first_name' => $fbUserProfile['first_name'],
'last_name' => $fbUserProfile['last_name'],
'picture' => $fbUserProfile['picture']['url'],
'email' => $fbUserProfile['email'],
'link' => $fbUserProfile['link'],
'age_range' => $fbUserProfile['age_range']['min'],
'currency' => $fbUserProfile['currency']['user_currency'],
'devices' => $fbUserProfile['devices'][0]['hardware'],
'gender' => $fbUserProfile['gender'],
'install_type' => $fbUserProfile['install_type'],
'installed' => $fbUserProfile['installed'],
'is_shared_login' => $fbUserProfile['is_shared_login'],
'is_verified' => $fbUserProfile['is_verified'],
'locale' => $fbUserProfile['locale'],
'name_format' => $fbUserProfile['name_format'],
'payment_pricepoints' => $fbUserProfile['payment_pricepoints'], //credits?
'security_settings' => $fbUserProfile['security_settings']['secure_browsing']['enabled'],
'test_group' => $fbUserProfile['test_group'],
'timezone' => $fbUserProfile['timezone'],
'updated_time' => $fbUserProfile['updated_time'],
'verified' => $fbUserProfile['verified'],
'video_upload_limits' => $fbUserProfile['video_upload_limits']['size'],
'viewer_can_send_gift' => $fbUserProfile['viewer_can_send_gift'],
//extended permissions
'relationship_status' => $fbUserProfile['relationship_status'],
'hometown' => $fbUserProfile['hometown']['name'],
'languages' => implode(",", array_map(function($x) { return $x['name'];},$fbUserProfile['languages'])),//$fbUserProfile['languages'][0]['name'].",".$fbUserProfile['languages'][1]['name'].",".$fbUserProfile['languages'][2]['name'].",".$fbUserProfile['languages'][3]['name'].",".$fbUserProfile['languages'][4]['name'],
'likes' => implode(",", array_map(function($x){ return $x['name'];}, $fbUserProfile['likes']['data'])),
'favorite_athletes' => implode(",", array_map(function($x) { return $x['name'];},$fbUserProfile['favorite_athletes']))
I have the following code running on my laptop which is running a MAMP server (so apache). On my system it works absolutely fine, however, when I push it to my server it starts throwing "Trying to get property of non-object errors. The databases and migrations are all up to date, and reflect the setup on my laptop. I am wondering why this would be happening on my server and not my laptop. It also seems to happen randomly, which makes me think it's possibly a caching problem?
foreach($posts as $post){
$user = User::where("id","=",$post->posted_by)->first();
$response['posts'][] = [
'id' => $post->id,
'username' => $user->username, //causes problem
'firstname' => $user->name, //causes problem
'lastname' => $user->lastname, // causes problem
'images' => $post->getPostImages(),
'title' => $post->title,
'content' => $post->content,
'price' => $post->price,
'category' => Category::find($post->category_id)->title //causes problem
];
}
This is happening because a category object cant be found
you should change your code to this
foreach($posts as $post){
$user = User::where("id","=",$post->posted_by)->first();
//check if category id is set
if(!$post->category_id)
abort(500,'category_id is not set with Post: #'.$post->id);
//get the category
$category = Category::find($post->category_id);
//check if it found a category
if(!is_object($category)){
abort(500,'could not find Category: #'.$post->category_id);
}
$response['posts'][] = [
'id' => $post->id,
'username' => $user->username, //causes problem
'firstname' => $user->name, //causes problem
'lastname' => $user->lastname, // causes problem
'images' => $post->getPostImages(),
'title' => $post->title,
'content' => $post->content,
'price' => $post->price,
'category' => $category->title //causes problem
];
}
This change should help you find out what is missing :)
I am using Cakephp 2.2.4 and I need to retrive a list of Lead that belongs to the user (id = 106).
The result of the query is:
array(
(int) 0 => array(
'Lead' => array(
'id' => '6',
'user_id' => '106',
'date' => '2012-12-31 22:15:23',
'ip' => '127.0.0.1',
'service_id' => '1',
'location' => 'Rome',
'message' => 'Message Message',
'telephone' => null,
'active' => null
),
'User' => array(
'id' => '106',
'email' => 'daje#daje.it',
'pwd' => '0433c024cb08be13000d59a347e640482843f46f177e95749dc6599c259617fd3491dcb940b47693cbbc7f65a2cc5ef62deca2e600c1be133ad54170f7d1fbd1',
'role_id' => '3',
'active' => '1'
),
'Service' => array(
'id' => '1',
'name' => 'Primo servizio'
),
'Estimate' => array(
(int) 0 => array(
'id' => '1',
'lead_id' => '6',
'user_id' => '106'
)
)
)
)
It looks good but I need to count the Estimates (Estimate array), I would like to retrive the number of the estimates, and not the array with all the fields (of estimates table).
How can i do it?
I need :
Lead array as it shown
User array as it shown
Service array as it shown
Estimate (only the total number of the estimates... in this case 1)
The find is very simple:
$options = array('conditions' => array('User.id' => 106));
debug($this->Lead->find('all', $options));
Try something like this, not 100% sure it'll work but worth a go if not I'd advise trawling the cakephp docs for retrieving your data:
$options = array(
'fields' => array('Lead.*', 'User.*', 'Service.*', 'count(Estimate.id)'),
'conditions' => array('User.id' => 106)
);
Without diving too far into the internals of the Cake ORM, assuming you don't need to do this immediately at query time, couldn't you just get the count of the estimate array programmatically after the fetch?
http://php.net/manual/en/function.count.php
$leads = $this->Lead->find('all',$options);
foreach($leads as $lead){
//get the number of estimates for every lead result
$lead_num = count($lead['Estimate']);
}
Alternatively, you could manually write a join query for this one fetch and execute it using the Cake Model class's query method. Without knowing the specifics of your table schema and model relations its hard to give specifics about how to structure the query, but this shouldn't be too difficult by just look at your table spec and extracting a sql COUNT statement for every Estimate with given id.