本文整理汇总了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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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();
}
示例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);
}
}
示例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);
}
示例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);
}
}
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}