Magento: API product.list error - magento

I am using Magento API to get list product. But it have error
$proxy = new SoapClient($this->_url);
$sessionId = $proxy->login($this->_user, $this->_api);
$filters = array(
'sku' => array('like'=>'msj006%')
);
$result = $proxy->call($sessionId, 'product.list',$filters);
$resultEncode = json_encode($result);
But it giv error: Call to a member function getBackend() on boolean
What wrong here ?

It seems that you have customized core part of magneto Or any extension which is customizing product model can create this issue. You can check your core code located at "app/code/core/Mage/Eav/Model/Entity/Abstract.php"
public function isAttributeStatic($attribute)
{
$attrInstance = $this->getAttribute($attribute);
$attrBackendStatic = $attrInstance->getBackend()->isStatic();
return $attrInstance && $attrBackendStatic;
}

Related

How to update invoice using XERO API?

I am using xero api to integrate it with my web app to manage invoices, currently i want to update invoice through invoice id, i have an helper xero.php file to handle crud operations. I have a function get invoice by invoice id, i want to update the InvoiceNumber. What is the best way to update invoice?
update_invoice_function
public function update_invoice(){
$invoice_id = '******-***-****-****-************';
$updated_invoice = Xero::find_invoice_by_id($invoice_id);
$updated_invoice['response']->TotalDiscount = "1";
$updated_invoice['response']->Date = "2020-01-20";
$updated_invoice['response']->Status = "DRAFT";
$get_invoice_response = Xero::update_invoice_by_id($invoice_id,$updated_invoice['response']);
dd($get_invoice_response);
}
update_invoice_by_id function
public static function update_invoice_by_id($invoice_id,$updated_invoice){
self::instanciate();
try{
$update = self::$xero->loadByGUID('Accounting\\Invoice',$invoice_id);
dd($update);
$update->jsonSerialize($updated_invoice);
$invoice_response = self::$xero->save($update);
$response = [
'error' => false,
'status' => 200,
'message' => 'Invoice updated successfully',
'response' => $invoice_response->getElements()
];
}
catch (Exception $e){
$response = [
'error' => true,
'status' => $e->getCode(),
'message' => $e->getMessage()
];
}
return $response;
}
we have an example app that shows some sample calls to things like createInvoice.. However worth noting that there was recently a breaking change for the newer version of the API to support batch calls for invoice Create & Updates:
Older Way
$result = $apiInstance->updateInvoice($xeroTenantId, $guid, $invoice);
New Way
-> updateOrCreateInvoices is the newest way.. I recommend looking at your version of the package you are running as the function has changed.
https://github.com/XeroAPI/xero-php-oauth2-app/blob/4bf74e915df1b0fee66f954ffcbdc331e762a06a/example.php#L1222
However - in general, doing a POST on an existing invoice with the invoice ID and the New Number will enable you to update it.
{
"InvoiceID": "292532ba-xxxx-xxxx-xxxx-60e7c39c4360",
"InvoiceNumber": "INV-im-a-new-number"
}
Hope this un-blocks you!

Unable to override account creation email template

I need to modify the welcome email sent to user upon new account creation. I need to do this in my custom module. I tried to override the function sendNewAccountEmail in Magento\Customer\Model\Customer using preference method and also using plugin method. Both were not working.
For preference method I added the following
In Vendor/Module/etc/di.xml
<preference for="Magento\Customer\Model\Customer" type = "Vendor\Module\Model\Customer" />
Added Customer.php file in the location Vendor\Module\Model\Customer and added the following code
public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeId = '0')
{
echo "It's Working";exit;
$types = $this->getTemplateTypes();
if (!isset($types[$type])) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Please correct the transactional account email type.')
);
}
if (!$storeId) {
$storeId = $this->_getWebsiteStoreId($this->getSendemailStoreId());
}
$this->_sendEmailTemplate(
$types[$type],
'customname/email/account_email_template',
['customer' => $this, 'back_url' => $backUrl, 'store' => $this->getStore()],
$storeId
);
return $this;
}
Still it's not taking the Customer.php file in the module.
echo "It's Working"; is not displaying.
What is the correct method to follow? I tried the plugin method also. It's also not working.

Passing variable from DOMPDF controller to view

I want create a DOMPDF with laravel, and I must passing my variable to view. I've been try passing variable like below, but it still not working yet.
here my Laravel Controller
public function pdf(Request $request, $id){
$salesorder = $this->show($id)->salesorder;
$detailservice = $this->show($id)->detailservice;
$detailemployee = $this->show($id)->detailemployee;
$data = [$salesorder, $detailemployee, $detailservice];
$pdf = PDF::loadView('summary.invoice', $data);
return $pdf->download('invoice.pdf');
}
the error on my view is :
Undefined variable: salesorder
How to passing some variable from Laravel controller to DOMPDF ?
PS : dd($data) result is correctly
You have to pass the data as below
$data = [
'salesorder' => $salesorder,
'detailemployee' => $detailemployee,
'detailservice' => $detailservice
];
or try using compact
$data = compact('salesorder', 'detailemployee', 'detailservice');
You may try this following
public function pdf(Request $request, $id){
$salesorder = $this->show($id)->salesorder;
$detailservice = $this->show($id)->detailservice;
$detailemployee = $this->show($id)->detailemployee;
$pdf = PDF::loadView('summary.invoice', array('salesorder' => $salesorder,'detailemployee'=>$detailemployee,'detailservice'=>$detailservice));
return $pdf->download('invoice.pdf');
}
You can use library function to do that easily.
$pdf_text = "It will be the text you want to load";
PDF::loadHTML($pdf_text)->save('public/you-file-name.pdf');
You can change the orientation and paper size, and hide or show errors (by default, errors are shown when debug is on)
PDF::loadHTML($pdf_text)->setPaper('a4', 'landscape')->setWarnings(false)->save('public/you-file-name.pdf')
You may try the following.
$html = view('summary.invoice', ['salesorder' => $salesorder, 'detailemployee' => $detailemployee, 'detailservice' => $detailservice])->render();
$pdf = App::make('dompdf.wrapper');
$invPDF = $pdf->loadHTML($html);
return $pdf->download('invoice.pdf');
I know this is old but this may help others. you need to use array key in your view.
Controller:
$data = [
'foo' => $bar,
];
$pdf = PDF::loadView('pdf.document', $data);
return $pdf->stream('doc.pdf');
View:
<p>{{$foo}}</p>

Laravel 5 - PayPal not getting Price when calling API

For some reason PayPal isn't receiving the total price I'm assigning to the transaction.
I'm using NetShell's PayPal module.
I have my controller that looks like this:
class PayPalController extends Controller {
private $_apiContext;
public function __construct() {
$this->_apiContext = PayPal::ApiContext(
config('services.paypal.client_id'),
config('services.paypal.secret'));
$this->_apiContext->setConfig(array(
'mode' => 'sandbox',
'service.EndPoint' => 'https://api.sandbox.paypal.com',
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => true,
'log.FileName' => storage_path('logs/paypal.log'),
'log.LogLevel' => 'FINE'
));
}
public function getCheckout() {
$payer = PayPal::Payer();
$payer->setPaymentMethod('paypal');
$amount = PayPal::Amount();
$amount->setCurrency('USD');
$amount->setTotal(42); // This is the simple way,
// you can alternatively describe everything in the order separately;
// Reference the PayPal PHP REST SDK for details.
$transaction = PayPal::Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('What are you selling?');
$redirectUrls = PayPal::RedirectUrls();
$redirectUrls->setReturnUrl(action('PayPalController#getDone'));
$redirectUrls->setCancelUrl(action('PayPalController#getCancel'));
$payment = PayPal::Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setRedirectUrls($redirectUrls);
$payment->setTransactions(array($transaction));
$response = $payment->create($this->_apiContext);
$redirectUrl = $response->links[1]->href;
return Redirect::to( $redirectUrl );
}
// Other functions here. Removed for question.
}
getCheckout() gets called at the route `/paypal/checkout'
When I go to /paypal/checkout there is no price.
Have I missed something? Any help would be appreciated.
Thanks!
It could be about the price type.Price must be declared in float.
Try,
floatval($price)
And check this out,I wrote about integrating paypal express to laravel,
Paypal express integration

php soap client call magento soap v2 api web service login method fail with Error cannot find parameter

magento 1.6, php 5.3.8, windows 7, iis 7.5
follow the sample on mangento but can not get it work.
the old v1 api works though
last request is: string(233) " zzc000 "
last response is: string(294) " SOAP-ENV:ClientError cannot find parameter "
<?php
try{
$proxy = new SoapClient('http://127.0.0.1/Magento1620/index.php/api/v2_soap?wsdl=1', array('trace' => 1, 'connection_timeout' => 120));
$sessionId = $proxy->login("zzc000", "zzc000");
$filters = array(
'sku' => array('like'=>'zol%')
);
$products = $proxy->call($sessionId, 'product.list', array($filters));
var_dump($products);
/*
$proxy = new SoapClient('http://127.0.0.1:50594/webservice1.asmx?WSDL');
var_dump($proxy->HelloWorld());
*/
} catch (Exception $e) {
var_dump($proxy->__getLastRequest());
var_dump($proxy->__getLastResponse());
//echo 'Caught exception: ', $e->getMessage(), "\n";
//var_dump($e->getTraceAsString());
}
?>
please help
thanks
I put web service as WS-I compliant v2 API WSDL
is it going to affect anything?
after a bit research, now i can log in using the following code, but i can not retrieve the products
$sessionId = $proxy->login(array(
'username' => "zzc000",
'apiKey' => "zzc000"
));
but I got the following exception when try to list the products
SOAP-ERROR: Encoding: object has no 'sessionId' property
by using the following code
$filters = array(
'sku' => array('like'=>'zol%')
);
$products = $proxy->catalogProductList($sessionId, $filters);
if you use the v2_soap api, the function call is slightly different. Instead of call() you have to use the camel-cased api method. e.g.:
$products=$proxy->catalogProductInfo($sessionId,$sku);

Resources