/** * {@inheritdoc} */ public function createByTaxonPaginator(TaxonInterface $taxon, array $criteria = []) { $root = $taxon->isRoot() ? $taxon : $taxon->getRoot(); $queryBuilder = $this->createQueryBuilder('o'); $queryBuilder->innerJoin('o.taxons', 'taxon')->andWhere($queryBuilder->expr()->eq('taxon.root', ':root'))->andWhere($queryBuilder->expr()->orX('taxon = :taxon', ':left < taxon.left AND taxon.right < :right'))->setParameter('root', $root)->setParameter('taxon', $taxon)->setParameter('left', $taxon->getLeft())->setParameter('right', $taxon->getRight()); $this->applyCriteria($queryBuilder, $criteria); return $this->getPaginator($queryBuilder); }
function it_transforms_taxons_collection_to_product_taxons_collection(ProductTaxonInterface $productTaxon, TaxonInterface $taxon, FactoryInterface $productTaxonFactory) { $productTaxons = new ArrayCollection([$productTaxon->getWrappedObject()]); $taxons = new ArrayCollection([$taxon->getWrappedObject()]); $productTaxonFactory->createNew()->willReturn($productTaxon); $productTaxon->setTaxon($taxon)->shouldBeCalled(); $this->reverseTransform($taxons)->shouldBeCollection($productTaxons); }
function it_recognizes_a_subject_as_not_eligible_if_a_product_taxon_is_not_matched(OrderInterface $subject, OrderItemInterface $item, ProductInterface $reflexBow, TaxonInterface $bows) { $configuration = ['taxons' => ['swords', 'axes']]; $bows->getCode()->willReturn('bows'); $reflexBow->getTaxons()->willReturn([$bows]); $item->getProduct()->willReturn($reflexBow); $subject->getItems()->willReturn([$item]); $this->isEligible($subject, $configuration)->shouldReturn(false); }
function it_filters_passed_order_items_with_given_configuration(OrderItemInterface $item1, OrderItemInterface $item2, ProductInterface $product1, ProductInterface $product2, TaxonInterface $taxon1, TaxonInterface $taxon2) { $item1->getProduct()->willReturn($product1); $product1->getTaxons()->willReturn([$taxon1]); $taxon1->getCode()->willReturn('taxon1'); $item2->getProduct()->willReturn($product2); $product2->getTaxons()->willReturn([$taxon2]); $taxon2->getCode()->willReturn('taxon2'); $this->filter([$item1, $item2], ['filters' => ['taxons' => ['taxon1']]])->shouldReturn([$item1]); }
/** * {@inheritdoc} */ public function selectMainTaxon(TaxonInterface $taxon) { $this->openTaxonBookmarks(); Assert::isInstanceOf($this->getDriver(), Selenium2Driver::class); $this->getDriver()->executeScript(sprintf('$(\'input.search\').val(\'%s\')', $taxon->getName())); $this->getElement('search')->click(); $this->getElement('search')->waitFor(10, function () { return $this->hasElement('search_item_selected'); }); $itemSelected = $this->getElement('search_item_selected'); $itemSelected->click(); }
/** * @param TaxonInterface $taxon */ private function uploadTaxonImages(TaxonInterface $taxon) { $images = $taxon->getImages(); foreach ($images as $image) { if ($image->hasFile()) { $this->uploader->upload($image); } // Upload failed? Let's remove that image. if (null === $image->getPath()) { $images->removeElement($image); } } }
function it_can_get_taxons_from_specific_taxonomy(TaxonInterface $taxon1, TaxonInterface $taxon2, TaxonInterface $taxon3, TaxonomyInterface $taxonomy1, TaxonomyInterface $taxonomy2) { $taxon1->getTaxonomy()->willReturn($taxonomy1); $taxon2->getTaxonomy()->willReturn($taxonomy1); $taxon3->getTaxonomy()->willReturn($taxonomy2); $taxonomy1->getName()->willReturn('Category'); $taxonomy2->getName()->willReturn('Brand'); $this->addTaxon($taxon1); $this->addTaxon($taxon2); $this->addTaxon($taxon3); $this->getTaxons('category')->shouldHaveCount(2); $this->getTaxons('brand')->shouldHaveCount(1); }
/** * @When /^I browse products from (taxon "([^"]+)")$/ */ public function iCheckListOfProductsForTaxon(TaxonInterface $taxon) { $this->taxonShowPage->open(['permalink' => $taxon->getPermalink()]); }
/** * @When /^I view (oldest|newest) products from (taxon "([^"]+)")$/ */ public function iViewSortedProductsFromTaxon($sortDirection, TaxonInterface $taxon) { $sorting = ['createdAt' => 'oldest' === $sortDirection ? 'asc' : 'desc']; $this->indexPage->open(['slug' => $taxon->getSlug(), 'sorting' => $sorting]); }
/** * @Then /^this taxon should (belongs to "[^"]+")$/ */ public function thisTaxonShouldBelongsTo(TaxonInterface $taxon) { Assert::true($this->updatePage->hasResourceValues(['parent' => $taxon->getId()]), sprintf('Current taxon should have %s parent taxon.', $taxon->getName())); }
/** * @Given /^([^"]+) gives ("[^"]+%") off on every product (classified as "[^"]+") and a ("(?:€|£|\$)[^"]+") discount to every order with items total equal at least ("(?:€|£|\$)[^"]+")$/ */ public function itGivesOffOnEveryProductClassifiedAsAndAFixedDiscountToEveryOrderWithItemsTotalEqualAtLeast(PromotionInterface $promotion, $taxonDiscount, TaxonInterface $taxon, $orderDiscount, $targetAmount) { $orderDiscountAction = $this->actionFactory->createFixedDiscount($orderDiscount); $promotion->addAction($orderDiscountAction); $rule = $this->ruleFactory->createItemTotal($targetAmount); $this->createUnitPercentagePromotion($promotion, $taxonDiscount, $this->getTaxonFilterConfiguration([$taxon->getCode()]), $rule); }
function it_creates_a_fixed_discount_promotion_which_contains_a_taxon_rule(ActionFactoryInterface $actionFactory, ActionInterface $action, ObjectManager $objectManager, PromotionInterface $promotion, RuleFactoryInterface $ruleFactory, RuleInterface $rule, TaxonInterface $tanks) { $tanks->getCode()->willReturn('tanks'); $ruleFactory->createContainsTaxon('tanks', 10)->willReturn($rule); $actionFactory->createFixedDiscount(500)->willReturn($action); $action->getConfiguration()->willReturn([]); $action->setConfiguration([])->shouldBeCalled(); $promotion->addAction($action)->shouldBeCalled(); $promotion->addRule($rule)->shouldBeCalled(); $objectManager->flush()->shouldBeCalled(); $this->thePromotionGivesOffIfOrderContainsNumberOfProductsClassifiedAs($promotion, 500, 10, $tanks); }
/** * {@inheritdoc} */ public function chooseParent(TaxonInterface $taxon) { $this->getElement('parent')->selectOption($taxon->getName(), false); }
/** * @Given /^the ("[^"]+" taxon) has(?:| also) an image "([^"]+)" with a code "([^"]+)"$/ */ public function theTaxonHasAnImageWithACode(TaxonInterface $taxon, $imagePath, $imageCode) { $filesPath = $this->getParameter('files_path'); $taxonImage = $this->taxonImageFactory->createNew(); $taxonImage->setFile(new UploadedFile($filesPath . $imagePath, basename($imagePath))); $taxonImage->setCode($imageCode); $this->imageUploader->upload($taxonImage); $taxon->addImage($taxonImage); $this->objectManager->flush($taxon); }
function it_creates_item_percentage_discount_action_for_promotion_products_with_specific_taxon(ActionFactoryInterface $actionFactory, ActionInterface $action, ObjectManager $objectManager, PromotionInterface $promotion, TaxonInterface $taxon) { $taxon->getCode()->willReturn('scottish_kilts'); $actionFactory->createItemPercentageDiscount(0.1)->willReturn($action); $action->getConfiguration()->willReturn(['percentage' => 0.1]); $action->setConfiguration(['percentage' => 0.1, 'filters' => ['taxons' => ['scottish_kilts']]])->shouldBeCalled(); $promotion->addAction($action)->shouldBeCalled(); $objectManager->flush()->shouldBeCalled(); $this->itGivesPercentageOffEveryProductClassifiedAs($promotion, 0.1, $taxon); }
/** * @Then the first taxon on the list should be :taxon */ public function theFirstTaxonOnTheListShouldBe(TaxonInterface $taxon) { Assert::same($this->createPage->getFirstLeafName(), $taxon->getName(), sprintf('Expected %s as a first taxon, but got %s.', $taxon->getName(), $this->createPage->getFirstLeafName())); }
function it_throws_exception_while_reverse_transform_if_taxons_element_is_not_an_array(TaxonInterface $axes) { $this->shouldThrow(new \InvalidArgumentException('"taxons" element of collection should be Traversable'))->during('reverseTransform', [new ArrayCollection(['taxons' => $axes->getWrappedObject()])]); }
function it_reverse_transforms_into_array_of_taxons_codes(TaxonInterface $axes, TaxonInterface $shields) { $axes->getCode()->willReturn('axes'); $shields->getCode()->willReturn('shields'); $this->reverseTransform(new ArrayCollection([$axes->getWrappedObject(), $shields->getWrappedObject()]))->shouldReturn(['axes', 'shields']); }
/** * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off on every product (classified as "[^"]+")$/ */ public function itGivesFixedOffEveryProductClassifiedAs(PromotionInterface $promotion, $discount, TaxonInterface $taxon) { $action = $this->actionFactory->createItemFixedDiscount($discount); $promotion->addAction($this->configureActionTaxonFilter($action, [$taxon->getCode()])); $this->objectManager->flush(); }
/** * @param TaxonInterface $taxon * @param string $direction * * @throws ElementNotFoundException */ private function moveLeaf(TaxonInterface $taxon, $direction) { Assert::oneOf($direction, [self::MOVE_DIRECTION_UP, self::MOVE_DIRECTION_DOWN]); $leaves = $this->getLeaves(); foreach ($leaves as $leaf) { if ($leaf->getText() === $taxon->getName()) { $moveButton = $leaf->getParent()->find('css', sprintf('.sylius-taxon-move-%s', $direction)); $moveButton->click(); $moveButton->waitFor(5, function () use($moveButton) { return $this->isOpen() && !$moveButton->hasClass('loading'); }); return; } } throw new ElementNotFoundException($this->getDriver(), sprintf('Move %s button for %s taxon', $direction, $taxon->getName())); }
/** * @Given /^([^"]+) gives ("(?:€|£|\$)[^"]+") off if order contains (\d+) products (classified as "[^"]+")$/ */ public function thePromotionGivesOffIfOrderContainsNumberOfProductsClassifiedAs(PromotionInterface $promotion, $discount, $count, TaxonInterface $taxon) { $rule = $this->ruleFactory->createContainsTaxon($taxon->getCode(), $count); $this->createFixedPromotion($promotion, $discount, [], $rule); }