protected function createVariationProduct() { $options = ['screwSize' => ['M6' => ['M6', 'M6'], 'M8' => ['M8', 'M8'], 'M10' => ['M10', 'M10'], 'M12' => ['M12', 'M12']], 'color' => ['black' => ['BK', 'Black'], 'blue' => ['BL', 'Blue'], 'gold' => ['GO', 'Gold'], 'green' => ['GR', 'Green'], 'red' => ['RD', 'Red']], 'material' => ['plastic' => ['Plastic', 'Plastic'], 'metal' => ['Metal', 'Metal']]]; $product = new Product(); foreach ($options as $type => $typeOptions) { foreach ($typeOptions as $index => $data) { $product->setOption($type, $index, $data[0], $data[1]); } } $data = [['M6' => ['material' => 'metal', 'color' => 'black']], ['M6' => ['material' => 'metal', 'color' => 'blue']], ['M6' => ['material' => 'metal', 'color' => 'green']], ['M10' => ['material' => 'metal', 'color' => 'black']], ['M10' => ['material' => 'metal', 'color' => 'gold']], ['M10' => ['material' => 'metal', 'color' => 'green']]]; foreach ($data as $options) { foreach ($options as $screwSize => $otherOptions) { $label = $screwSize; foreach ($otherOptions as $type => $name) { $label .= $name; } $variation = $product->useVariation($label); } foreach ($options as $screwSize => $otherOptions) { $variation->setOption('screwSize', $screwSize); foreach ($otherOptions as $type => $index) { $variation->setOption($type, $index); } } } }
protected function createRecurringOrder() { $order = new Order(); $customer = new Partner(); $order->setOwner($customer); $product1 = new Product(); $product1->setName('product1'); $context = new PricingContext(); $recurringElement = new RecurringElement(); $recurringElement->setCycles(-1); $recurringElement->setInterval('1 month'); $recurringElement->setRecurringCharge('30'); $pricingSet = new PricingSet(new TotalValueElement()); $pricingSet->addPricingElement($recurringElement); $pricingSet->setProcessingState(PricingSet::PROCESSING_FINISHED); $pricingSet1 = $pricingSet->process($context); $orderItem1 = new Item($product1); $rp = new \ReflectionProperty($orderItem1, 'pricingSet'); $rp->setAccessible(true); $rp->setValue($orderItem1, $pricingSet1); $rp->setAccessible(false); $rm = new \ReflectionMethod($order, 'addItem'); $rm->setAccessible(true); $rm->invokeArgs($order, array($orderItem1)); $rm->setAccessible(false); return $order; }
public function testBrandSpecification() { $this->dbSetUp(); $brand = new Brand(); $brand->setName('brand'); $this->brandGateway->persistBrand($brand); $newProduct = new Product(); $newProduct->addBrand($brand); $this->productGateway->persistProduct($newProduct); $this->productGateway->flush(); $spec = new ProductSpecification(); $spec->withBrand($brand); $product = $this->productGateway->findOne($spec); $this->assertEquals($newProduct, $product); }
public function testFindProductInOrder() { $mgr = $this->createOrderManager(); $order = $mgr->createOrder('test'); $createItem = new \ReflectionMethod($mgr, 'createItem'); $createItem->setAccessible(true); $addItem = new \ReflectionMethod($order, 'addItem'); $addItem->setAccessible(true); $product = new Product(); $product->setName('test product'); $testItem = $createItem->invokeArgs($mgr, array($product)); $addItem->invokeArgs($order, array($testItem)); $item = $mgr->findProductInOrder($order, $product); $this->assertSame($product, $item->getProduct(), 'find the item that contains the product'); $newProduct = new Product(); $newProduct->setName('with options'); $optionsBlue = array('color' => 'blue', 'size' => 'small'); $blueItem = $createItem->invokeArgs($mgr, array($newProduct, $optionsBlue)); $addItem->invokeArgs($order, array($blueItem)); $foundBlueItem = $mgr->findProductInOrder($order, $newProduct, $optionsBlue); $this->assertSame($newProduct, $foundBlueItem->getProduct(), 'find the item that contains the product with the options'); $this->assertSame($optionsBlue, $foundBlueItem->getOptions(), 'find the item that contains the product with the options'); $optionsRed = array('color' => 'red', 'size' => 'large'); $redItem = $createItem->invokeArgs($mgr, array($newProduct, $optionsRed)); $addItem->invokeArgs($order, array($redItem)); $foundRedItem = $mgr->findProductInOrder($order, $newProduct, array('size' => 'large', 'color' => 'red')); $this->assertNotSame($redItem, $blueItem); $this->assertSame($newProduct, $foundRedItem->getProduct(), 'find the item that contains the product with the options'); $this->assertSame($optionsRed, $foundRedItem->getOptions(), 'find the item that contains the product with the options'); $this->markTestIncomplete('this needed to be revisited'); $this->assertNull($mgr->findProductInOrder($order, $product, $optionsRed), "product and options don't match, nothing returned"); $this->assertNull($mgr->findProductInOrder($order, $newProduct), 'this item has options, so nothing returned'); $this->assertNull($mgr->findProductInOrder($order, $newProduct, array('color' => 'yellow')), 'no yellow options set'); }
public function testOptions() { $product = new Product(); $product->setOption('color', 'colorBlue', 'Blue', 'blue'); $product->setOption('color', 'colorGreen', 'Green', 'green'); $product->setOption('color', 'colorRed', 'Red', 'red'); $product->setOption('material', 'materialCotton', 'Cotton', 'cotton'); $product->setOption('material', 'materialSmall', 'Polyester', 'polyester'); $product->setOption('size', 'sizeLarge', 'Large', 'large'); $product->setOption('size', 'sizeSmall', 'Small', 'small'); $options = $product->getOptions(); $this->assertCount(7, $options, 'all product options should be returned'); $options = $product->getOptions('color'); $this->assertCount(3, $options, 'all product options of color type should be returned'); $this->assertInstanceOf('Vespolina\\Entity\\Product\\Option', array_shift($options), 'a Option object should be returned'); $blue = $product->getOption('color', 'colorBlue'); $this->assertInstanceOf('Vespolina\\Entity\\Product\\Option', $blue, 'the single option object should have been returned'); $options = $product->getOptionsArray(); $expected = ['color' => ['colorBlue' => 'Blue', 'colorGreen' => 'Green', 'colorRed' => 'Red'], 'material' => ['materialCotton' => 'Cotton', 'materialSmall' => 'Polyester'], 'size' => ['sizeLarge' => 'Large', 'sizeSmall' => 'Small']]; $this->assertEquals($expected, $options, 'all product options should be returned'); $options = $product->getOptionsArray('size'); $expected = ['sizeLarge' => 'Large', 'sizeSmall' => 'Small']; $this->assertEquals($expected, $options, 'all product options of size type should be returned'); $product->setOption('color', 'colorBlue', 'NewBlue', 'newblue'); $newBlue = $product->getOption('color', 'colorBlue'); $this->assertSame('NewBlue', $newBlue->getDisplay(), 'the display should have changed'); $this->assertSame('newblue', $newBlue->getName(), 'the display should have changed'); $this->assertSame(spl_object_hash($blue), spl_object_hash($newBlue), 'the object should be the same'); return $product; }