douyan8070 2016-04-15 11:01
浏览 36

在Array中获取价值[Symfony2 - Payum]

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;

    }
  • 写回答

1条回答 默认 最新

  • dqtl46964 2016-04-16 16:41
    关注

    This is what i have done to get The totalAmount and 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());
            }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表