Sonata\Component\Delivery\Pool::getMethod PHP Method

getMethod() public method

return a ServiceDeliveryInterface Object.
public getMethod ( string $code ) : Sonata\Component\Delivery\ServiceDeliveryInterface
$code string
return Sonata\Component\Delivery\ServiceDeliveryInterface
    public function getMethod($code)
    {
        return isset($this->methods[$code]) ? $this->methods[$code] : null;
    }

Usage Example

Ejemplo n.º 1
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));
     }
 }
All Usage Examples Of Sonata\Component\Delivery\Pool::getMethod