When the user add some products in the cart, the products are save in the entity commande that will contain the price, quantity , description etc...
s:10:"complement";s:9:"test test";}s:7:"priceHT";d:520;s:8:"priceTTC";d:624.25;s:5:"token";s:40:"50908802a1c1f0daf19e60277e336d6ab49142de";}
I want to get PriceHT in the entity commande so i can send it to paypal.
I'm using Payum (1.0.0).
I have this error:
Attempted to call an undefined method named "getPriceTTC" of class "FLY\BookingsBundle\Entity\Commandes".
This is the result of dump($commande);
Commandes {#1175 ▼
-id: 87
-user: User {#922 ▶}
-confirm: false
-date: DateTime {#1173 ▶}
-reference: 0
-commande: array:6 [▼
"tva" => array:1 [▶]
"entity" => array:1 [▶]
"address" => array:8 [▶]
"priceHT" => 47.0
"priceTTC" => 56.42
"token" => "0a044567dfe10f5594e8a5f1a9a632a66fd30b01"
]
#number: null
#description: null
#clientEmail: null
#clientId: null
#totalAmount: null
#currencyCode: null
#details: []
#creditCard: null
}
This is what i have done so far:
public function validationCommandeAction($id)
{
$gatewayName = 'express_euro';
$storage = $this->get('payum')->getStorage('FLY\BookingsBundle\Entity\Commandes');
$em = $this->getDoctrine()->getManager();
$commande = $em->getRepository('FLYBookingsBundle:Commandes')->find($id);
if (!$commande || $commande->getConfirm() == 1)
throw $this->createNotFoundException('Your order doesn t exist');
$commande = $storage->create();
$commande->setUser($this->get('security.token_storage')->getToken()->getUser());
$commande->setDate(new \DateTime());
$commande->setCurrencyCode('EUR');
$commande->setClientId($this->getUser()->getId());
$commande->setClientEmail($this->getUser()->getEmail());
$commande->setTotalAmount($commande->getPriceTTC());
$commande->setConfirm(1);
$commande->setReference($this->container->get('setNewReference')->reference()); //Service
$storage->update($commande);
$em->flush();
$captureToken = $this->get('payum.security.token_factory')->createCaptureToken(
$gatewayName,
$commande,
'complete' // the route to redirect after capture;
);
return $this->redirect($captureToken->getTargetUrl());
}
ADD:
public function bill()
{
$em = $this->getDoctrine()->getManager();
$generator = $this->container->get('security.secure_random');
$session = $this->getRequest()->getSession();
$address = $session->get('address');
$cart = $session->get('cart');
$commande = array();
$totalHT = 0;
$totalTVA = 0;
$address = $em->getRepository('FLYBookingsBundle:Address')->find($address['address']);
$entities = $em->getRepository('FLYBookingsBundle:Post')->findArray(array_keys($session->get('cart')));
foreach ($entities as $entity) {
$priceHT = ($entity->getPrice() * $cart[$entity->getId()]);
$priceTTC = ($entity->getPrice() * $cart[$entity->getId()] / $entity->getTva()->getMultiplicate());
$totalHT += $priceHT;
if (!isset($commande['tva']['%' . $entity->getTva()->getValue()]))
$commande['tva']['%' . $entity->getTva()->getValue()] = round($priceTTC - $priceHT, 2);
else
$commande['tva']['%' . $entity->getTva()->getValue()] += round($priceTTC - $priceHT, 2);
$totalTVA += round($priceTTC - $priceHT, 2);
$commande['entity'][$entity->getId()] = array(
'from' => $entity->getAirport(),
'to' => $entity->getAirport1(),
'quantity' => $cart[$entity->getId()],
'priceHT' => round($entity->getPrice(), 2),
'priceTTC' => round($entity->getPrice() / $entity->getTva()->getMultiplicate(), 2));
}
$commande['address'] = array('surname' => $address->getSurname(),
'name' => $address->getName(),
'phone' => $address->getPhone(),
'address' => $address->getAddress(),
'zipcode' => $address->getZipcode(),
'city' => $address->getCity(),
'country' => $address->getCountry(),
'complement' => $address->getComplement());
$commande['priceHT'] = round($totalHT, 2);
$commande['priceTTC'] = round($totalHT + $totalTVA, 2);
$commande['token'] = bin2hex($generator->nextBytes(20));
return $commande;
}
答案 0 :(得分:0)
这是我为获得TotalAmount和description而做的。
public function validationCommandeAction($id)
{ $session = $this->getRequest()->getSession();
$gatewayName = 'express_euro';
$storage = $this->get('payum')->getStorage('FLY\BookingsBundle\Entity\Commandes');
$em = $this->getDoctrine()->getManager();
$commande = $em->getRepository('FLYBookingsBundle:Commandes')->find($id);
dump($commande);
if (!$commande || $commande->getConfirm() == 1)
throw $this->createNotFoundException('Your order doesn t exist');
$commande = $storage->create();
$commande->setUser($this->get('security.token_storage')->getToken()->getUser());
$commande->setDate(new \DateTime());
$commande->setCurrencyCode('EUR');
$commande->setClientId($this->getUser()->getId());
$commande->setClientEmail($this->getUser()->getEmail());
$commande->setNumber(uniqid());
$entities = $em->getRepository('FLYBookingsBundle:Post')->findArray(array_keys($session->get('cart')));
foreach ($entities as $entity) {
$commande->setTotalAmount($priceTTC = round($entity->getPrice() / $entity->getTva()->getMultiplicate()*100, 2));
$commande->setDescription($entity->getAirport());
}
$commande->setConfirm(1);
$commande->setReference($this->container->get('setNewReference')->reference()); //Service
$storage->update($commande);
$em->flush();
$captureToken = $this->get('payum.security.token_factory')->createCaptureToken(
$gatewayName,
$commande,
'complete' // the route to redirect after capture;
);
return $this->redirect($captureToken->getTargetUrl());
}