protected function createRandomProduct(ObjectManager $manager) { $faker = $this->getFakerGenerator(); $sentence = $faker->unique()->sentence(3); $name = substr($sentence, 0, strlen($sentence) - 1); $shortDescription = $faker->text(100); $description = $faker->text(1000); $sku = $this->getFakerGenerator()->creditCardNumber(); $shop = $this->getReference('shop'); $currency = $this->randomizeSamples('currency', LoadCurrencyData::$samples); $producer = $this->randomizeSamples('producer', LoadProducerData::$samples); $availability = $this->randomizeSamples('availability', LoadAvailabilityData::$samples); $categories = $this->randomizeSamples('category', $s = LoadCategoryData::$samples, rand(2, 4)); $statuses = $this->randomizeSamples('product_status', LoadProductStatusData::$samples, rand(2, 3)); $tax = $this->randomizeSamples('tax', LoadTaxData::$samples); $unit = $this->randomizeSamples('unit', LoadUnitData::$samples); $dimension = new Dimension(); $dimension->setDepth(rand(10, 100)); $dimension->setHeight(rand(10, 100)); $dimension->setWidth(rand(10, 100)); $buyPrice = new Price(); $buyPrice->setGrossAmount(rand(50, 80)); $buyPrice->setCurrency($currency->getCode()); $sellPrice = new DiscountablePrice(); $sellPrice->setGrossAmount($price = rand(100, 200)); $sellPrice->setCurrency($currency->getCode()); foreach ($statuses as $status) { if ($status->translate()->getName() === 'Promotions') { $sellPrice->setDiscountedGrossAmount($price * (rand(80, 95) / 100)); $sellPrice->setValidFrom(new \DateTime()); $sellPrice->setValidTo((new \DateTime())->modify('+30 days')); } } $product = new Product(); $product->setSKU($sku); $product->setHierarchy(rand(0, 10)); $product->setEnabled(true); $product->setAvailability($availability); $product->setBuyPrice($buyPrice); $product->setBuyPriceTax($tax); $product->setSellPrice($sellPrice); $product->setSellPriceTax($tax); $product->setCategories($categories); $product->addShop($shop); $product->setStatuses($statuses); $product->translate('en')->setName($name); $product->translate('en')->setSlug(Sluggable::makeSlug($name)); $product->translate('en')->setShortDescription($shortDescription); $product->translate('en')->setDescription($description); $product->mergeNewTranslations(); $product->setProductPhotos($this->getPhotos($product, $manager)); $product->setProducer($producer); $product->setStock(rand(0, 1000)); $product->setUnit($unit); $product->setDimension($dimension); $product->setTrackStock(true); $product->setPackageSize(1); $product->setWeight(rand(0, 5)); $manager->persist($product); }
/** * {@inheritdoc} */ public function createFromCartProduct(CartProductInterface $cartProduct, OrderInterface $order) { $orderProduct = new OrderProduct(); $product = $cartProduct->getProduct(); $attribute = $cartProduct->getAttribute(); $sellPrice = $cartProduct->getSellPrice(); $baseCurrency = $sellPrice->getCurrency(); $targetCurrency = $order->getCurrency(); $grossAmount = $this->currencyHelper->convert($sellPrice->getFinalGrossAmount(), $baseCurrency, $targetCurrency); $netAmount = $this->currencyHelper->convert($sellPrice->getFinalNetAmount(), $baseCurrency, $targetCurrency); $taxAmount = $this->currencyHelper->convert($sellPrice->getFinalTaxAmount(), $baseCurrency, $targetCurrency); $sellPrice = new Price(); $sellPrice->setGrossAmount($grossAmount); $sellPrice->setNetAmount($netAmount); $sellPrice->setTaxAmount($taxAmount); $sellPrice->setTaxRate($sellPrice->getTaxRate()); $sellPrice->setCurrency($targetCurrency); $orderProduct->setSellPrice($sellPrice); $orderProduct->setBuyPrice($product->getBuyPrice()); $orderProduct->setQuantity($cartProduct->getQuantity()); $orderProduct->setWeight($cartProduct->getWeight()); $orderProduct->setProductAttribute($attribute); $orderProduct->setProduct($product); return $orderProduct; }
private function prepareCostsCollection(array $values, ShippingMethod $shippingMethod) { if (!isset($values['ranges'])) { throw new \InvalidArgumentException('Wrong arguments passed. Ranges are missing in the "costs" array.'); } $collection = new ArrayCollection(); foreach ($values['ranges'] as $value) { $cost = new Price(); $cost->setGrossAmount($value['price']); $range = new ShippingMethodCost(); $range->setCost($cost); $range->setRangeFrom($value['min']); $range->setRangeTo($value['max']); $range->setShippingMethod($shippingMethod); $collection->add($range); } return $collection; }
protected function getShippingCostsCollection(ShippingMethodInterface $shippingMethod) { $collection = new ArrayCollection(); $cost = new ShippingMethodCost(); $cost->setRangeFrom(0); $cost->setRangeTo(100000); $price = new Price(); $price->setCurrency('EUR'); $price->setNetAmount(10); $price->setTaxAmount(2.3); $price->setTaxRate(23); $price->setGrossAmount(12.3); $cost->setCost($price); $cost->setShippingMethod($shippingMethod); $collection->add($cost); return $collection; }
/** * {@inheritdoc} */ public function getShippingCostCurrency() { return $this->productTotal->getCurrency(); }
/** * Creates an instance of order product * * @param array $productValues * @param OrderInterface $order * * @return \WellCommerce\AppBundle\Entity\OrderProductInterface */ protected function createOrderProduct(array $productValues, OrderInterface $order) { $productId = (int) $productValues['product_id']; $product = $this->productRepository->find($productId); if (!$product instanceof ProductInterface) { throw new \InvalidArgumentException(sprintf('Cannot add product to order. ID "%s" does not exists.', $productId)); } $orderProduct = $this->factory->create(); $orderProduct->setBuyPrice($product->getBuyPrice()); $orderProduct->setOrder($order); $orderProduct->setProduct($product); $orderProduct->setProductAttribute(null); $orderProduct->setQuantity($productValues['quantity']); $orderProduct->setWeight($productValues['weight']); $sellPrice = new Price(); $grossAmount = $productValues['gross_amount']; $taxRate = $product->getSellPriceTax()->getValue(); $netAmount = TaxHelper::calculateNetPrice($grossAmount, $taxRate); $sellPrice->setTaxRate($taxRate); $sellPrice->setTaxAmount($grossAmount - $netAmount); $sellPrice->setNetAmount($netAmount); $sellPrice->setGrossAmount($grossAmount); $sellPrice->setCurrency($order->getCurrency()); $orderProduct->setSellPrice($sellPrice); return $orderProduct; }