Skip to content

Commit

Permalink
fix ajax
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivascu Madalin committed Oct 13, 2023
1 parent 8f5cff6 commit 9528566
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 152 deletions.
58 changes: 0 additions & 58 deletions Api/Data/PaypalExpress/OrderDataItemInterface.php

This file was deleted.

4 changes: 2 additions & 2 deletions Api/PaypalExpressQuoteCreateInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ interface PaypalExpressQuoteCreateInterface
*
* @param \Buckaroo\Magento2\Api\Data\PaypalExpress\ShippingAddressRequestInterface $shipping_address
* @param string $page
* @param \Buckaroo\Magento2\Api\Data\PaypalExpress\OrderDataItemInterface[]|null $order_data
* @param string|null $order_data
* @return \Buckaroo\Magento2\Api\Data\PaypalExpress\QuoteCreateResponseInterface
*/
public function execute(
ShippingAddressRequestInterface $shipping_address,
string $page,
$order_data = null
string $order_data = null
);
}
14 changes: 6 additions & 8 deletions Model/PaypalExpress/QuoteBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public function __construct(
$this->customer = $customer;
}

public function setFormData(array $formData)
/** @inheritDoc */
public function setFormData(string $formData)
{
$this->formData = $this->formatFormData($formData);
}
Expand Down Expand Up @@ -135,20 +136,17 @@ protected function addProduct()
throw new PaypalExpressException($exceptionMessage, 1);
}
}
/**
/**
* Format form data
*
* @param array $form_data
* @param string $form_data
*
* @return \Magento\Framework\DataObject
*/
protected function formatFormData(array $form_data)
protected function formatFormData(string $form_data)
{
$data = [];

foreach ($form_data as $orderKeyValue) {
$data[$orderKeyValue->getName()] = $orderKeyValue->getValue();
}
parse_str($form_data, $data);
$dataObject = $this->dataObjectFactory->create();

return $dataObject->setData($data);
Expand Down
4 changes: 2 additions & 2 deletions Model/PaypalExpress/QuoteBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ interface QuoteBuilderInterface
/**
* Set form data
*
* @param array $formData
* @param string $formData
*
* @return void
*/
public function setFormData(array $formData);
public function setFormData(string $formData);

/**
* Build quote from form data and session
Expand Down
16 changes: 4 additions & 12 deletions Model/PaypalExpress/QuoteCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,9 @@ public function __construct(
public function execute(
ShippingAddressRequestInterface $shipping_address,
string $page,
$form_data = null
string $form_data = null
) {

if ($page === 'product') {
$this->validateData($form_data);
if ($page === 'product' && is_string($form_data)) {
$this->quote = $this->createQuote($form_data);
} else {
$this->quote = $this->checkoutSession->getQuote();
Expand Down Expand Up @@ -267,12 +265,12 @@ protected function setPaymentMethod()
/**
* Create quote if in product page
*
* @param array $form_data
* @param string $form_data
* @param ShippingAddressRequestInterface $shipping_address
*
* @return Quote
*/
protected function createQuote(array $form_data)
protected function createQuote(string $form_data)
{
try {
$quoteBuilder = $this->quoteBuilderInterfaceFactory->create();
Expand All @@ -283,10 +281,4 @@ protected function createQuote(array $form_data)
throw new PaypalExpressException(__("Failed to create quote"), 1, $th);
}
}
protected function validateData($form_data)
{
if (!is_array($form_data)) {
throw new PaypalExpressException(__("Invalid order data"), 1);
}
}
}
69 changes: 0 additions & 69 deletions Model/PaypalExpress/Request/OrderDataItem.php

This file was deleted.

2 changes: 1 addition & 1 deletion view/frontend/web/js/view/checkout/paypal-express/pay.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ define([
getOrderData() {
let form = $("#product_addtocart_form");
if (this.page === 'product') {
return form.serializeArray();
return form.serialize();
}
},
/**
Expand Down

0 comments on commit 9528566

Please sign in to comment.