Hello, Well, I would like to integrate the Magento system on my website (only 1 page), as it has a module for quick integration of the MOIP checkout system, so I would not need to do the whole system by hand, as there is a ready-made module for this platform(Magento).
So that was the only way I could get a transparent MOIP checkout quickly. With this in mind, I want to know how to add items to the Magento cart (through PHP for example), so that when I redirect the client to the checkout page (when the Magento system enters with MOIP module) the cart items can appear right, as if the person had from the beginning adding the items to the cart through the Magento platform.
It is possible? How do I do? Another alternative?
It even seems like a workaround, installing a platform in a folder just to have a MOIP module, but this is the only alternative (faster, I believe) I had to go through this problem…
Any clarification, just ask. Thanks!
I don't know if what I say will help you, because it's not a definitive answer, but I've been through a similar problem, but in my case I really needed to "emulate" a purchase outside of Magento, but pretending that the person had done the entire process inside it and I say I managed to get close, but I gave up Magento is full of freshness and nuances which makes things VERY complicated. So honestly I think the time and headbanging you will have trying to do this will be better to use the MOIP SDK which gives more play. But I will say more or less how far I have come.
1) Programming with Objects
The first way I found to do this is using Magento's own classes, functions and objects, you include the "Mage.php" file in any PHP file and start to assemble the cart by calling the functions, yes Magento literally assembles the cart little by little, it creates a session for that purchase, then adds the user that the purchase belongs to, then adds the products for that session and user, then adds more shipping and payment, and finally generates an order, all within the tables and within that order, that is, you cannot calculate shipping without a registered user, for example, or just a separate zip code, for example.
Something like this (this is just more or less the syntax to run needs more things):
<?php require_once("app/Mage.php"); $session = Mage::getSingleton("customer/session"); $cart = Mage::getSingleton("checkout/cart"); $cart->init(); $cart->addProduct(12, 3); $cart->save(); var_dump($cart); ?>
But it changes a lot from version to version of Magento and what you want to do, so you'll have to dig deeper into the codes of the version you're using and what you want to do, there are several examples on the internet I don't know which could be useful for you, I'll play some for you to see.
2) Using Magento API
Well what a lot of people don't know is that Magento has 2 API system's, one REST that serves to make small internal requests and the other using SOAP (v1 and v2) that you can do almost all operations within Magento (even if mega slow as they are slow if crazy) . To use the API you must first enter the settings there in the 'admin' area and in the API tab create a username and password and set the permissions for that user, it would be something like a key. Remember that there are discrepancies between the v1 version of the API and the v2 version, so I will have to test both to see which will work for its purpose, in my case I used both for each situation that needed a 'module' that only works well in one version.
From there, you just access the API with any PHP file, even if it's running on your local machine, something like that.
<?php $proxy = new SoapClient("http://seuhost.com.br/api/v2_soap/?wsdl"); $sessionId = $proxy->login("user-Criado", "senha-Criada"); $result = $proxy->shoppingCartCreate($sessionId, "3"); var_dump($result); ?>
Well, to use these APIs, you will have to study the code, as it is fragmented into several mini calls such as shipping, payment, users, coupon, among other things, I will point out the links that I think you need.
In both cases, a problem that maybe I see is how you are going to link the user to the cart, in general Magento needs to know in advance who it is to set up the cart, you can even use a 'guest' user, but when you get to the chekout it's a lot payment and shipping problems within Magento, so I couldn't say how you could do this, in my case I received the data first and looked inside Magento (in the DB) for the person's email if I found it, I would get the ID of the user and built it into the cart, if I couldn't find it, I would create a user, and then set up the cart, order, etc.
I know links are not recommended but the code examples are quite large and complex, sorry.