当前位置: 首页>>代码示例>>PHP>>正文


PHP RepositoryInterface::createNew方法代码示例

本文整理汇总了PHP中Sylius\Component\Resource\Repository\RepositoryInterface::createNew方法的典型用法代码示例。如果您正苦于以下问题:PHP RepositoryInterface::createNew方法的具体用法?PHP RepositoryInterface::createNew怎么用?PHP RepositoryInterface::createNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sylius\Component\Resource\Repository\RepositoryInterface的用法示例。


在下文中一共展示了RepositoryInterface::createNew方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generate

 /**
  * {@inheritdoc}
  */
 public function generate(VariableInterface $variable)
 {
     if (!$variable->hasOptions()) {
         throw new \InvalidArgumentException('Cannot generate variants for an object without options.');
     }
     $optionSet = array();
     $optionMap = array();
     foreach ($variable->getOptions() as $k => $option) {
         foreach ($option->getValues() as $value) {
             $optionSet[$k][] = $value->getId();
             $optionMap[$value->getId()] = $value;
         }
     }
     $permutations = $this->getPermutations($optionSet);
     foreach ($permutations as $permutation) {
         $variant = $this->variantRepository->createNew();
         $variant->setObject($variable);
         $variant->setDefaults($variable->getMasterVariant());
         if (is_array($permutation)) {
             foreach ($permutation as $id) {
                 $variant->addOption($optionMap[$id]);
             }
         } else {
             $variant->addOption($optionMap[$permutation]);
         }
         $variable->addVariant($variant);
         $this->process($variable, $variant);
     }
 }
开发者ID:bcremer,项目名称:Sylius,代码行数:32,代码来源:VariantGenerator.php

示例2: prepareAdjustmentForOrder

 /**
  * @param PaymentSubjectInterface $payment
  *
  * @return AdjustmentInterface
  */
 private function prepareAdjustmentForOrder(PaymentSubjectInterface $payment)
 {
     $adjustment = $this->adjustmentRepository->createNew();
     $adjustment->setLabel(AdjustmentInterface::PAYMENT_ADJUSTMENT);
     $adjustment->setAmount($this->feeCalculator->calculate($payment));
     $adjustment->setDescription($payment->getMethod()->getName());
     return $adjustment;
 }
开发者ID:nanyi,项目名称:Sylius,代码行数:13,代码来源:PaymentChargesProcessor.php

示例3: createPayment

 /**
  * {@inheritdoc}
  */
 public function createPayment(OrderInterface $order)
 {
     $payment = $this->paymentRepository->createNew();
     $payment->setCurrency($order->getCurrency());
     $payment->setAmount($order->getTotal());
     $order->addPayment($payment);
     return $payment;
 }
开发者ID:bcremer,项目名称:Sylius,代码行数:11,代码来源:PaymentProcessor.php

示例4: createPayment

 /**
  * {@inheritdoc}
  */
 public function createPayment(OrderInterface $order)
 {
     $this->updateExistingPaymentsStates($order);
     /** @var $payment PaymentInterface */
     $payment = $this->paymentRepository->createNew();
     $payment->setCurrency($order->getCurrency());
     $payment->setAmount($order->getTotal());
     $order->addPayment($payment);
     return $payment;
 }
开发者ID:nanyi,项目名称:Sylius,代码行数:13,代码来源:PaymentProcessor.php

示例5: createAndAssignAttributes

 /**
  * @param ArchetypeInterface        $archetype
  * @param AttributeSubjectInterface $subject
  */
 private function createAndAssignAttributes(ArchetypeInterface $archetype, AttributeSubjectInterface $subject)
 {
     foreach ($archetype->getAttributes() as $attribute) {
         if (null === $subject->getAttributeByName($attribute->getName())) {
             /** @var AttributeValueInterface $attributeValue */
             $attributeValue = $this->attributeValueRepository->createNew();
             $attributeValue->setAttribute($attribute);
             $subject->addAttribute($attributeValue);
         }
     }
 }
开发者ID:Strontium-90,项目名称:Sylius,代码行数:15,代码来源:ArchetypeBuilder.php

示例6: generate

 /**
  * {@inheritdoc}
  */
 public function generate(PromotionInterface $promotion, Instruction $instruction)
 {
     for ($i = 0, $amount = $instruction->getAmount(); $i < $amount; $i++) {
         $coupon = $this->repository->createNew();
         $coupon->setPromotion($promotion);
         $coupon->setCode($this->generateUniqueCode());
         $coupon->setUsageLimit($instruction->getUsageLimit());
         $this->manager->persist($coupon);
     }
     $this->manager->flush();
 }
开发者ID:Strontium-90,项目名称:Sylius,代码行数:14,代码来源:CouponGenerator.php

示例7: build

 /**
  * {@inheritdoc}
  */
 public function build(PrototypeInterface $prototype, ProductInterface $product)
 {
     foreach ($prototype->getAttributes() as $attribute) {
         $attributeValue = $this->attributeValueRepository->createNew();
         $attributeValue->setAttribute($attribute);
         $product->addAttribute($attributeValue);
     }
     foreach ($prototype->getOptions() as $option) {
         $product->addOption($option);
     }
 }
开发者ID:bcremer,项目名称:Sylius,代码行数:14,代码来源:PrototypeBuilder.php

示例8: 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);
 }
开发者ID:bcremer,项目名称:Sylius,代码行数:14,代码来源:FixedDiscountAction.php

示例9: createShipment

 /**
  * {@inheritdoc}
  */
 public function createShipment(OrderInterface $order)
 {
     $shipment = $order->getShipments()->first();
     if (!$shipment) {
         $shipment = $this->shipmentRepository->createNew();
         $order->addShipment($shipment);
     }
     foreach ($order->getInventoryUnits() as $inventoryUnit) {
         if (null === $inventoryUnit->getShipment()) {
             $shipment->addItem($inventoryUnit);
         }
     }
 }
开发者ID:bcremer,项目名称:Sylius,代码行数:16,代码来源:ShipmentFactory.php

示例10: applyShippingCharges

 /**
  * {@inheritdoc}
  */
 public function applyShippingCharges(OrderInterface $order)
 {
     // Remove all shipping adjustments, we recalculate everything from scratch.
     $order->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT);
     foreach ($order->getShipments() as $shipment) {
         $shippingCharge = $this->calculator->calculate($shipment);
         $adjustment = $this->adjustmentRepository->createNew();
         $adjustment->setLabel(AdjustmentInterface::SHIPPING_ADJUSTMENT);
         $adjustment->setAmount($shippingCharge);
         $adjustment->setDescription($shipment->getMethod()->getName());
         $order->addAdjustment($adjustment);
     }
     $order->calculateTotal();
 }
开发者ID:Strontium-90,项目名称:Sylius,代码行数:17,代码来源:ShippingChargesProcessor.php

示例11: create

 /**
  * {@inheritdoc}
  */
 public function create(StockableInterface $stockable, $quantity, $state = InventoryUnitInterface::STATE_SOLD)
 {
     if ($quantity < 1) {
         throw new \InvalidArgumentException('Quantity of units must be greater than 1.');
     }
     $units = new ArrayCollection();
     for ($i = 0; $i < $quantity; $i++) {
         $inventoryUnit = $this->repository->createNew();
         $inventoryUnit->setStockable($stockable);
         $inventoryUnit->setInventoryState($state);
         $units->add($inventoryUnit);
     }
     return $units;
 }
开发者ID:bcremer,项目名称:Sylius,代码行数:17,代码来源:InventoryUnitFactory.php

示例12: addAttribute

 /**
  * {@inheritdoc}
  */
 public function addAttribute($name, $value, $presentation = null)
 {
     $attribute = $this->attributeRepository->findOneBy(array('name' => $name));
     if (null === $attribute) {
         $attribute = $this->attributeRepository->createNew();
         $attribute->setName($name);
         $attribute->setPresentation($presentation ?: $name);
         $this->productManager->persist($attribute);
         $this->productManager->flush($attribute);
     }
     $attributeValue = $this->attributeValueRepository->createNew();
     $attributeValue->setAttribute($attribute);
     $attributeValue->setValue($value);
     $this->product->addAttribute($attributeValue);
     return $this;
 }
开发者ID:kongqingfu,项目名称:Sylius,代码行数:19,代码来源:ProductBuilder.php

示例13: createItem

 /**
  * Create promotion item
  *
  * @param array $configuration
  *
  * @return OrderItemInterface
  */
 protected function createItem(array $configuration)
 {
     $variant = $this->variantRepository->find($configuration['variant']);
     $promotionItem = $this->itemRepository->createNew();
     $promotionItem->setVariant($variant);
     $promotionItem->setQuantity((int) $configuration['quantity']);
     $promotionItem->setUnitPrice((int) $configuration['price']);
     return $promotionItem;
 }
开发者ID:kongqingfu,项目名称:Sylius,代码行数:16,代码来源:AddProductAction.php

示例14: updateOrCreate

 /**
  * @param CurrencyInterface[] $managedCurrencies
  * @param string              $code
  * @param float               $rate
  *
  * @return null|CurrencyInterface
  */
 protected function updateOrCreate(array $managedCurrencies, $code, $rate)
 {
     if (!empty($managedCurrencies) && in_array($code, $managedCurrencies)) {
         foreach ($managedCurrencies as $currency) {
             if ($code === $currency->getCode()) {
                 $currency->setExchangeRate($rate);
                 $this->manager->persist($currency);
                 return;
             }
         }
     } else {
         /** @var $currency CurrencyInterface */
         $currency = $this->repository->createNew();
         $currency->setCode($code);
         $currency->setExchangeRate($rate);
         $this->manager->persist($currency);
     }
 }
开发者ID:kongqingfu,项目名称:Sylius,代码行数:25,代码来源:AbstractImporter.php

示例15: getCart

 /**
  * {@inheritdoc}
  */
 public function getCart()
 {
     $this->initializeCart();
     if (null !== $this->cart) {
         return $this->cart;
     }
     $this->cart = $this->repository->createNew();
     $this->eventDispatcher->dispatch(SyliusCartEvents::CART_INITIALIZE, new CartEvent($this->cart));
     return $this->cart;
 }
开发者ID:bcremer,项目名称:Sylius,代码行数:13,代码来源:CartProvider.php


注:本文中的Sylius\Component\Resource\Repository\RepositoryInterface::createNew方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。