How to retrieve abandoned cart details in Magento? - magento2

I am creating a new extension in Magento version 2. Now I need to get abandoned carts report details. How can I retrieve this data?

Finally I found the way to get the abandoned cart details. Here is the code.
$om = \Magento\Framework\App\ObjectManager::getInstance();
$collection = $om->get('Magento\Reports\Model\ResourceModel\Quote\Collection');
$store_id = $this->storeManager->getStore()->getId();
$collection->prepareForAbandonedReport([$store_id]);
$rows = $collection->load();

Related

Google currency converter no longer working

It appears that Google Finance Currency Converter has stopped working altogether. A week ago I started getting these email notifications from my Magento 1.9.2 store:
Currency update warnings:
WARNING: Cannot retrieve rate from https://finance.google.com/finance/converter?a=1&from=GBP&to=EUR.
WARNING: Cannot retrieve rate from https://finance.google.com/finance/converter?a=1&from=GBP&to=USD.
Those URLs are indeed no longer valid. Does anyone know if there are new URLs we can use, or do we need to configure a different service?
This link is not working anymore.
protected $_url = 'https://finance.google.com/finance/converter?a=1&from={{CURRENCY_FROM}}&to={{CURRENCY_TO}}';
I researched and found this codes.
Find this file:
app/code/local/Payserv/GoogleFinance/Model/Google.php
Replace the codes with this:
class Payserv_GoogleFinance_Model_Google extends Mage_Directory_Model_Currency_Import_Abstract {
protected $_url = 'http://free.currencyconverterapi.com/api/v3/convert?q={{CURRENCY_FROM}}_{{CURRENCY_TO}}';
protected $_messages = array();
protected function _convert($currencyFrom, $currencyTo, $retry=0) {
$url = str_replace('{{CURRENCY_FROM}}', $currencyFrom, $this->_url);
$url = str_replace('{{CURRENCY_TO}}', $currencyTo, $url);
try {
$resultKey = $currencyFrom.'_'.$currencyTo;
$response = file_get_contents($url);
$data = Mage::helper('core')->jsonDecode($response);
$results = $data['results'][$resultKey];
$queryCount = $data['query']['count'];
if( !$queryCount && !isset($results)) {
$this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $url);
return null;
}
return (float)$results['val'];
} catch (Exception $e) {
if ($retry == 0) {
$this->_convert($currencyFrom, $currencyTo, 1);
} else {
$this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s', $url);
}
}
}
}
It seems to be intermittent (it shows if I load a page 10 times or so, but only once every 10 clicks). But I've personally started configuring other services. I am using bank API's (currently a Swedish one so it might not help you). But check with your bank, they usually have APIs.
Good luck!
Apparently Google doesn't offer this service anymore.
The main alternative looks to be:
Fixer.io API
Currencylayer API
Both offers 1000 request for free a month ( you need to create an account on their homepage )
Source: https://stackoverflow.com/a/8391430/716435
Google doesn't provide the currency converter API anymore. There are several alternative APIs offering currency conversion data. Some have been mentioned in posts already (Fixer, Currencylayer...)
Another option is SWOP currency exchange rate API, a fast, easy to use, reliable and transparent foreign exchange rate API made from developers for developers. Full disclaimer: I'm one of the developers of SWOP :)
The SWOP API offers current and historical rates for 180+ currencies. They are gathered directly from trusted sources (various Central Banks and other important banks).
The SWOP API has two endpoints, GraphQL and REST/JSON, for developer convenience.
There's a free plan allowing 1,000 requests per month.
The problem is with the link, google updated the api link recently, and I found success once on checking 10 times to the existing link. Try changing to this link https://www.google.com/finance/converter
see this https://www.techbuy.in/google-finance-api-currency-converter-not-working-updated-link-check-currency-converter/
I was facing same problem from last week. But new url solved my problem and now currency conversion working fine.
try this:
https://finance.google.com/bctzjpnsun/converter
Google's finance URL doesn't seem to work for now, I have prepared a workaround to use MSN Money (Microsoft's) API. It returns JSON so you can consume it using any programing language, I have put sample using PHP:
function msn($from, $to, $amount) {
$url = 'https://finance.services.appex.bing.com/Market.svc/ChartDataV5?symbols=245.20.'.strtoupper($from).strtoupper($to).'LITE&chartType=1y';
$request = curl_init();
$timeOut = 0;
curl_setopt($request, CURLOPT_URL, $url);
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($request, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)');
curl_setopt($request, CURLOPT_CONNECTTIMEOUT, $timeOut);
$response = json_decode(curl_exec($request));
curl_close($request);
$rate = array_last($response[0]->Series)->P;
return $rate * $amount;
}
The above function accepts the currency that you currently have, the target currency and amount. Send's a GET request to MSN URL and parses the JSON to get today's exchange rate. Finally, it multiplies the rate with your amount to convert it to the target currency.
I hope this solves your need, the code has a lot of rooms for optimization I just gave you a simple implementation
For example, you can save the exchange rate in your database and use that rate for one day this way you will only call the API once a day.

Extend magento rest api to get category listing

I have created an extended service using Create new magento Rest api to get category list in magento , Now don't know what will be the url to hit that service.
$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');
$allCategories = $proxy->call($sessionId, 'category.tree'); // Get all categories.
this code will ussfull to call the api(SOAP), run this form root.
$oauthClient= new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
$oauthClient->enableDebug();
Call rest using this code

Paypal billing plan description?

I want to do the following in paypal rest! api billing plan:
the description in the left, how do i do this in php rest api when it comes to billing plan?
For example, if it was just one ordinary item, i did this with the following code:
$item = new Item();
$item->setQuantity('1');
$item->setName('benny');
$item->setPrice('7.41');
$item->setCurrency('USD');
$item->setSku('blah');
// //var_dump($item);
$items = new ItemList();
$items->addItem($item);
...
$transaction->setItemList($items);
I don't see anything similar when it comes to the plans api:
https://developer.paypal.com/docs/api/#billing-plans-and-agreements
This is what i get when i do an agreement: (only description but i want items to be here too, just like the prev example)

How do I connect to external API from Magento

I am looking for some assistance in creating an API based module to push customer information out of Magento into a Third party loyalty program.
So far I have created a basic module but cannot find any good information on creating API based modules in Magento and could really do with some advice please...
I need to somehow hook into the Checkout success page in Magneto and add a form the will POST the customers information (name, address etc) to a third party loyalty program. I also need to be able to login to complete the billing information etc...
Does anyone know of any handy tutorials or documentation for such an implementation?
So far I have setup an API user with the appropriate roles. I have also created a very basic module for test purpses but browsing to the file I get a 404 error
apitest.php
<?php
$proxy = new SoapClient('http://mysite.com/api/?wsdl'); //edit the address and put the url to your magento here
$sessionId = $proxy->login('######', '#######'); // put in the info for your user here
echo "Login ID : $sessionId";
$result = $proxy->call($sessionId, 'Mymodule.testConnection', array('param1' => ' This string was sent from soap client'));
echo $result;
Objectmodel/api.php
<?php
class MyModule_MyModule_Model_ObjectModel_Api extends Mage_Api_Model_Resource_Abstract
{
public function testConnection($arg)
{
return "Hello World! My argument is : " . $arg;
}
}
I followed the example from here for getting a basic 'Hello world' module up and running if anyone could assist me with getting the correct setup I would be grateful
Instead of connect magento API you can create customer like this.
define('INCLUDE_PATH', '/var/www/QA/mojostage/app/');
define('INCLUDE_FILE', 'Mage.php');
Mage::app();
$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId($wesite_id);
$customer->loadByEmail($customer_email);
/*
* Check if the email exist on the system.
* If YES, it will not create a user account.
*/
if (!$customer->getId()) {
//setting data such as email, firstname, lastname, and password
$customer->setEmail($customer_email);
$customer->setTaxvat($value['cus_vatnumber'])
->setCreatedAt($date1)
->setDob($value['date_of_birth'])
->setGroupId($cus_group_id)
->setConfirmation($is_active)
->setCreatedIn('Admin')
->setStoreId($store_id)
->setWebsiteId($wesite_id)
->setEntityId($value['cus_id']);
$customer->setFirstname($customer_fname);
$customer->setLastname($customer_lname);
$customer->setPassword($value['password']);
$subscriber = Mage::getModel('newsletter/subscriber');
$subscriber->setStoreId($store_id)
->setCustomerId($value['cus_id'])
->setSubscriberEmail($customer_email)
->setSubscriberStatus($value['cus_spam'])
->setSubscriberConfirmCode($subscriber->randomSequence());
}
//the save the data and send the new account email.
$customer->save();
$subscriber->save();

cannot get full shopping cart detail using GetExpressCheckoutDetails

I am currently testing an online store using a custom cart within paypal sandbox.
I am able to go trough all transcation steps properly
setExpressCheckout-> pay -> DoExpressCheckout.
During the DoExpressCheckout step I think it would be the good time to update my database with the order. For that I use the GetExpressCheckoutDetails function to retrieve the content of the transaction.
Sadly this function return everything paypal has to offer but miss the content of my cart. All i can get is the detail of one item. If the transaction involve multiple items i would only get the details of the first one.
Here is my code (mostly taken from paypal samples) :
$token =urlencode( $_REQUEST['token']);
$payerId=urlencode( $_REQUEST['PayerID']);
$getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($token);
$getExpressCheckoutReq = new GetExpressCheckoutDetailsReq();
$getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
$paypalService = new PayPalAPIInterfaceServiceService();
$getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
$details = $getECResponse->GetExpressCheckoutDetailsResponseDetails;
// $details->PaymentDetails->PaymentDetailsItem this array should hold all items details
// sadly it always have 1 element instead of the full content of my cart :(
$orderTotal = $details->PaymentDetails->OrderTotal;
$PaymentDetails= new PaymentDetailsType();
$PaymentDetails->OrderTotal = $orderTotal;
//
Some stuff with payment details
//
$DoECRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
$DoECRequest = new DoExpressCheckoutPaymentRequestType();
$DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails;
$DoECReq = new DoExpressCheckoutPaymentReq();
$DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
$DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq);
Do i miss a step or call a bad function. Because i tried to print_r every variable i came across and the full content of my cart was nowhere to be found. I find this strange since the 'orderTotal' of the transaction match with my original cart. I could store my original order during the SetExpressCheckout step but since paypal already have those values i find it redundant.
As a last resort I did found the content of my cart using $paypalService->getLastRequest() but seriously this is the raw XML returned by paypal and the api should be parsing it properly :(.
Thanks for reading
I had this exact same issue - while the XML returned by PayPal is fine, their PHP SDK doesn't parse it properly, so you can only ever see the last item in GetExpressCheckout.
I've posted a fix for this problem in an issue on PayPal's GitHub, please check it out:
https://github.com/paypal/SDKs/issues/37