/** * Get action type * * @param ActionInterface $action * * @return null|string */ protected function getRegistryIdentifier($action) { if ($action instanceof ActionInterface && null !== $action->getType()) { return $action->getType(); } if (null !== $this->registryIdentifier) { return $this->registryIdentifier; } return null; }
function it_should_revert_all_actions_registered(ServiceRegistryInterface $registry, PromotionActionInterface $action, PromotionSubjectInterface $subject, PromotionInterface $promotion, ActionInterface $actionModel) { $configuration = []; $registry->get('test_action')->shouldBeCalled()->willReturn($action); $promotion->getActions()->shouldBeCalled()->willReturn([$actionModel]); $actionModel->getType()->shouldBeCalled()->willReturn('test_action'); $actionModel->getConfiguration()->shouldBeCalled()->willReturn($configuration); $action->revert($subject, $configuration, $promotion)->shouldBeCalled(); $subject->removePromotion($promotion)->shouldBeCalled(); $this->revert($subject, $promotion); }
function it_should_revert_all_actions_registered(ServiceRegistryInterface $registry, PromotionActionInterface $action, PromotionSubjectInterface $subject, PromotionInterface $promotion, ActionInterface $actionModel) { $configuration = array(); $registry->get(ActionInterface::TYPE_FIXED_DISCOUNT)->shouldBeCalled()->willReturn($action); $promotion->getActions()->shouldBeCalled()->willReturn(array($actionModel)); $actionModel->getType()->shouldBeCalled()->willReturn(ActionInterface::TYPE_FIXED_DISCOUNT); $actionModel->getConfiguration()->shouldBeCalled()->willReturn($configuration); $action->revert($subject, $configuration, $promotion)->shouldBeCalled(); $subject->removePromotion($promotion)->shouldBeCalled(); $this->revert($subject, $promotion); }
/** * {@inheritdoc} */ public function removeAction(ActionInterface $action) { $action->setPromotion(null); $this->actions->removeElement($action); return $this; }
/** * @param PromotionInterface $promotion * @param ActionInterface $action * @param array $configuration * @param RuleInterface|null $rule */ private function persistPromotion(PromotionInterface $promotion, ActionInterface $action, array $configuration, RuleInterface $rule = null) { $configuration = array_merge($configuration, $action->getConfiguration()); $action->setConfiguration($configuration); $promotion->addAction($action); if (null !== $rule) { $promotion->addRule($rule); } $this->objectManager->flush(); }
/** * @param PromotionInterface $promotion * @param ActionInterface $action * @param array $configuration */ private function persistPromotionWithAction(PromotionInterface $promotion, ActionInterface $action, array $configuration) { $configuration = array_merge($configuration, $action->getConfiguration()); $action->setConfiguration($configuration); $promotion->addAction($action); $this->objectManager->flush(); }