I'm trying to post a new order which comes from another marketplace. I have all the correct information, but for some reason the POST is not accepting or recognizing the variant_id Im sending. It always returns an error saying I'm missing name, price, and title. I'm not sure why this comes. Here is the array Im sending:
Array
(
[order] => Array
(
[line_items] => Array
(
[0] => Array
(
[id] => 2147483647
[quantity] => 1
[price] => 609
)
)
[customer] => Array
(
[first_name] => Jurgen
[last_name] => Feuchter Garcia
[email] => mail#gmail.com
)
[note] => /// ***** ORDEN MERCADOLIBRE ***** /// ID DE ORDEN ML: order_number
[financial_status] => pending
[tags] => Array
(
[0] => Orden MercadoLibre
)
)
)
And here is the response:
Array
(
[errors] => Array
(
[order] => Array
(
[0] => Line items is invalid
)
[line_items] => Array
(
[0] => Name can't be blank
[1] => Title can't be blank
)
)
)
I've tried using the value name variant_id instead of id, and it asked me for the same information. Any ideas why this might be happening?
I actually found out what was wrong, the variant_id was wrong. Apparently if the variant_id is wrong, it tells you that name and title is missing, and if you have it right, it mentions that price line is missing. This is what happened to me. Not totally sure if it works like that, but I got it to work using the correct variant_id and adding pricing for the product.
You can't add a price like that and mind that the id pertains to a variant id and not the product id.
Your variant with id 214748364 should already be priced before hand in the Shopify admin dashboard (backend).
Error 1 is displayed because Price is not part of line_items.
Error 2 is however strange because, Name and Title are not compulsory parts of line_items. For e.g. below example would create an order successfully.
POST /admin/orders.json
{
"order": {
"email": "foo#example.com",
"fulfillment_status": "fulfilled",
"send_receipt": true,
"send_fulfillment_receipt": true,
"line_items": [
{
"variant_id": 447654529,
"quantity": 1
}
]
}
}
Related
I'm pretty out of practice with MySQL and PHP, but I have a project I'm working on for a friend that involves selecting data from two tables, and combining them into one result - seems simple.
Table 1 has 13 fields, but the important ones are id (auto-increment, primary key) and serial (unique). The rest are just ones like customer, description, etc. etc.
Pictures has 3 fields, picID (auto-increment, primary key), imagePath and serial
I need to retrieve all data from Table 1, and if there is a matching photo (identified by the same serial - only ever 1 photo possible per serial) in Pictures, then retrieve that data too. I then output the data from Table1, and use imagePath from Pictures to build an image in HTML if one has been uploaded.
The query I've been using is:
$sql = "SELECT * FROM Table1 LEFT JOIN Pictures ON Table1.serial = Pictures.serial ORDER BY Table1.serial";
Which seems perfect, EXCEPT if any row from Table1 does not have a photo match in Pictures, the serial is no longer returned with the rest of the data, although the remainder of the row is all correct.
I have looked into the different types of JOIN, and whether it's just UNION that I need, but I am a bit stumped. How should I query to get each row of Table1 plus Pictures.imagePath added on to the matching Table1 row, if it exists?
Thank you for your time!!!! :)
EDIT with dumped array output
Array
(
[0] => Array
(
[id] => 51
[0] => 51
[client] => Test Client
[1] => Test Client
[location] => Ayreford House
[2] => Ayreford House
[description] => Ceiling cavity of building XYZ
[3] => Ceiling cavity of building XYZ
[serial] =>
[4] => 18001
[blah] => 123456
[5] => 123456
[fw] => Wall
[6] => Wall
[pm] => Plasterboard
[7] => Plasterboard
[stuff] => ventilation ducting
[8] => ventilation ducting
[ref] => S1000-2018
[9] => S1000-2018
[otheref] => XTX-1325
[10] => XTX-1325
[notes] => Updated photo
[11] => Updated photo
[date] => 2018-06-28 21:37:49
[12] => 2018-06-28 21:37:49
[picID] =>
[13] =>
[imagePath] =>
[14] =>
[15] =>
)
It's doing that because both Table1 and Pictures have a column called serial and it drops the table names when it is generating the array keys. Probably its doing something like this internally:
$result = array()
$result[0] = Table1.serial;
$result['serial'] = Table1.serial;
$result[1] = Table1.client;
$result['client'] = Table1.client;
....
$result[14] = Pictures.serial;
$result['serial'] = Pictures.serial;
So you end up with only Picture.serial as the value for the key 'serial' in the resulting array.
One way to fix this would be to specify your columns explicitly and don't include Pictures.serial, like this:
SELECT
Table1.id,
Table1.client,
Table1.location,
Table1.description,
Table1.serial,
Pictures.notes
FROM
Table1
LEFT JOIN
Pictures ON Table1.serial = Pictures.serial
ORDER BY
Table1.serial
Too poor documentation drives me crazy in mediawiki and semantic mediawiki.
What does column subobject in smw_object_ids mean? How can I find something related to record which stores something like _QUERYgjdfghjsag9u05sdfa in specified above column?
EDIT
And which data smw_proptable_hash supposed to hold? If I unserialize I see:
array (
'smw_di_number' => '3acec8ed7529527ac33713b1668f31c2',
'smw_di_blob' => 'c201d67c4b8317d31b05d38d796671d2',
'smw_di_time' => 'eff3878694d4aee1e88eb979bbd30097',
'smw_di_wikipage' => 'e474079e8c5fab4ec7197d6aaa884032',
'smw_fpt_ask' => 'e721ae2cb8f49309e10a27467306644c',
'smw_fpt_inst' => 'c7af3f2c8f2f5276c1284b3855358979',
'smw_fpt_sobj' => '7fe51e1a5b9c41d770d3dd8b1e1a16fa',
'smw_fpt_mdat' => 'a400d86be3f69fbb788c4cfcdddaf077',
'smw_fpt_cdat' => 'd063996afa76760ea758a1ab13deb191',
)
But none of them I can't find in specified tables.
Well, I believe you should not perform raw SQL queries to browse semantic data because SMW already has classes and methods for it. Although, they're barely documented, so you'll need to investigate sources to understand how it works and how to properly use it.
You can find some example by looking at sources of SemanticQueryInterface or since it has support for subobjects you can just use it in your code.
According to source code
[`extensions/SemanticMediaWiki/includes/storage/SQLStore/SMW_SQLStore3_Writers.php:462 - preparePropertyTableUpdates`]
hashes gets generated as follows:
$newHash = md5( serialize( array_values( $newData[$tableName] ) ) );
as instance $newData may be
Array
(
[smw_fpt_cdat] => Array
(
[0] => Array
(
[s_id] => 2281824
[o_serialized] => 1/2017/3/22/13/26/37
[o_sortkey] => 2457835.0601505
)
)
[smw_fpt_mdat] => Array
(
[0] => Array
(
[s_id] => 2281824
[o_serialized] => 1/2017/3/22/13/26/37
[o_sortkey] => 2457835.0601505
)
)
[smw_di_wikipage] => Array
(
[0] => Array
(
[s_id] => 2281824
[p_id] => 754161
[o_id] => 2215135
)
[1] => Array
(
[s_id] => 2281824
[p_id] => 754162
[o_id] => 2215135
)
)
[smw_di_number] => Array
(
[0] => Array
(
[s_id] => 2281824
[p_id] => 754163
[o_serialized] => 1
[o_sortkey] => 1
)
[1] => Array
(
[s_id] => 2281824
[p_id] => 754164
[o_serialized] => 157470
[o_sortkey] => 157470
)
[2] => Array
(
[s_id] => 2281824
[p_id] => 754165
[o_serialized] => 638908
[o_sortkey] => 638908
)
)
)
Then, this stuff gets updated as mentioned in
[extensions/SemanticMediaWiki/includes/storage/SQLStore/SMW_SQLStore3_Writers.php:611 - writePropertyTableRowUpdates]
== To be continued soon ==
Please see the discussion at
https://www.semantic-mediawiki.org/wiki/Architecture_Tradeoffs
The viewd SMW_TRIPLES and SWM_TRIPLES_NS will give you access to the subject, predicate, object and type of the triples stored in SQLStore3.
The way it works shows you how the general structure of the SQLStore3 database is linking items.
now you are specifically asking for the table smw_object_ids
which has the following columns:
Field Type Null Key Default Extra
smw_id int(8) unsigned NO PRI (null) auto_increment
smw_namespace int(11) NO (null)
smw_title varbinary(255) NO MUL (null)
smw_iw varbinary(32) NO (null)
smw_subobject varbinary(255) NO (null)
smw_sortkey varbinary(255) NO MUL (null)
smw_proptable_hash mediumblob YES (null)
to be able to view the content of the varbinaries you might want to use a cast e.g. like
select smw_id as id, cast(smw_subobject as char) as subobject,cast(smw_title as char)
as title
from smw_object_ids
where length(smw_subobject)>0
Now you'll see that subobject have an internal hash code that is appended to the page title to make the subobjects identifiable within a page.
Here is an example of page called "HammerUndSichel" which has four subobjects:
id subobject title
91147 _0a12ff61e3b10c31478f2ff62b49e68e HammerUndSichel
91149 _52193085936ccfee4bc197ce37614073 HammerUndSichel
91207 _7fba483328e69e6aeb6dff0fc74447f4 HammerUndSichel
91148 _838fe1bff8f83dbfa40fb3314c47677b HammerUndSichel
For the internal storage the "id" column is used and the subobject column does not come into play yet. The trouble only starts when you would like to do some kind of reverse search. E.g. the subobject with the id 91147 and the subobject _0a12ff61e3b10c31478f2ff62b49e68e you'd like to find out some property value set within that subobject. Within an ask query you do this with hasSubObject in the SQL Store this gets more tricky.
The SMW_TRIPLES_NS view addresses the issue by adding the namespace and subobject information to each subject in the triples. This allows to uniquely identify subobject triples.
For the second part of your question regarding the hash please look at some of the other answers which seem to be more competent on the issue than me.
I have 2 dropdowns were content of the second one depends on the first one. I produce it's content by generating an array and passing it to JsonResponse
new JsonResponse($response_object);
My $response_object is created based on the list in the database where array keys match entity ID:
6 => 'A Item',
3 => 'B Item',
1 => 'C Item',
10 => 'D Item'
Problem is, that even tho I'm passing that list to JsonResponse as displayed (sorted by value), it displays it in the dropdown ordered by the key, not value.
This is how I build the response_object
foreach ($entities as $entity) {
$response_object->entities[$entity->getId()] = $entity->getName()
}
$response = new JsonResponse($response_object);
return $response;
Twig is a simple for widget
{{ form_widget(select_current_form.entity) }
Config in form builder for this particular field is
->add('entity', 'choice', array('required' => false, 'choices' => $entity_choices))
How to force it to display the list in order by value?
You can maybe try to use string as key in your array. Remember that you can use natsort to easily sort your array.
Instead of passing an array to the JsonResponse, if you pass an object you will be able to preserve its sorting.
Instead of this,
6 => 'A Item',
3 => 'B Item',
1 => 'C Item',
10 => 'D Item'
Arrange your function to bring an array of objects like this. (In PDO, you can use \PDO::FETCH_OBJ fetch mode)
[0] => stdClass Object
(
[id] => 6
[value] => A Item
)
[1] => stdClass Object
(
[id] => 3
[value] => B Item
)
[2] => stdClass Object
(
[id] => 1
[value] => C Item
)
[3] => stdClass Object
(
[id] => 10
[value] => D Item
)
I hope someone will find this helpful.
I'm using CakePHP 2.5.2 and having a bit of trouble searching for data efficiently.
In my application I've 3 tables, teams, players, skills... In teams there are 80 records, players 2400 records, skills 2400 records... I want to calculate the average skill of a team...
//Team model
public $actsAs = array('Containable');
public $hasMany = array('Player');
//Player model
public $actsAs = array('Containable');
public $hasOne = array('Skill');
public $belongsTo = array('Team');
//Skill model
public $actsAs = array('Containable');
public $belongsTo = array('Player');
My research is:
$team = $this->Team->find('all', array(
'contain' => array(
'Player' => array(
'Skill'
)
),
));
$this->set('team', $team);
that gives the expected result:
Array
(
[0] => Array
(
[Team] => Array
(
[id] => 1
[name] => my_team_name
)
[Player] => Array
(
[0] => Array
(
[id] => 000000419
[name] => Name
[surname] => Surname
[age] => 21
[team_id] => 1
[Team_id] => 1
[Skill] => Array
(
[id] => 20
[player_id] => 000000419
[skill] => 599
)
), ecc.....
This structure use at least 1680 queries... that are too much for me...
I've tried an other way, that involve just one query, returns a bad data structure but all the information that i need (also redundant). unfortunately follow this way i can not iterate in View to display what i need.
$player = $this->Team->Player->find('all', array(
'contains' => array(
'Skill',
),
that returns
Array
(
[0] => Array
(
[Player] => Array
(
[id] => 000000400
[nome] => my_player_name
[cognome] => my_player_surname
[nation_id] => 380
[age] => 29
[team_id] => 2
)
[Team] => Array
(
[id] => 2
[nome] => my_team_name
)
[Skill] => Array
(
[id] => 1
[player_id] => 000000400
[average] => 632
)
)
ecc.
Is there a way to iterate in VIEV to get the average skill of every team? Any other solutions?
Thanks!
You can use my plugin to solve this issue if you can upgrade CakePHP to 2.6 or later. The plugin has a high compatibility with ContainableBehavior, but generates better queries.
I think that the find operation will execute only 2 queries then.
I would be happy if you try it.
https://github.com/chinpei215/cakephp-eager-loader
Usage
1. Enable EagerLoader plugin
// In your model
$actsAs = ['EagerLoader.EagerLoader'];
If you are afraid that loading my plugin breaks something somewhere, you can also enable it on the fly.
// On the fly
$this->Team->Behaviors->load('EagerLoader.EagerLoader');
2. Execute the same find operation
$this->Team->find('all', ['contain' => ['Player' => ['Skill']]]);
3. See the query log
You will see the query log such as the following:
SELECT ... FROM teams AS Team WHERE 1 = 1;
SELECT ... FROM players AS Player LEFT JOIN skills AS Skill ON Player.id = Skill.player_id WHERE Player.id IN ( ... );
if you feeling that query searching so many tables (ie, models) then
you can unbind those model, before performing search with find()
if you want to fetch some particular column of a table, then remove
others column by selecting "fields" in find().
I have the following query in a Cakephp 2.4 model:
$scores = $this->WorkInfo->find('list', array(
'conditions' => array('WorkInfo.work_id' => $work_ids),
'fields' => array('WorkInfo.date', 'SUM(WorkInfo.score)'),
'group' => array('WorkInfo.date')
));
Which generates the following query:
SELECT
`WorkInfo`.`date`,
SUM(`WorkInfo`.`score`)
FROM
`home`.`work_infos` AS `WorkInfo`
WHERE
`WorkInfo`.`work_id` IN (4, 7, 8, 12, 9, 11, 13, 10, 14, 6, 5)
GROUP BY
`WorkInfo`.`date`
The result I get in my application is:
'2014-03-24' => null
'2014-03-25' => null
'2014-03-26' => null
'2014-03-27' => null
'2014-03-28' => null
'2014-03-31' => null
While the result I get from pasting this very query in the mysql console is:
'2014-03-24' => 0
'2014-03-25' => 36
'2014-03-26' => 0
'2014-03-27' => 164
'2014-03-28' => 0
'2014-03-31' => 0
What is going on here? It is supposed that same queries output same results, isn't it?
I have read something about creating virtual fields for this, but I do not want to overkill, it should be possible to perform a simple aggregation query through Cakephp using the find function.
Thanks!
Try this
$scores = $this->WorkInfo->find('all', array(
'conditions' => array('work_id' => $work_ids),
'fields' => array('date', 'SUM(score) AS score'),
'group' => array('date')
));
then with Set::combine you can format your array cakephp find list
$scores = Set::combine($scores, '{n}.WorkInfo.date', '{n}.0.score');
prints=>
'2014-03-24' => 0
'2014-03-25' => 36
'2014-03-26' => 0
'2014-03-27' => 164
'2014-03-28' => 0
'2014-03-31' => 0
Ok, sadly, I think what you want to do can't be done as you want to do it.
Let's see, you use the find('list') method, so that's here in the API. Code looks normal, and as you said, query is ok, returns everything you want. Problem is in line 2883
return Hash::combine($results, $query['list']['keyPath'], $query['list']['valuePath'], $query['list']['groupPath']);
That line organizes the returned array after the query is done. And seeing the doc for that function, we have
Creates an associative array using a $keyPath as the path to build its
keys, and optionally $valuePath as path to get the values. If
$valuePath is not specified, or doesn’t match anything, values will be
initialized to null.
Which is what happens to you. Now, debugging, the query result before applying the Hash::combine function is something like this
Array
(
[0] => Array
(
[WorkInfo] => Array
(
[date] => 2013-04-01
)
[0] => Array
(
[SUM(`WorkInfo`.`score`)] => 24
)
)
)
so you see, you get the results. And the respective Hash::combine
Array
(
[groupPath] =>
[valuePath] => {n}.SUM(WorkInfo.score)
[keyPath] => {n}.WorkInfo.date
)
which probably causes problem with the dot inside the parenthesis. And the combine function doesn't find the valuePath, and you get null, and you get sad.
If you change your query to 'SUM(WorkInfo.score) AS score' (leaving everything as is), you have almost the same problem with valuePath
Array
(
[groupPath] =>
[valuePath] => {n}.SUM(WorkInfo.score) as score
[keyPath] => {n}.WorkInfo.date
)
//respective result array
Array
(
[0] => Array
(
[WorkInfo] => Array
(
[date] => 2013-04-01
)
[0] => Array
(
[score] => 24
)
)
)
You might think that doing 'SUM(score) AS score' (without the dot) will solve it, but the code of find('list') adds the alias if it doesn't find a dot (in line 2865).
So... I guess what I'm saying is: do a virtual field, or listen to Isaac Rajaei, or create a custom find function. But with find('list') and SUM() you won't have luck :(