Create Magento category with assigned id using SOAP api - api

I am working on a script (which is in Python) for doing some management on our Magento environment.
Now I am wondering if I can create categories with assigned ID.
I think this might be impossible due to key constraints. But is there a way?
Just putting category_id in the parameter list in catalog_category.create, it does not work, it just skips the parameter.
The main reason of wanting this is because I need to know the category ID in order to create the subcategories.
I do know the Magento API returns the ID of the created category. But, I have no way of knowing what subcategories are supposed to go to that created category. (Or I can rewrite a load of code, which I am not too fond of...).
So I was thinking this was the easiest way to go with right now.
Any suggestions, comments, answers? Anything is appreciated!

No, you can't. Magento's entity IDs are for Magento so you cannot specify what you'd like them to be.
When you create an entity with the API it will return the new ID, as you've said.
For your use case it might be easiest to add a new attribute to your categories in Magento, call it "my_category_id" or something and allow your API to set that instead.

Related

Possible to assign order to account?

Is it possible to assign an order manually in the backend to a customer?
I couldn't find anything about it.
Unfortunately this is a regular task of our customer support.
You can create a new order manually in the administration.
You can't however retroactively change the customer of an order placed via the storefront, if that is what you meant. In theory you could do it programmatically by replacing customer specific associations of the order with new ones, based on another customer. It's still likely this would come with a few undesired side effects though.
I guess you mean: You want to create a order for a customer via the administration. For this, have a look into the docs:
https://docs.shopware.com/en/shopware-6-en/orders/create-order-in-admin

Obtaining list of Customers

Is there any way to query balanced and obtain a list of customers via code?
Consider my site has many users, only some of them require a balanced customer id.
I could search my own DB and look for customers who have a balanced id assigned.
For the purpose of error checking I would like to query balanced and get their list of customers.
I know I can do this manually through the marketplace UI, this is not practical so i need to do it programatically.
Here's an example: https://github.com/balanced/balanced-php/blob/master/tests/Balanced/SuiteTest.php#L259
$marketplaces = Marketplace::query()->all();
Balanced's PHP client uses https://github.com/bninja/restful underneath the hood, so every resource has a static query method. Look # https://github.com/bninja/restful/blob/master/src/RESTful/Query.php#L120 to see that this exposes a all() member method as well.
So, for any Balanced resource, in PHP, you can query it by saying ${RESOURCE_NAME}::query(). In your case, if you want to get ALL the customers, then you can do:
Balanced\Customer::query()->all();
Hope this helps.
I'm not sure about PHP, but with ruby you can access it via:
Balanced::Customer.all
If the PHP wrapper provides a Customer Object, I'd guess you'd be able to access it that way.
According to the PHP documentation the object is accessible via:
Balanced\Customer()

Shopify API: Create a Promotion?

Using the Shopify API, is there a way to creation promotions for your store? If not, is there a way to programmatically create promotions in Shopify? (short of using CURL posts to the admin)
That is, I can create a promotion by hand using the admin and navigating to the Promotions and clicking the Add a discount code link. I'd like to be able to do the same thing programmatically, or to know for certain this isn't possible. I don't see any obvious method on the api list, but it seems like something should be an API method.
Unfortunately they don't allow it... I resorted to creating an interface to do so, though:
https://github.com/MartinAmps/Shopify-Private-APIs
Hope it helps
Edit
I also created a blog post about it.
There is no way to create discounts via the API.
If you want we have made an application that can be used to create discount codes.
Otherwise you can use a tool like Mechanize to automate coupon creation for you, but keep in mind theres a good chance that any time in the future it will break since we don't make any promises to keep our admin the same in the future. Any changes have a good chance of breaking whatever script you'd end up writing.
The Price Rules API is now public and allow any app to create price rules and discount codes.
https://help.shopify.com/api/price-rules
If you're familiar with Rails or you're already using ActiveResource for your Shopify API calls, then you can drop in this modified version of Discount < ActiveResource::Base https://gist.github.com/choonkeat/09a56da222f506e627c5

Identify item by either an ID or a slug in a RESTful API

I'm currently designing an API and I came a cross a little problem:
How should a URL of a RESTful API look like when you should be able to identify an item by either an ID or a slug?
I could think of three options:
GET /items/<id>
GET /items/<slug>
This requires that the slug and the ID are distinguishable, which is not necessarily given in this case. I can't think of a clean solution for this problem, except you do something like this:
GET /items/id/<id>
GET /items/slug/<slug>
This would work fine, however this is not the only place I want to identify items by either a slug or an ID and it would soon get very ugly when one wants to implement the same approach for the other actions. It's just not very extendable, which leads us to this approach:
GET /items?id=<id>
GET /items?slug=<slug>
This seems to be a good solution, but I don't know if it is what one would expect and thus it could lead to frustrating errors due to incorrect use. Also, it's not so easy - or let's say clean - to implement the routing for this one. However, it would be easily extendable and would look very similar to the method for getting multiple items:
GET /items?ids=<id:1>,<id:2>,<id:3>
GET /items?slugs=<slug:1>,<slug:2>,<slug:3>
But this has also a downside: What if someone wants to identify some of the items he want to fetch with IDs, but the others with a slug? Mixing these identifiers wouldn't be easy to achieve with this.
What is the best and most widely-accepted solution for these problems?
In general, what matters while designing such an API?
Of the three I prefer the third option, it's not uncommon to see that syntax; e.g. parts of Twitter's API allow that syntax:
https://dev.twitter.com/rest/reference/get/statuses/show/id
A fourth option is a hybrid approach, where you pick one (say, ID) as the typical access method for single items, but also allow queries based on the slug. E.g.:
GET /items/<id>
GET /items?slug=<slug>
GET /items?id=<id>
Your routing will obvious map /items/id to /items?id=
Extensible to multiple ids/slugs, but still meets the REST paradigm of matching URIs to the underlying data model.

Setting carrier per product

I'm working on a store that has two types of products: perishable food and general merchandise. The food must always be shipped overnight via FedEx, and the other merchandise must always be shipped via USPS. If somebody orders products from both categories, they must be shipped separately.
Do you know of an existing module or configuration settings that would allow for this?
If not, it sounds like a custom module would be the other solution. In this case, what is the best approach? I'm thinking it would be splitting the order into a multi-address shipment, using the same address for both but with different shipping methods. Unfortunately I'm not sure how to do this programatically, so any tutorials/samples/resources would be greatly appreciated.
Probably the sanest way to handle this would be to create two orders per product type, each shipping with a different carrier to the same address. This also IMO makes more sense from a stores tracking perspective as you can handle each independently from each other.
To get you on the right track(since Magento is especially cryptic in this part of itself) you should read the Inchoo programmatically create order in Magento post and by the same author Programatically create customer and order in Magento with full blown one page checkout.
Basically as I see this going is:
Get the customer order
Itinerate through each product inside the order and split it up in two arrays for each product type
Create a separate order for each product type and use the different shipping methods for each.
You will probably have to extend a some controllers OR do it the non-standard way and use helper functions for this, the hard parts will be integrating the payment/shipping modules inside your order process. Going this way will have you creating the full checkout process as the one page checkout Magento provides won't really work and is too much pain to get to work because of the way it uses AJAX.
Also another alternative is to hook in to Magento's pre-create order events and create the orders there using already defined order data split it up in two orders, but this is something I never heard or saw implemented at the moment so you'd have to do it "blindfolded" so to speak.
An easier approach would be to use a custom field that defines your product's shipping method, this way you just add that and don't care about custom orders. You just react with that, however tracking will become mostly impossible IMO.
Over-ride the Free Shipping module.
You can setup a sales rule that applies to certain products and makes them 'Free Shipping', leaving the other products to your chosen main shipment provider.
You will need to see how this works, however, the point is that Magento does have something built in to split an order into two shipping categories, albeit only a sales rule on free shipping. But you have source code...