当用户在购物车中添加一些产品时,产品将保存在实体命令中,其中将包含价格,数量,说明等。

s:10:"complement";s:9:"test test";}s:7:"priceHT";d:520;s:8:"priceTTC";d:624.25;s:5:"token";s:40:"50908802a1c1f0daf19e60277e336d6ab49142de";}


我想在实体突击队中获得PriceHT,因此我可以将其发送给Paypal。

我正在使用Payum(1.0.0)。

我有这个错误:


  尝试调用一个名为class的未定义方法“ getPriceTTC”
  “ FLY \ BookingsBundle \ Entity \ Commandes”。


这是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
}


这是我到目前为止所做的:

 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());
    }


加:

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;

    }

最佳答案

这就是我要做的以获取总金额和说明。

关于php - 获取数组[Symfony2-Payum]中的值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36645379/

10-09 19:42