Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax error or access violation #94

Open
Sorrow81 opened this issue Mar 9, 2019 · 0 comments
Open

Syntax error or access violation #94

Sorrow81 opened this issue Mar 9, 2019 · 0 comments

Comments

@Sorrow81
Copy link

Sorrow81 commented Mar 9, 2019

Hello,

I followed the documentation and during the test order/new/10.10, I have a SQL error that appears. I don't really understand, how can I define a PaymentInstruction?

An exception occurred while executing 'INSERT INTO order (amount, payment_instruction_id) VALUES (?, ?)' with params ["42.24", null]:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order (amount, payment_instruction_id) VALUES ('42.24', NULL)' at line 1
// src/App/Entity/Order.php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use JMS\Payment\CoreBundle\Entity\PaymentInstruction;

/**
 * @ORM\Entity(repositoryClass="App\Repository\OrderRepository")
 */
class Order
{
	/**
	 * @ORM\Column(name="id", type="integer")
	 * @ORM\Id
	 * @ORM\GeneratedValue(strategy="AUTO")
	 */
	private $id;

	/**
	 * @ORM\OneToOne(targetEntity="JMS\Payment\CoreBundle\Entity\PaymentInstruction")
	 */
	private $paymentInstruction;

	/**
	 * @ORM\Column(type="decimal", precision=10, scale=5)
	 */
	private $amount;

	public function __construct($amount)
	{
		$this->amount = $amount;
	}

	public function getId()
	{
		return $this->id;
	}

	public function getAmount()
	{
		return $this->amount;
	}

	public function getPaymentInstruction()
	{
		return $this->paymentInstruction;
	}

	public function setPaymentInstruction(PaymentInstruction $instruction): void
	{
		$this->paymentInstruction = $instruction;
	}
}
// src/App/Controller/OrdersController.php

namespace App\Controller;

use App\Entity\Order;
use JMS\Payment\CoreBundle\Form\ChoosePaymentMethodType;
use JMS\Payment\CoreBundle\PluginController\PluginController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

/**
 * @Route("/order")
 */
class OrderController extends AbstractController
{
	/**
	 * @Route("/new/{amount}", name="order.new")
	 * @param $amount
	 * @return \Symfony\Component\HttpFoundation\RedirectResponse
	 */
	public function newAction($amount): RedirectResponse
	{
		$em = $this->getDoctrine()->getManager();

		$order = new Order($amount);
		$em->persist($order);
		$em->flush();

		return $this->redirectToRoute('order.show', [
			'orderId' => $order->getId(),
		]);
	}

	/**
	 * @Route("/{orderId}/show", name="order.show")
	 * @param $orderId
	 * @param Request $request
	 * @param PluginController $ppc
	 * @return \Symfony\Component\HttpFoundation\Response
	 */
	public function showAction($orderId, Request $request, PluginController $ppc): Response
	{
		$order = $this->getDoctrine()->getManager()->getRepository(Order::class)->find($orderId);

		$form = $this->createForm(ChoosePaymentMethodType::class, null, [
			'amount'   => $order->getAmount(),
			'currency' => 'EUR',
		]);

		return $this->render('order/_order.html.twig', [
			'order' => $order,
			'form'  => $form->createView(),
		]);
	}
}

Can someone enlighten me? I don't understand why I don't have enough to make it work.

Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant