Square API - Object Update for Multiple Locations - square-connect

I'm trying to update objects using the endpoint BatchRetrieveCatalogObjects (POST /v2/catalog/batch-upsert).
When I post the request, I get the error
[type] => bad_request
[message] => Multi-location support is unavailable for this endpoint. Parameter `merchant_id` must correspond to a single-location account, not a business account
How can I update objects if there are multiple locations and if items have location overrides?
Is there another endpoint that I can use?
UpsertCatalogObject (POST /v2/catalog/object) does not work either. Same error.
Below is a sample request payload:
Array
(
[idempotency_key] => 1122334455667788
[batches] => Array
(
[type] => ITEM
[id] => 5BLFIPNYBTDD5ARZYQU4K7SV
[item_data] => Array
(
[name] => Honey Mead
[description] => Mead is an adult beverage brewed exclusively with honey.
[category_id] => OIMGQF7DCO7W6SEXEMKGIJK5
)
[variations] => Array
(
[type] => ITEM_VARIATION
[id] => BEQZ6FXAJACGW55RRZBMXDEI
[item_variation_data] => Array
(
[item_id] => 5BLFIPNYBTDD5ARZYQU4K7SV
[name] => Case (24 bottles)
[pricing_type] => FIXED_PRICING
[ordinal] => 4
[price_money] => Array
(
[amount] => 11900
)
[location_overrides] => Array
(
[0] => Array
(
[location_id] => 81J6E4K21KGC9
[price_money] => Array
(
[amount] => 11900
)
[pricing_type] => FIXED_PRICING
[track_inventory] => 1
[inventory_alert_type] => LOW_QUANTITY
[inventory_alert_threshold] => 15
)
)
)
)
)
)
Additional Notes for Clarification:
I'm trying to edit the price at either the variation or location_overrides level. I get the error for any call to the endpoint. I think the Square API developers don't allow any calls to the endpoint for any multi-unit locations. I also cannot delete locations either on the website or API. They only allow you to hide locations, which I did. But the error still persists.
I tried the v1 endpoint and get strange results. V1 & V2 use different variation_id. So if I pass a v2 variation_id to the v1 endpoint, it creates a new variation rather than updating it. The new variation then displays a new field called catalog_v1_id. Then when I try to delete the variation on the website, it disappears from the website view but still exists as an active item when I call the v2 list variation endpoint. I'm thinking this API has a whole host of bugs and is not ready for prime time.

Related

How do i know notification send to firebase or not

i want to send notification to specific android device with laravel-firebase . currently i am following this "brozot/laravel-fcm" so when Sending a Downstream Message to a Device , how do i know notification is send or not . when i test it in my postman it returns
LaravelFCM\Response\DownstreamResponse Object
(
[numberTokensSuccess:protected] => 0
[numberTokensFailure:protected] => 1
[numberTokenModify:protected] => 0
[messageId:protected] =>
[tokensToDelete:protected] => Array
(
[0] => .....
)
[tokensToModify:protected] => Array
(
)
[tokensToRetry:protected] => Array
(
)
[tokensWithError:protected] => Array
(
)
[hasMissingToken:protected] =>
[tokens:LaravelFCM\Response\DownstreamResponse:private] => Array
(
[0] => .....
)
[logEnabled:protected] =>
)
You can see in the response how many messages succeeded or failed. From your own output above:
[numberTokensSuccess:protected] => 0
[numberTokensFailure:protected] => 1
It looks like you tried to send a message to one device, and it failed.

Magento API 'Exception' with message 'Item (Mage_Sales_Model_Order) with the same id "X" already exist'

I'm trying to get a list of orders using the Magento REST API.
The REST request we use is pretty basic: http://www.example.com/api/rest/orders
The response shows the next error:
{
"messages": {
"error": [
{
"code": 0,
"message": "Item (Mage_Sales_Model_Order) with the same id \"54\" already exist"
}
]
}
}
Checking my exception log to see what's going on and got the next backtrace of the error:
2015-09-10T21:54:59+00:00 ERR (3):
exception 'Exception' with message 'Item (Mage_Sales_Model_Order) with the same id "54" already exist' in /path/to/site/lib/Varien/Data/Collection.php:373
Stack trace:
#0 /path/to/site/lib/Varien/Data/Collection/Db.php(576): Varien_Data_Collection->addItem(Object(Mage_Sales_Model_Order))
#1 /path/to/site/lib/Varien/Data/Collection.php(301): Varien_Data_Collection_Db->load()
#2 /path/to/site/app/code/core/Mage/Sales/Model/Api2/Order.php(302): Varien_Data_Collection->getItems()
#3 /path/to/site/app/code/core/Mage/Api2/Model/Resource.php(245): Mage_Sales_Model_Api2_Order->_retrieveCollection()
#4 /path/to/site/app/code/core/Mage/Api2/Model/Dispatcher.php(74): Mage_Api2_Model_Resource->dispatch()
#5 /path/to/site/app/code/core/Mage/Api2/Model/Server.php(239): Mage_Api2_Model_Dispatcher->dispatch(Object(Mage_Api2_Model_Request), Object(Mage_Api2_Model_Response))
#6 /path/to/site/app/code/core/Mage/Api2/Model/Server.php(107): Mage_Api2_Model_Server->_dispatch(Object(Mage_Api2_Model_Request), Object(Mage_Api2_Model_Response), Object(Mage_Api2_Model_Auth_User_Admin))
#7 /path/to/site/api.php(67): Mage_Api2_Model_Server->run()
#8 {main}
I modified the file app/code/core/Mage/Sales/Model/Api2/Order.php (function _retrieveCollection) and added a line to print some info on the logs:
Mage::log($collection->getSelect(),null,'mylog.log');
That's part of the output:
[_parts:protected] => Array
(
[straightjoin] =>
[distinct] =>
[columns] => Array
(
[0] => Array
(
[0] => main_table
[1] => *
[2] =>
)
[1] => Array
(
[0] => payment_method
[1] => method
[2] => payment_method
)
[2] => Array
(
[0] => gift_message
[1] => sender
[2] => gift_message_from
)
[3] => Array
(
[0] => gift_message
[1] => recipient
[2] => gift_message_to
)
[4] => Array
(
[0] => gift_message
[1] => message
[2] => gift_message_body
)
[5] => Array
(
[0] => order_tax
[1] => title
[2] => tax_name
)
[6] => Array
(
[0] => order_tax
[1] => percent
[2] => tax_rate
)
)
[union] => Array
(
)
[from] => Array
(
[main_table] => Array
(
[joinType] => from
[schema] =>
[tableName] => sales_flat_order
[joinCondition] =>
)
[payment_method] => Array
(
[joinType] => left join
[schema] =>
[tableName] => sales_flat_order_payment
[joinCondition] => main_table.entity_id = payment_method.parent_id
)
[gift_message] => Array
(
[joinType] => left join
[schema] =>
[tableName] => gift_message
[joinCondition] => main_table.gift_message_id = gift_message.gift_message_id
)
[order_tax] => Array
(
[joinType] => left join
[schema] =>
[tableName] => sales_order_tax
[joinCondition] => main_table.entity_id = order_tax.order_id
)
)
[where] => Array
(
)
[group] => Array
(
)
[having] => Array
(
)
[order] => Array
(
)
[limitcount] =>
[limitoffset] =>
[forupdate] =>
)
[_tableCols:protected] => Array
(
)
)
If I understood correctly that means that the SQL statement was something like:
SELECT
main_table.*,
payment_method.method AS method,
gift_message.sender AS gift_message_from,
gift_message.recipient AS gift_message_to,
gift_message.message AS gift_message_body,
order_tax.title AS tax_name,
order_tax.percent AS tax_rate
FROM
sales_flat_order AS main_table LEFT JOIN
sales_flat_order_payment AS payment_method ON main_table.entity_id = payment_method.parent_id LEFT JOIN
gift_message ON main_table.gift_message_id = gift_message.gift_message_id LEFT JOIN
sales_order_tax AS order_tax ON main_table.entity_id = order_tax.order_id
After manually running the previous query, it came up with more than one row with the same entity_id (sales_flat_order). These 'duplicated' entity_id rows seem to be the problem later on when using Varien_Data_Collection->addItem
The part of the query that is making the two rows with same entity_id to be on the resultset is the LEFT JOIN sales_order_tax. That table contains can contain N rows per each order placed, since every row contains a different tax rule applied.
For example in Canada we collect two different Tax Rules combined for
some areas. In British Columbia we collect GST 5% (country specific)
plus PST 7% (province specific).
Am I missing something obvious here, or did I run into a bug?
Any help is much appreciated, thanks for reading!
P.S. My issue is very close to the one described in here: Magento API V2 Sales Orders List Not Working
After a while playing around I think I found a solution, so I'm posting it here for future references.
Solution
We need to modify the query of the collection, to group by sales_flat_order.entity_id before it starts iterating the items in Mage_Sales_Model_Api2_Order::_retrieveCollection.
Since modifying core files it's not a good practice we can make a copy of the core class to the local code pool and modify it as desired. Magento will use the class under the local folder to override the core class.
Copy app/code/core/Mage/Sales/Model/Api2/Order.php to app/code/local/Mage/Sales/Model/Api2/Order.php
Modify the file under the local code pool folder (app/code/local/Mage/Sales/Model/Api2)
Look for the function _retrieveCollection (around line 288 in Magento 1.9.2)
After the line $this->_addTaxInfo($collection); you should add:
$collection->getSelect()->group('main_table.entity_id');
Cons
If we are updating Magento we want to compare our current version of the Mage_Sales_Model_Api2_Order class with the new version, and if we find differences we shall repeat the process of making a copy of the core file under the local code pool folder and perform the edition again.

Yammer: get usernames with messages

I was wondering how I could get the usernames, etc. from messages using the API. Calling the GET messages API gives me all the info I need from the message, but I only get the userID. Because of API request limits, I can't afford to do another API request to know for each messages all the needed userinfo.
Am I missing something, or is this simply not possible?
In fact, check the "references" part of the response and you will find the whole details concerning your user.
I dont see where that is? This is my API response from yammer (for one message)
Array
(
[0] => stdClass Object
(
[id] => 544689850
[sender_id] => 1507082247
[replied_to_id] => 544673530
[created_at] => 2015/06/04 13:03:09 +0000
[network_id] => 355014
[message_type] => update
[sender_type] => user
[url] => https://www.yammer.com/api/v1/messages/544689850
[web_url] => https://www.yammer.com/b-rail.be/messages/544689850
[group_id] => 5741341
[body] => stdClass Object
(
[parsed] => Signed and Approved!
[plain] => Signed and Approved!
[rich] => Signed and Approved!
)
[thread_id] => 544673530
[client_type] => Web
[client_url] => https://www.yammer.com/
[system_message] =>
[direct_message] =>
[chat_client_sequence] =>
[language] => en
[notified_user_ids] => Array
(
)
[privacy] => private
[attachments] => Array
(
)
[liked_by] => stdClass Object
(
[count] => 0
[names] => Array
(
)
)
[content_excerpt] => Signed and Approved!
[group_created_id] => 5741341
)

Magento custom shippment method

I wrote shippment module with checking a lot of resources/tutorials etc. I am using magento 1.9. Source of module is:
https://github.com/aleextra/magentoshipping
I lost full day to find why it doesn't works fine. Magento see my module, when I am adding at Model/Carrier.php at line 52 code:
die($result);
it shows objec dump:
Mage_Shipping_Model_Rate_Result Object
(
[_rates:protected] => Array
(
[0] => Mage_Shipping_Model_Rate_Result_Method Object
(
[_data:protected] => Array
(
[carrier] => mikshipping
[carrier_title] => Mik Carrier
[method] => fixed
[method_title] => Fixed price 10
[price] => 10
[cost] => 10.00
)
[_hasDataChanges:protected] => 1
[_origData:protected] =>
[_idFieldName:protected] =>
[_isDeleted:protected] =>
[_oldFieldsMap:protected] => Array
(
)
[_syncFieldsMap:protected] => Array
(
)
)
)
[_error:protected] =>
)
What I am doing wrong?
As a quick guess I say that your carriers name in the config.xml (mshipping) does not match the code used in Carrier.php (mikshipping). I have them always being the same so Iḿ not absolutely sure if this might cause the issue, but it is easy to check.

Magento get Shipping collectRates() attributes in observer

In a shippingModule in the collectRates method, i have set up a few values:
$method->setCarrier('test_customrate');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('test_customrate');
$method->setMethodTitle($this->getConfigData('name'));
$method->setPrice($this->getConfigData('price'));
$method->setCost(2);
$method->setUsername($this->getConfigData('username'));
$method->setPassword($this->getConfigData('password'));
$result->append($method);
Where are these values stored in the checkout session?
I can't find them anywhere.
I have now found that with the below mentioned code in the observer, i can get a couple of values back as mentioned above. However, some values like cost, username and password are not present here.
$rates = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()
->getShippingRatesCollection();
foreach ($rates as $rate) {
Mage::log($rate->getData());
}
this retrieves something of the following structure:
2013-06-01T15:36:10+00:00 DEBUG (7): Array
(
[rate_id] => 852
[address_id] => 93
[created_at] => 2013-06-01 15:36:06
[updated_at] => 2013-06-01 15:36:09
[carrier] => test_customrate
[carrier_title] => test_customrate
[code] => test_customrate_test_customrate
[method] => test_customrate
[method_description] =>
[price] => 0.0000
[method_title] => test123
[error_message] =>
)
I worked around this by simply getting the values directly from the shipping module config.
Like this:
Mage::getStoreConfig('section/group/field');
So I'm just getting the data from system.xml like i did in the collectRates().
However this is quite static and i would still prefer a method to get this straight from the order.
For now this fixes my problem. If anything knows any other ways feel free to answer

Resources