コード例 #1
0
 /**
  * Test getPurchasableName with a product
  */
 public function testGetPurchasableNameWithVariant()
 {
     $purchasableNameResolver = new PurchasableNameResolver();
     $product = $this->prophesize('Elcodi\\Component\\Product\\Entity\\Interfaces\\ProductInterface');
     $variant = $this->prophesize('Elcodi\\Component\\Product\\Entity\\Interfaces\\VariantInterface');
     $product->getName()->willReturn('Product Name');
     $variant->getProduct()->willReturn($product->reveal());
     $attribute1 = $this->prophesize('Elcodi\\Component\\Attribute\\Entity\\Interfaces\\AttributeInterface');
     $attribute1->getName()->willReturn('attribute1');
     $value1 = $this->prophesize('Elcodi\\Component\\Attribute\\Entity\\Interfaces\\ValueInterface');
     $value1->getAttribute()->willReturn($attribute1->reveal());
     $value1->getValue()->willReturn('value1');
     $attribute2 = $this->prophesize('Elcodi\\Component\\Attribute\\Entity\\Interfaces\\AttributeInterface');
     $attribute2->getName()->willReturn('attribute2');
     $value2 = $this->prophesize('Elcodi\\Component\\Attribute\\Entity\\Interfaces\\ValueInterface');
     $value2->getAttribute()->willReturn($attribute2->reveal());
     $value2->getValue()->willReturn('value2');
     $variant->getOptions()->willReturn(new ArrayCollection([$value1->reveal(), $value2->reveal()]));
     $this->assertEquals('Product Name - attribute1 value1 - attribute2 value2', $purchasableNameResolver->getPurchasableName($variant->reveal()));
     $this->assertEquals('Product Name # attribute1 value1 # attribute2 value2', $purchasableNameResolver->getPurchasableName($variant->reveal(), ' # '));
 }
コード例 #2
0
ファイル: PaymentBridge.php プロジェクト: pramoddas/bamboo
 /**
  * Get extra data
  *
  * Returns the order lines as array in the following form
  *
  * [
  *   1 => [ 'item' => 'Item 1', 'amount' => 1234, 'currency_code' => 'EUR ],
  *   2 => [ 'item_name' => 'Item 2', 'item_amount' => 2345, 'item_currency_code' => 'EUR ],
  * ]
  *
  * @return array
  */
 public function getExtraData()
 {
     $extraData = [];
     $orderDescription = [];
     if ($this->order instanceof Order) {
         $currency = $this->order->getAmount()->getCurrency();
         /**
          * @var OrderLine $orderLine
          *
          * Line prices must be converted to the currency
          * of the Cart when they are defined in another
          * currency
          */
         foreach ($this->order->getOrderLines() as $orderLine) {
             $orderLineArray = [];
             $purchasable = $orderLine->getPurchasable();
             $orderLineName = $this->purchasableNameResolver->getPurchasableName($purchasable);
             $orderLineArray['item_name'] = $orderLineName;
             $lineAmount = $orderLine->getProductAmount();
             /*
              * We need to convert any price to match
              * current order currency
              */
             $convertedAmount = $this->currencyConverter->convertMoney($lineAmount, $currency);
             $orderLineArray['amount'] = $convertedAmount->getAmount();
             /**
              * Line items currency should always match
              * the one from the order
              */
             $orderLineArray['item_currency_code'] = $this->getCurrency();
             $orderDescription[] = $orderLineName;
             $orderLineArray['quantity'] = $orderLine->getQuantity();
             $extraData['items'][$orderLine->getId()] = $orderLineArray;
         }
         // We add the shipping costs as a new "shadow" line in the extraData structure.
         $shippingAmount = $this->order->getShippingAmount();
         if ($shippingAmount->isGreaterThan(Money::create(0, $shippingAmount->getCurrency()))) {
             $extraData['items'][] = ['item_name' => 'shipping', 'item_currency_code' => $shippingAmount->getCurrency(), 'quantity' => 1, 'amount' => $shippingAmount->getAmount()];
         }
         // We add the coupon discounts as a new "shadow" line in the extraData structure.
         $couponAmount = $this->order->getCouponAmount();
         if ($couponAmount->isGreaterThan(Money::create(0, $couponAmount->getCurrency()))) {
             $extraData['discount_amount_cart'] = $couponAmount->getAmount();
         }
         $extraData['order_description'] = implode(" - ", $orderDescription);
     }
     return $extraData;
 }