I use rest api to create a simple product on my magento. All works correctly except quantity column that is correctly update on "Quantity" column but not on the salable quantity.
Rest call: "www.mysite.com/V1/products"
Array data
$data = [
"product" => [
"sku" => $sku,
"name" => $product_title,
"attribute_set_id" => 4,
"price" => $price,
"status" => 1,
"visibility" => 4,
"type_id" => "simple",
"weight" => "1",
"extension_attributes" => [
"category_links" => [
[
"position" => 0,
"category_id" => "53"
]
],
"stock_item" => [
"qty" => $qty,
"is_in_stock" => true
]
],
"custom_attributes" => [
[
"attribute_code" => "special_price",
"value" => $salable_price
],
[
"attribute_code" => "special_from_date",
"value" => "2021-02-07 00:00:00"
],
[
"attribute_code" => "special_to_date",
"value" => "2091-02-07 00:00:00"
],
[
"attribute_code" => "cost",
"value" => $salable_price
],
[
"attribute_code" => "description",
"value" => $description
],
[
"attribute_code" => "short_description",
"value" => $short_description
]
]
]
];
As you see, qty has been correctly update on qty column but not on the salable quantity. What is my mistake?
Please try this:
"stockItem": {
"is_in_stock": 1,
"qty": 10,
"manage_stock": true,
"use_config_manage_stock": 1
}
Related
I have two collections in MongoDB I want to aggregation between them, it worked fine but I don't know how to print the value in the blade(view) of levels that's come from other collection?
$allRanges = Range::raw(( function($collection) {
return $collection->aggregate([
[
'$lookup' => [
'from' => 'Levels',
'localField' => 'LevelId',
'foreignField'=> '_id',
'as' => 'levels'
]
], [
'$match' =>[
'PlanTypeId'=> '5daad2c12939b70f0b7ff052'
]
],
]);
})))->toarray();
output:
=> [
[
"_id" => "5daad809095e6f0c7e37fbf2",
"PlanTypeId" => "5daad2c12939b70f0b7ff052",
"LevelId" => "5dab14832d31e850ea1644b2",
"Range" => "range1",
"step" => 1,
"part" => 10,
"levels" => MongoDB\Model\BSONArray {#3149
flag::STD_PROP_LIST: false,
flag::ARRAY_AS_PROPS: false,
iteratorClass: "ArrayIterator",
storage: [
MongoDB\Model\BSONDocument {#3146
flag::STD_PROP_LIST: false,
flag::ARRAY_AS_PROPS: true,
iteratorClass: "ArrayIterator",
storage: [
"_id" => MongoDB\BSON\ObjectId {#3147
+"oid": "5dab14832d31e850ea1644b2",
},
"PlanTypeId" => "5daad2c12939b70f0b7ff052",
"Level" => "1",
],
},
],
},
],
I get the Range but how get for example levels->Level?
<tr>
#foreach($allRanges as $d)
<td>{{$d['Range']}}</td>
</tr>
#endforeach
I'm having trouble adding taxes to a square checkout api transaction. Everything else is working, but I can't make the taxes part work. It would be appreciated if someone could post a few lines of the relevant php code that adds taxes at the item or order level. Thank you in advance.
Here's an example of a PHP Checkout request that create a $5.00 charge, with a 10% tax (50 cent) at the order level:
$checkout_api = new \SquareConnect\Api\CheckoutApi();
$request_body = new \SquareConnect\Model\CreateCheckoutRequest(
[
"idempotency_key" => uniqid(),
"order" => [
"line_items" => [
[
"name" => "Test Payment",
"quantity" => "1",
"base_price_money" => [
"amount" => 500,
"currency" => "USD"
]
]],
"taxes" => [
[
"name" => "This is so taxing",
"type" => "ADDITIVE",
"percentage" => "10"
]
]
]
]
);
$response = $checkout_api->createCheckout($location_id, $request_body);
If you want to add it at the item level, you would just move the taxes array to inside the line_items object. Example of 2 items, one with tax and one without:
$checkout_api = new \SquareConnect\Api\CheckoutApi();
$request_body = new \SquareConnect\Model\CreateCheckoutRequest(
[
"idempotency_key" => uniqid(),
"order" => [
"line_items" => [
[
"name" => "Test Payment",
"quantity" => "1",
"base_price_money" => [
"amount" => 500,
"currency" => "USD"
],
"taxes" => [
[
"name" => "This is so taxing",
"type" => "ADDITIVE",
"percentage" => "10"
]
]
],
[
"name" => "Test Payment Without Tax",
"quantity" => "1",
"base_price_money" => [
"amount" => 500,
"currency" => "USD"
]
]],
]
]
);
$response = $checkout_api->createCheckout($location_id, $request_body);
I watched Elasticsearch Do's, Don'ts and Pro-Tips by Itamar Syn Hershko
https://www.youtube.com/watch?v=c9O5_a50aOQ
I see multiple conditions in several fields in the following image:
https://imgur.com/a/17zAZ4w
I tried to make it in
my Laravel 5.7 app (with the elasticsearch/elasticsearch plugin) as seen in the following code:
$elasticQuery = [
"bool" => [
'must' => [
'multi_match' => [
'query' => $text,
'fields' => ['name^4', 'description']
],
],
"should" => [
'term' => [
"category_id" => 1,
]
]
]
];
but I got the error :
{"error":{"root_cause":[{"type":"parsing_exception","reason":"[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":130}],"type":"parsing_exception","reason":"[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":130},"status":400}
But when I use a simple condition:
$elasticQuery = [
'multi_match' => [
'query' => $text,
'fields' => ['name^4', 'description'],
],
];
I got a valid result:
[hits] => Array
(
[total] => 1
[max_score] => 7.4126062
[hits] => Array
(
[0] => Array
(
[_index] => select_vote
[_type] => vote
[_id] => 16
[_score] => 7.4126062
[_source] => Array
(
[id] => 16
[slug] => in-the-film-babe-what-type-of-animal-was-babe
[name] => In the film Babe, what type of animal was Babe?
[description] => Babe is a 1995 A...
[created_at] => 2018-11-10 09:14:15
[category_id] => 2
[category] => Array
(
[name] => Movie&Cartoons
[slug] => movie-cartoons
[created_at] => 2018-11-10 09:14:12
)
)
)
)
)
is this a valid format for multi-request?
MODIFIED BLOCK # 2:
Making some search I found work:
$elasticQuery = [
"bool" => [
'should' => [
[
"multi_match" => [
"query" => $text,
"type" => "cross_fields",
"fields" => [
"name^4",
"description"
]
]
],
[
'match' => [
'category_id' => [
'query' => 1,
]
]
],
[
'match' => [
'category_id' => [
'query' => 3,
]
]
],
]
]
];
when I need to make a search by text fields and the array of category (1 and 3) in the example above it works but looks like it works like an "OR" condition, but I need to make a restriction like "AND" using SQL terminology...
Which way is correct in order to make a restriction as like "AND"?
Thanks!
If you just change should to must it is not going to work because category_id cannot have two values at the same time (unless it's an array, but it's not).
You need to use the following query instead:
$elasticQuery = [
"bool" => [
'must' => [
[
"multi_match" => [
"query" => $text,
"type" => "cross_fields",
"fields" => [
"name^4",
"description"
]
]
],
],
'filter' => [
[
'terms' => [
'category_id' => [ 1, 3 ]
]
]
]
]
];
I want to write query with following condition :
search by category (like category = 'cat1')
and with price range (and price between 100 to 500)
and sort by price (low to high)
I tried:
$params = [
'index' => 'my_index',
'type' => 'product',
'body' => [
//"from" => 0, "size" => 2,
"sort" => [
["default_product_low_price.sale_price" => ["order" => "asc"]]
],
'query'=> $query,
"aggs" => [
"default_product_low_price" => [
"nested" => [
"path" => "default_product_low_price"
],
"aggs" => [
"range" => ["default_product_low_price.sale_price" => [ "gte" => '790',
"lte" => '1000' ]],
//"max_price" => ["max" => [ "field" => "default_product_low_price.sale_price" ]]
],
]
]
]
];
But I am getting an error
Bad Request 400 Exception in GuzzleConnection.php line 277: error.
Please guide me where I am wrong? What is the right query?
I think this should be your query :
$params = [
'index' => 'my_index',
'type' => 'product',
'body' => [
"sort" =>[
["default_product_low_price.sale_price" => ["order" => "asc"]]
],
"query"=> [
"filtered"=> [
"query"=> [
"match_all"=> []
],
"query"=>[
"term"=> [
"category.name"=> "jeans"
]
],
"filter"=> [
"nested"=> [
"path"=> "default_product_low_price",
"filter"=> [
"bool"=> [
"must"=> [
[
"range"=> [
"default_product_low_price.sale_price"=> [
"gte"=> 100,
"lte"=> 200,
]
]
]
]
]
]
]
]
]
]
]
];
I'm trying to order elements by field descending in Elasticquent, but don't know how. This is my code:
$laws_y = Law::searchByQuery([
],
[
"group_by_law_year" => ["terms" => ['field' => "law_year", "size" => 100]]
]);
Can anyone help?
You can do it using the order setting and order by _term: desc:
$laws_y = Law::searchByQuery([
],
[
"group_by_law_year" => [
"terms" => [
'field' => "law_year",
"order" => ["_term" => "desc" ], <--- add this line
"size" => 100
]
]
]);