Ejemplo n.º 1
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Payment handler of class Sonata\Component\Payment\PassPayment must return a code on getCode method. Please refer to the documentation (https://sonata-project.org/bundles/ecommerce/master/doc/reference/bundles/payment/index.html)
  */
 public function testAddMethodError()
 {
     $pool = new Pool();
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $payment = new PassPayment($router);
     $pool->addMethod($payment);
 }
Ejemplo n.º 2
0
 /**
  * Build a basket
  *
  * @param \Sonata\Component\Basket\BasketInterface $basket
  *
  * @throws \RuntimeException
  */
 public function build(BasketInterface $basket)
 {
     $basket->setProductPool($this->productPool);
     foreach ($basket->getBasketElements() as $basketElement) {
         if ($basketElement->getProduct() === null) {
             // restore information
             if ($basketElement->getProductCode() == null) {
                 throw new \RuntimeException('The product code is empty');
             }
             $productDefinition = $this->productPool->getProduct($basketElement->getProductCode());
             $basketElement->setProductDefinition($productDefinition);
         }
     }
     // load the delivery address
     $deliveryAddressId = $basket->getDeliveryAddressId();
     if ($deliveryAddressId) {
         $address = $this->addressManager->findOneBy(array('id' => $deliveryAddressId));
         $basket->setDeliveryAddress($address);
     }
     $deliveryMethodCode = $basket->getDeliveryMethodCode();
     if ($deliveryMethodCode) {
         $basket->setDeliveryMethod($this->deliveryPool->getMethod($deliveryMethodCode));
     }
     // load the payment address
     $billingAddressId = $basket->getBillingAddressId();
     if ($billingAddressId) {
         $address = $this->addressManager->findOneBy(array('id' => $billingAddressId));
         $basket->setBillingAddress($address);
     }
     // load the payment method
     $paymentMethodCode = $basket->getPaymentMethodCode();
     if ($paymentMethodCode) {
         $basket->setPaymentMethod($this->paymentPool->getMethod($paymentMethodCode));
     }
 }
Ejemplo n.º 3
0
 public function testPool()
 {
     $pool = new Pool();
     $router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface');
     $delivery = new PassPayment($router);
     $delivery->setCode('pass_1');
     $pool->addMethod($delivery);
     $delivery = new PassPayment($router);
     $delivery->setCode('pass_2');
     $pool->addMethod($delivery);
     $delivery = new PassPayment($router);
     $delivery->setCode('pass_2');
     // same code
     $pool->addMethod($delivery);
     $this->assertEquals(2, count($pool->getMethods()), 'Pool return 2 elements');
     $this->assertInstanceOf('Sonata\\Component\\Payment\\PassPayment', $pool->getMethod('pass_2'), 'Pool return an FreeDelivery Instance');
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function reverseTransform($value)
 {
     return $this->paymentPool->getMethod($value);
 }