本文整理汇总了PHP中Sylius\Component\Promotion\Model\PromotionInterface类的典型用法代码示例。如果您正苦于以下问题:PHP PromotionInterface类的具体用法?PHP PromotionInterface怎么用?PHP PromotionInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PromotionInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: revert
/**
* {@inheritdoc}
*/
public function revert(PromotionSubjectInterface $subject, PromotionInterface $promotion)
{
foreach ($promotion->getActions() as $action) {
$this->getActionCommandByType($action->getType())->revert($subject, $action->getConfiguration(), $promotion);
}
$subject->removePromotion($promotion);
}
示例2:
function it_decrements_promotion_usage_if_promotion_was_used(OrderInterface $order, PromotionInterface $promotion)
{
$order->getPromotions()->willReturn([$promotion]);
$promotion->getUsed()->willReturn(5);
$promotion->setUsed(4)->shouldBeCalled();
$this->decrementPromotionUsage($order);
}
示例3: getPromotionFieldsWithHeader
/**
* @param PromotionInterface $promotion
* @param string $header
*
* @return NodeElement
*/
private function getPromotionFieldsWithHeader(PromotionInterface $promotion, $header)
{
$tableAccessor = $this->getTableAccessor();
$table = $this->getElement('table');
$fields = $tableAccessor->getFieldFromRow($table, $tableAccessor->getRowWithFields($table, ['code' => $promotion->getCode()]), $header);
return $fields;
}
示例4: isEligible
/**
* {@inheritdoc}
*/
public function isEligible(PromotionSubjectInterface $promotionSubject, PromotionInterface $promotion)
{
if (!$promotion->isCouponBased()) {
throw new UnsupportedPromotionException('Only coupon based promotions can be evaluated by this checker.');
}
if (!$promotionSubject instanceof OrderInterface) {
return false;
}
$coupon = $promotionSubject->getPromotionCoupon();
if (!$coupon instanceof CouponInterface) {
return false;
}
if ($promotion !== $coupon->getPromotion()) {
return false;
}
$couponUsageLimit = $coupon->getPerCustomerUsageLimit();
if (0 === $couponUsageLimit) {
return true;
}
$customer = $promotionSubject->getCustomer();
if (null === $customer) {
return false;
}
$placedOrdersNumber = $this->orderRepository->countByCustomerAndCoupon($customer, $coupon);
// <= because we need to include the cart orders as well
return $placedOrdersNumber <= $couponUsageLimit;
}
示例5: createForPromotion
/**
* {@inheritdoc}
*/
public function createForPromotion(PromotionInterface $promotion)
{
Assert::true($promotion->isCouponBased(), sprintf('Promotion with name %s is not coupon based.', $promotion->getName()));
$coupon = $this->factory->createNew();
$coupon->setPromotion($promotion);
return $coupon;
}
示例6: createAdjustment
/**
* @param PromotionInterface $promotion
* @param string $type
*
* @return AdjustmentInterface
*/
protected function createAdjustment(PromotionInterface $promotion, $type = AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)
{
$adjustment = $this->adjustmentFactory->createNew();
$adjustment->setType($type);
$adjustment->setLabel($promotion->getName());
$this->originator->setOrigin($adjustment, $promotion);
return $adjustment;
}
示例7:
function it_creates_a_coupon_and_assigns_a_promotion_to_id(FactoryInterface $factory, PromotionInterface $promotion, PromotionCouponInterface $coupon)
{
$factory->createNew()->willReturn($coupon);
$promotion->getName()->willReturn('Christmas sale');
$promotion->isCouponBased()->willReturn(true);
$coupon->setPromotion($promotion)->shouldBeCalled();
$this->createForPromotion($promotion)->shouldReturn($coupon);
}
示例8: removeUnitOrderPromotionAdjustmentsByOrigin
/**
* @param OrderItemUnitInterface $unit
* @param PromotionInterface $promotion
*/
private function removeUnitOrderPromotionAdjustmentsByOrigin(OrderItemUnitInterface $unit, PromotionInterface $promotion)
{
foreach ($unit->getAdjustments(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT) as $adjustment) {
if ($promotion->getCode() === $adjustment->getOriginCode()) {
$unit->removeAdjustment($adjustment);
}
}
}
示例9:
function it_returns_false_if_subject_coupons_is_not_eligible(PromotionCouponEligibilityCheckerInterface $promotionCouponEligibilityChecker, PromotionCouponAwarePromotionSubjectInterface $promotionSubject, PromotionInterface $promotion, PromotionCouponInterface $promotionCoupon)
{
$promotion->isCouponBased()->willReturn(true);
$promotionSubject->getPromotionCoupon()->willReturn($promotionCoupon);
$promotionCoupon->getPromotion()->willReturn($promotion);
$promotionCouponEligibilityChecker->isEligible($promotionSubject, $promotionCoupon)->willReturn(false);
$this->isEligible($promotionSubject, $promotion)->shouldReturn(false);
}
示例10: createAdjustment
/**
* @param PromotionInterface $promotion
*
* @return AdjustmentInterface
*/
protected function createAdjustment(PromotionInterface $promotion)
{
$adjustment = $this->adjustmentFactory->createNew();
$adjustment->setType(AdjustmentInterface::PROMOTION_ADJUSTMENT);
$adjustment->setDescription($promotion->getDescription());
$this->originator->setOrigin($adjustment, $promotion);
return $adjustment;
}
示例11: createAdjustment
/**
* @param PromotionInterface $promotion
* @param string $type
*
* @return AdjustmentInterface
*/
protected function createAdjustment(PromotionInterface $promotion, $type = AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT)
{
/** @var AdjustmentInterface $adjustment */
$adjustment = $this->adjustmentFactory->createNew();
$adjustment->setType($type);
$adjustment->setLabel($promotion->getName());
$adjustment->setOriginCode($promotion->getCode());
return $adjustment;
}
示例12: isEligible
/**
* {@inheritdoc}
*/
public function isEligible(PromotionInterface $promotion)
{
if (null === ($usageLimit = $promotion->getUsageLimit())) {
return true;
}
if ($promotion->getUsed() < $usageLimit) {
return true;
}
return false;
}
示例13: execute
/**
* {@inheritdoc}
*/
public function execute(PromotionSubjectInterface $subject, array $configuration, PromotionInterface $promotion)
{
if (!$subject instanceof OrderInterface && !$subject instanceof OrderItemInterface) {
throw new UnexpectedTypeException($subject, 'Sylius\\Component\\Core\\Model\\OrderInterface or Sylius\\Component\\Core\\Model\\OrderItemInterface');
}
$adjustment = $this->repository->createNew();
$adjustment->setAmount(-$configuration['amount']);
$adjustment->setLabel(OrderInterface::PROMOTION_ADJUSTMENT);
$adjustment->setDescription($promotion->getDescription());
$subject->addAdjustment($adjustment);
}
示例14:
function it_reverts_all_actions_registered(ServiceRegistryInterface $registry, PromotionActionCommandInterface $action, PromotionSubjectInterface $subject, PromotionInterface $promotion, PromotionActionInterface $actionModel)
{
$configuration = [];
$registry->get('test_action')->willReturn($action);
$promotion->getActions()->willReturn([$actionModel]);
$actionModel->getType()->willReturn('test_action');
$actionModel->getConfiguration()->willReturn($configuration);
$action->revert($subject, $configuration, $promotion)->shouldBeCalled();
$subject->removePromotion($promotion)->shouldBeCalled();
$this->revert($subject, $promotion);
}
示例15: array
function it_applies_fixed_discount_as_promotion_adjustment($adjustmentRepository, OrderInterface $order, AdjustmentInterface $adjustment, PromotionInterface $promotion)
{
$adjustmentRepository->createNew()->willReturn($adjustment);
$promotion->getDescription()->willReturn('promotion description');
$adjustment->setAmount(-500)->shouldBeCalled();
$adjustment->setLabel(OrderInterface::PROMOTION_ADJUSTMENT)->shouldBeCalled();
$adjustment->setDescription('promotion description')->shouldBeCalled();
$order->addAdjustment($adjustment)->shouldBeCalled();
$configuration = array('amount' => 500);
$this->execute($order, $configuration, $promotion);
}