protected function checkEan(Product $product, $colorAttributeId, $sizeAttributeId) { $isCombination = false; $defaultPse = $product->getDefaultSaleElements(); $combinationAttribute = $colorAttributeId . ',' . $sizeAttributeId; if (null !== $combinationAttribute) { $combination = AttributeAvQuery::create()->useAttributeCombinationQuery()->filterByAttributeId(explode(',', $combinationAttribute), Criteria::IN)->filterByProductSaleElementsId($defaultPse->getId())->endUse()->findOne(); if (null !== $combination) { $isCombination = true; } } if (false === $isCombination) { if (null === $defaultPse->getEanCode()) { return false; } } else { $productSaleElementss = $product->getProductSaleElementss(); foreach ($productSaleElementss as $productSaleElements) { if (null === $productSaleElements->getEanCode()) { return false; } } } return true; }
/** * @depends testRemoveAccessory */ public function testSetProductTemplate(ProductModel $product) { $templateId = TemplateQuery::create()->select('id')->addAscendingOrderByColumn('RAND()')->findOne(); $currencyId = CurrencyQuery::create()->select('id')->addAscendingOrderByColumn('RAND()')->findOne(); $oldProductSaleElements = $product->getDefaultSaleElements(); $this->assertEquals("Thelia\\Model\\ProductSaleElements", get_class($oldProductSaleElements), "There is no default pse for this product"); $event = new ProductSetTemplateEvent($product, $templateId, $currencyId); $event->setDispatcher($this->getDispatcher()); $action = new Product(); $action->setProductTemplate($event); $updatedProduct = $event->getProduct(); $this->assertEquals($templateId, $updatedProduct->getTemplateId()); $productSaleElements = $updatedProduct->getProductSaleElementss(); $this->assertEquals(1, count($productSaleElements), "after setting a new template, only 1 product_sale_elements must be present"); /** @var \Thelia\Model\ProductSaleElements $newProductSaleElements */ $newProductSaleElements = $productSaleElements->getFirst(); $this->assertEquals($updatedProduct->getRef(), $newProductSaleElements->getRef(), sprintf("PSE ref must be %s", $updatedProduct->getRef())); $this->assertTrue($newProductSaleElements->getIsDefault(), 'new PSE must be the default one for this product'); $productPrice = $newProductSaleElements->getProductPrices()->getFirst(); $oldProductPrice = $oldProductSaleElements->getProductPrices()->getFirst(); $this->assertEquals($oldProductSaleElements->getWeight(), $newProductSaleElements->getWeight(), sprintf("->testSetProductTemplate new PSE weight must be %s", $oldProductSaleElements->getWeight())); $this->assertEquals($oldProductPrice->getPrice(), $productPrice->getPrice(), sprintf("->testSetProductTemplate price must be %s", $oldProductPrice->getPrice())); $this->assertEquals($oldProductPrice->getPromoPrice(), $productPrice->getPromoPrice(), sprintf("->testSetProductTemplate promo price must be %s", $oldProductPrice->getPromoPrice())); $this->assertEquals($oldProductPrice->getCurrencyId(), $productPrice->getCurrencyId(), sprintf("->testSetProductTemplate currency_id must be %s", $oldProductPrice->getCurrencyId())); return $updatedProduct; }
/** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ protected function tearDown() { $this->freeProduct->getDefaultSaleElements()->setPromo($this->originalPromo)->save(); }