Ejemplo n.º 1
0
 public function testCreate()
 {
     $catalogPromotion = $this->dummyData->getCatalogPromotion();
     $catalogPromotion->setName('20% OFF Everything');
     $productQuantityDiscount1 = $this->dummyData->getProductQuantityDiscount();
     $productQuantityDiscount1->setType(PromotionType::exact());
     $productQuantityDiscount1->setQuantity(1);
     $productQuantityDiscount1->setValue(100);
     $product = $this->dummyData->getProduct();
     $product->setSku('sku1');
     $product->setName('Test Product');
     $productQuantityDiscount2 = $this->dummyData->getProductQuantityDiscount();
     $productQuantityDiscount2->setType(PromotionType::fixed());
     $productQuantityDiscount2->setQuantity(2);
     $productQuantityDiscount2->setValue(200);
     $price = $this->dummyData->getPrice();
     $price->addCatalogPromotion($catalogPromotion);
     $price->addProductQuantityDiscount($productQuantityDiscount1);
     $price->addProductQuantityDiscount($productQuantityDiscount2);
     $optionProduct = $this->dummyData->getOptionProduct();
     $optionProduct->getProduct()->setSku('OP1');
     $orderItemOptionProduct = $this->dummyData->getOrderItemOptionProduct($optionProduct);
     $optionValue = $this->dummyData->getOptionValue();
     $optionValue->setSku('OV1');
     $orderItemOptionValue = $this->dummyData->getOrderItemOptionValue($optionValue);
     $orderItemTextOptionValue = $this->dummyData->getOrderItemTextOptionValue();
     $order = $this->dummyData->getOrder();
     $orderItem = new OrderItem($order);
     $orderItem->setProduct($product);
     $orderItem->setQuantity(2);
     $orderItem->setPrice($price);
     $orderItem->addOrderItemOptionProduct($orderItemOptionProduct);
     $orderItem->addOrderItemOptionValue($orderItemOptionValue);
     $orderItem->addOrderItemTextOptionValue($orderItemTextOptionValue);
     $this->assertEntityValid($orderItem);
     $this->assertSame(2, $orderItem->getQuantity());
     $this->assertSame('sku1-OP1-OV1', $orderItem->getSku());
     $this->assertSame('Test Product', $orderItem->getName());
     $this->assertSame('20% OFF Everything, Buy 1 or more for $1.00 each, Buy 2 or more for $2.00 off', $orderItem->getDiscountNames());
     $this->assertSame($order, $orderItem->getOrder());
     $this->assertSame($product, $orderItem->getProduct());
     $this->assertSame($price, $orderItem->getPrice());
     $this->assertSame($orderItemOptionProduct, $orderItem->getOrderItemOptionProducts()[0]);
     $this->assertSame($orderItemOptionValue, $orderItem->getOrderItemOptionValues()[0]);
     $this->assertSame($orderItemTextOptionValue, $orderItem->getOrderItemTextOptionValues()[0]);
     $this->assertSame($catalogPromotion, $orderItem->getCatalogPromotions()[0]);
     $this->assertSame($productQuantityDiscount1, $orderItem->getProductQuantityDiscounts()[0]);
 }
Ejemplo n.º 2
0
 public function getOrderItem(Order $order, PricingInterface $pricing)
 {
     $orderItem = new OrderItem($order);
     $orderItem->setProduct($this->getProduct());
     $orderItem->setQuantity($this->getQuantity());
     $orderItem->setPrice($this->getPrice($pricing));
     foreach ($this->getCartItemOptionProducts() as $cartItemOptionProduct) {
         $orderItemOptionProduct = new OrderItemOptionProduct();
         $orderItemOptionProduct->setOptionProduct($cartItemOptionProduct->getOptionProduct());
         $orderItem->addOrderItemOptionProduct($orderItemOptionProduct);
     }
     foreach ($this->getCartItemOptionValues() as $cartItemTextOptionValue) {
         $orderItemOptionValue = new OrderItemOptionValue();
         $orderItemOptionValue->setOptionValue($cartItemTextOptionValue->getOptionValue());
         $orderItem->addOrderItemOptionValue($orderItemOptionValue);
     }
     foreach ($this->getCartItemTextOptionValues() as $cartItemTextOptionValue) {
         $orderItemTextOptionValue = new OrderItemTextOptionValue();
         $orderItemTextOptionValue->setTextOption($cartItemTextOptionValue->getTextOption());
         $orderItemTextOptionValue->setTextOptionValue($cartItemTextOptionValue->getTextOptionValue());
         $orderItem->addOrderItemTextOptionValue($orderItemTextOptionValue);
     }
     return $orderItem;
 }
Ejemplo n.º 3
0
 public function getOrderItemFull(Order $order)
 {
     if ($order === null) {
         $order = $this->getOrder();
     }
     $product = $this->getProduct();
     $product->enableAttachments();
     $orderItem = new OrderItem($order);
     $orderItem->setProduct($product);
     $orderItem->setQuantity(1);
     $orderItem->setPrice($this->getPriceFull());
     $orderItem->addOrderItemOptionProduct($this->getOrderItemOptionProduct());
     $orderItem->addOrderItemOptionValue($this->getOrderItemOptionValue());
     $orderItem->addOrderItemTextOptionValue($this->getOrderItemTextOptionValue());
     $orderItem->addAttachment($this->getAttachment());
     return $orderItem;
 }