本文整理汇总了PHP中Elcodi\Component\Currency\Entity\Money类的典型用法代码示例。如果您正苦于以下问题:PHP Money类的具体用法?PHP Money怎么用?PHP Money使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Money类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* Validates the value to be greater or equal than the constraint value.
*
* @param Money $value Value
* @param Constraint $constraint Constraint
*
* @return null
*/
public function validate($value, Constraint $constraint)
{
if (null === $value) {
return null;
}
if (!$value instanceof Money) {
throw new UnexpectedTypeException($value, 'Elcodi\\Component\\Currency\\Entity\\Money');
}
$minimumMoney = Money::create($constraint->value, $value->getCurrency());
if ($value->isLessThan($minimumMoney)) {
$this->context->buildViolation($constraint->message)->setParameter('{{ value }}', $this->formatValue($value, self::OBJECT_TO_STRING))->setParameter('{{ compared_value }}', $this->formatValue($minimumMoney, self::OBJECT_TO_STRING))->setParameter('{{ compared_value_type }}', $this->formatTypeOf($minimumMoney))->addViolation();
}
}
示例2: load
/**
* Load data fixtures with the passed EntityManager
*
* @param ObjectManager $manager
*/
public function load(ObjectManager $manager)
{
/**
* Pack.
*
* @var CategoryInterface $menCategory
* @var ManufacturerInterface $manufacturer
* @var CurrencyInterface $currencyEur
* @var ObjectDirector $packDirector
* @var EntityTranslatorInterface $entityTranslator
*/
$menCategory = $this->getReference('category-men');
$manufacturer = $this->getReference('manufacturer-levis');
$currencyEur = $this->getReference('currency-EUR');
$packDirector = $this->getDirector('purchasable_pack');
$entityTranslator = $this->get('elcodi.entity_translator');
// Id assigned = 9
$pack4flavors = $packDirector->create()->setName('Pack 4 flavors')->setSlug('pack-4-flavors')->setDescription('Pack 4 flavors')->setShortDescription('Pack 4 flavors')->addCategory($menCategory)->setPrincipalCategory($menCategory)->setManufacturer($manufacturer)->addPurchasable($this->getReference('variant-ibiza-lips-white-small'))->addPurchasable($this->getReference('product-ibiza-banana'))->addPurchasable($this->getReference('product-i-was-there'))->addPurchasable($this->getReference('product-a-life-style'))->setStockType(ElcodiProductStock::INHERIT_STOCK)->setPrice(Money::create(3000, $currencyEur))->setSku('pack-sku-code-1')->setHeight(30)->setWidth(30)->setDepth(30)->setWeight(200)->setShowInHome(true)->setEnabled(true);
$packDirector->save($pack4flavors);
$this->addReference('pack-4-flavors', $pack4flavors);
$entityTranslator->save($pack4flavors, ['en' => ['name' => 'Pack 4 flavors English', 'slug' => 'pack-4-flavors-en', 'description' => 'Sed venenatis mauris eros, sit amet dapibus turpis consectetur et.
Etiam blandit erat libero. Integer a elit a tortor scelerisque
bibendum quis eget tortor. Donec vitae tempor tellus.', 'metaTitle' => 'Pack 4 flavors English', 'metaDescription' => 'Pack 4 flqueavors English', 'metaKeywords' => 'Pack 4 flavors English'], 'es' => ['name' => 'Pack 4 flavors Spanish', 'slug' => 'pack-4-flavors-es', 'description' => 'Sed venenatis mauris eros, sit amet dapibus turpis consectetur et.
Etiam blandit erat libero. Integer a elit a tortor scelerisque
bibendum quis eget tortor. Donec vitae tempor tellus.', 'metaTitle' => 'Pack 4 flavors Spanish', 'metaDescription' => 'Pack 4 flavors Spanish', 'metaKeywords' => 'Pack 4 flavors Spanish'], 'fr' => ['name' => 'Pack 4 flavors Français', 'slug' => 'pack-4-flavors-fr', 'description' => 'Sed venenatis mauris eros, sit amet dapibus turpis consectetur et.
Etiam blandit erat libero. Integer a elit a tortor scelerisque
bibendum quis eget tortor. Donec vitae tempor tellus.', 'metaTitle' => 'Pack 4 flavors Français', 'metaDescription' => 'Pack 4 flavors Français', 'metaKeywords' => 'Pack 4 flavors Français'], 'ca' => ['name' => 'Pack 4 flavors Català', 'slug' => 'pack-4-flavors-ca', 'description' => 'Sed venenatis mauris eros, sit amet dapibus turpis consectetur et.
Etiam blandit erat libero. Integer a elit a tortor scelerisque
bibendum quis eget tortor. Donec vitae tempor tellus.', 'metaTitle' => 'Pack 4 flavors Català', 'metaDescription' => 'Pack 4 flavors Català', 'metaKeywords' => 'Pack 4 flavors Català']]);
$this->storePurchasableImage($pack4flavors, 'pack-1.jpg');
$packDirector->save($pack4flavors);
}
示例3: load
/**
* {@inheritDoc}
*/
public function load(ObjectManager $manager)
{
/**
* @var ObjectDirector $carrierDirector
* @var EntityTranslatorInterface $entityTranslator
*/
$carrierDirector = $this->getDirector('carrier');
$entityTranslator = $this->get('elcodi.entity_translator');
$carrier = $carrierDirector->create()->setName('default')->setTax($this->getReference('tax-vat-21'))->setDescription('Default carrier')->setEnabled(true);
$this->setReference('carrier-default', $carrier);
$carrierDirector->save($carrier);
$entityTranslator->save($carrier, ['en' => ['name' => 'Basic', 'description' => 'Our basic delivery system'], 'es' => ['name' => 'Básico', 'description' => 'Nuestro sistema de entrega básico'], 'fr' => ['name' => 'Minimale', 'description' => 'Notre système de livraison basique'], 'ca' => ['name' => 'Bàsic', 'description' => 'El nostre sistema d\'entrega bàsic']]);
/**
* @var CurrencyInterface $currencyEuro
* @var ZoneInterface $zoneSpain
*/
$zoneSpain = $this->getReference('zone-spain');
$currencyEuro = $this->getReference('currency-EUR');
$shippingRangeDirector = $this->getDirector('shipping_range');
$shippingPriceRange1 = $shippingRangeDirector->create()->setType(ElcodiShippingRangeTypes::TYPE_PRICE)->setCarrier($carrier)->setName('From 0€ to 10€')->setFromZone($zoneSpain)->setToZone($zoneSpain)->setFromPrice(Money::create(0, $currencyEuro))->setToPrice(Money::create(1000, $currencyEuro))->setPrice(Money::create(900, $currencyEuro))->setEnabled(true);
$shippingPriceRange2 = $shippingRangeDirector->create()->setType(ElcodiShippingRangeTypes::TYPE_PRICE)->setCarrier($carrier)->setName('From 10€ to 20€')->setFromZone($zoneSpain)->setToZone($zoneSpain)->setFromPrice(Money::create(1000, $currencyEuro))->setToPrice(Money::create(2000, $currencyEuro))->setPrice(Money::create(500, $currencyEuro))->setEnabled(true);
$shippingPriceRange3 = $shippingRangeDirector->create()->setType(ElcodiShippingRangeTypes::TYPE_PRICE)->setCarrier($carrier)->setName('Free for up to 20€')->setFromZone($zoneSpain)->setToZone($zoneSpain)->setFromPrice(Money::create(2000, $currencyEuro))->setToPrice(Money::create(999999999, $currencyEuro))->setPrice(Money::create(115, $currencyEuro))->setEnabled(true);
$shippingRangeDirector->save($shippingPriceRange1);
$shippingRangeDirector->save($shippingPriceRange2);
$shippingRangeDirector->save($shippingPriceRange3);
}
示例4: validateNegativeAmount
/**
* When a cart goes below 0 (due to discounts), set the amount to 0.
*
* @param CartInterface $cart Cart
*/
public function validateNegativeAmount(CartInterface $cart)
{
$amount = $cart->getAmount();
if ($amount->getAmount() <= 0) {
$cart->setAmount(Money::create(0, $amount->getCurrency()));
}
}
示例5: load
/**
* Load data fixtures with the passed EntityManager.
*
* @param ObjectManager $manager
*/
public function load(ObjectManager $manager)
{
/**
* Pack.
*
* @var CategoryInterface $category
* @var ManufacturerInterface $manufacturer
* @var CurrencyInterface $currency
* @var ObjectDirector $packDirector
*/
$category = $this->getReference('category');
$manufacturer = $this->getReference('manufacturer');
$product = $this->getReference('product');
$productReduced = $this->getReference('product-reduced');
$variant = $this->getReference('variant-red-small');
$currency = $this->getReference('currency-dollar');
$packDirector = $this->getDirector('purchasable_pack');
// Id assigned = 9
$pack = $packDirector->create()->setName('pack')->setSlug('pack')->setDescription('my pack description')->setShortDescription('my pack short description')->addCategory($category)->setPrincipalCategory($category)->setManufacturer($manufacturer)->addPurchasable($product)->addPurchasable($productReduced)->addPurchasable($variant)->setStockType(ElcodiProductStock::SPECIFIC_STOCK)->setStock(10)->setPrice(Money::create(5000, $currency))->setSku('pack-sku-code-1')->setHeight(30)->setWidth(30)->setDepth(30)->setWeight(200)->setEnabled(true);
$packDirector->save($pack);
$this->addReference('pack', $pack);
// Id assigned = 10
$packInherit = $packDirector->create()->setName('pack-inherit')->setSlug('pack-inherit')->setDescription('my pack inherit description')->setShortDescription('my pack inherit short description')->addCategory($category)->setPrincipalCategory($category)->setManufacturer($manufacturer)->addPurchasable($product)->addPurchasable($productReduced)->addPurchasable($variant)->setStockType(ElcodiProductStock::INHERIT_STOCK)->setPrice(Money::create(5000, $currency))->setSku('pack-inherit-sku-code-1')->setHeight(30)->setWidth(30)->setDepth(30)->setWeight(200)->setEnabled(true);
$this->storeProductImage($packInherit, 'pack.jpg');
$packDirector->save($packInherit);
$this->addReference('pack-inherit', $packInherit);
}
示例6: getTestableFields
/**
* Return the fields to test in entities.
*
* [
* [[
* "type" => $this::GETTER_SETTER,
* "getter" => "getValue",
* "setter" => "setValue",
* "value" => "Elcodi\Component\...\Interfaces\AnInterface"
* "nullable" => true
* ]],
* [[
* "type" => $this::ADDER_REMOVER|$this::ADDER_REMOVER,
* "getter" => "getValue",
* "setter" => "setValue",
* "adder" => "addValue",
* "removed" => "removeValue",
* "bag" => "collection", // can be array
* "value" => "Elcodi\Component\...\Interfaces\AnInterface"
* ]]
* ]
*
* @return array Fields
*/
public function getTestableFields()
{
$currency = new Currency();
$currency->setIso('EUR');
$currency->setSymbol('€');
return [[['type' => $this::GETTER_SETTER, 'getter' => 'getCode', 'setter' => 'setCode', 'value' => 'discount', 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getName', 'setter' => 'setName', 'value' => 'Discount', 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getEnforcement', 'setter' => 'setEnforcement', 'value' => ElcodiCouponTypes::ENFORCEMENT_AUTOMATIC, 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getPrice', 'setter' => 'setPrice', 'value' => Money::create(1000, $currency), 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getDiscount', 'setter' => 'setDiscount', 'value' => 10, 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getAbsolutePrice', 'setter' => 'setAbsolutePrice', 'value' => Money::create(1000, $currency), 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getValue', 'setter' => 'setValue', 'value' => 'value', 'nullable' => true]], [['type' => $this::GETTER_SETTER, 'getter' => 'getCount', 'setter' => 'setCount', 'value' => 10, 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getUsed', 'setter' => 'setUsed', 'value' => 10, 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getPriority', 'setter' => 'setPriority', 'value' => 10, 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getMinimumPurchase', 'setter' => 'setMinimumPurchase', 'value' => Money::create(1000, $currency), 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getStackable', 'setter' => 'setStackable', 'value' => true, 'nullable' => false]], [['type' => $this::GETTER_SETTER, 'getter' => 'getRule', 'setter' => 'setRule', 'value' => new Rule(), 'nullable' => true]]];
}
示例7: createPurchasable
/**
* Creates, flushes and returns a Purchasable
*
* @return PurchasableInterface
*/
protected function createPurchasable()
{
/**
* @var CurrencyInterface $currency
*/
$currency = $this->getRepository('currency')->findOneBy(['iso' => 'USD']);
/**
* @var ValueInterface $variantOption
*/
$variantOption = $this->find('attribute_value', 1);
/**
* @var ProductInterface $product
*/
$product = $this->getFactory('product')->create()->setPrice(Money::create(1000, $currency))->setName('abc')->setSlug('abc')->setEnabled(true)->setWidth(10)->setHeight(10)->setDepth(10)->setWeight(10)->setStock(10);
/**
* @var VariantInterface $variant
*/
$variant = $this->getFactory('product_variant')->create()->setProduct($product)->setPrice(Money::create(1200, $currency))->addOption($variantOption)->setWidth(10)->setHeight(10)->setDepth(10)->setWeight(10)->setEnabled(true)->setStock(20);
$product->setPrincipalVariant($variant);
$this->getObjectManager('product')->persist($product);
$this->getObjectManager('product_variant')->persist($variant);
$this->getObjectManager('product')->flush();
$this->getObjectManager('product_variant')->flush();
$this->variant = $variant;
return $variant;
}
示例8: getCouponAbsoluteValue
/**
* Calculate coupon absolute value.
*
* @param CartInterface $cart Cart
* @param CouponInterface $coupon Coupon
*
* @return MoneyInterface|false Absolute value for this coupon in this cart
*/
public function getCouponAbsoluteValue(CartInterface $cart, CouponInterface $coupon)
{
$currency = $this->currencyWrapper->get();
$couponPrice = Money::create(0, $currency);
$value = $coupon->getValue();
preg_match($this->regexp(), $value, $match);
$m = (int) $match[1];
$n = (int) $match[2];
$expressionValue = isset($match[3]) ? $match[3] : '';
$modifiers = isset($match[4]) ? $match[4] : '';
$freePerGroup = $m - $n;
$freePerGroup = max($freePerGroup, 0);
foreach ($cart->getCartLines() as $cartLine) {
$moneys = [];
$purchasable = $cartLine->getPurchasable();
$expressionEvaluator = $this->getExpressionLanguageInstance();
$expressionResult = (empty($expressionValue) || $expressionEvaluator->evaluate($expressionValue, ['purchasable' => $purchasable])) && $this->evaluatePurchasableType($purchasable, $modifiers);
if (true === $expressionResult) {
$partialElements = $cartLine->getQuantity();
for ($i = 0; $i < $partialElements; ++$i) {
$partialPurchasable = $cartLine->getPurchasable();
$moneys[] = $partialPurchasable->getReducedPrice()->getAmount() > 0 ? $partialPurchasable->getReducedPrice() : $partialPurchasable->getPrice();
}
$groups = $partialElements / $m;
if ($groups > 0) {
$nbMoneys = $groups * $freePerGroup;
$moneysToDiscount = array_slice($moneys, 0, $nbMoneys);
foreach ($moneysToDiscount as $moneyToDiscount) {
$couponPrice = $couponPrice->add($this->currencyConverter->convertMoney($moneyToDiscount, $currency));
}
}
}
}
return $couponPrice;
}
示例9: limitCartAmount
/**
* When a cart goes below 0 (due to discounts), set the amount to 0.
*
* @param CartOnLoadEvent $event Event
*/
public function limitCartAmount(CartOnLoadEvent $event)
{
$cart = $event->getCart();
$amount = $cart->getAmount();
if ($amount->getAmount() <= 0) {
$cart->setAmount(Money::create(0, $amount->getCurrency()));
}
}
示例10: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
/**
* We set given Currency as default object to work with
*/
$money = Money::create(0, $this->currencyWrapper->getDefaultCurrency());
$resolver->setDefaults(array('data_class' => 'Elcodi\\Component\\Currency\\Entity\\Money', 'empty_data' => $money));
}
示例11: testCurrencyRateNotFoundThrowsException
/**
* @expectedException \Exception
*/
public function testCurrencyRateNotFoundThrowsException()
{
$localAdapter = $this->getMock('Elcodi\\Component\\Currency\\Adapter\\LocaleProvider\\Interfaces\\LocaleProviderAdapterInterface');
$localAdapter->expects($this->any())->method('getLocaleIso')->will($this->returnValue('es_ES'));
$priceExtension = new PrintMoneyExtension($this->getMock('Elcodi\\Component\\Currency\\Services\\CurrencyConverter', [], [], '', false), $this->getMock('Elcodi\\Component\\Currency\\Wrapper\\CurrencyWrapper', [], [], '', false), $localAdapter);
$currencyFactory = new CurrencyFactory();
$currencyFactory->setEntityNamespace('Elcodi\\Component\\Currency\\Entity\\Currency');
$priceExtension->printMoney(Money::create(1000, $currencyFactory->create()->setIso('US1')), 'US1');
}
示例12: testConvertMoney
/**
* Test convert money.
*
* @param $isoFrom
* @param $isoTo
* @param $amount
* @param $resultAmount
*
* @dataProvider dataConvertMoney
*/
public function testConvertMoney($isoFrom, $isoTo, $amount, $resultAmount)
{
$currencyFrom = $this->createCurrency($isoFrom);
$currencyTo = $this->createCurrency($isoTo);
$money = Money::create($amount, $currencyFrom);
$moneyResult = $this->currencyConverter->convertMoney($money, $currencyTo);
$this->assertEquals($moneyResult->getAmount(), $resultAmount);
$this->assertEquals($moneyResult->getCurrency(), $currencyTo);
}
示例13: testCurrencyRateNotFoundThrowsException
/**
* @expectedException \Exception
*/
public function testCurrencyRateNotFoundThrowsException()
{
$locale = $this->getMock('Elcodi\\Component\\Language\\Entity\\Interfaces\\LocaleInterface');
$locale->expects($this->any())->method('getIso')->willReturn('es_ES');
$priceExtension = new MoneyPrinter($this->getMock('Elcodi\\Component\\Currency\\Services\\CurrencyConverter', [], [], '', false), $this->getMock('Elcodi\\Component\\Currency\\Wrapper\\CurrencyWrapper', [], [], '', false), Locale::create($locale));
$currencyFactory = new CurrencyFactory();
$currencyFactory->setEntityNamespace('Elcodi\\Component\\Currency\\Entity\\Currency');
$currencyFactory->setDateTimeFactory(new DateTimeFactory());
$priceExtension->printMoney(Money::create(1000, $currencyFactory->create()->setIso('US1')), 'US1');
}
示例14: createPurchasable
/**
* Creates, flushes and returns a Purchasable.
*
* @return mixed
*/
protected function createPurchasable()
{
/**
* @var CurrencyInterface $currency
*/
$currency = $this->getRepository('currency')->findOneBy(['iso' => 'USD']);
$product = $this->get('elcodi.factory.product')->create()->setPrice(Money::create(1000, $currency))->setName('abc')->setSlug('abc')->setWidth(10)->setHeight(10)->setDepth(10)->setWeight(10)->setEnabled(true)->setStock(10);
$this->getObjectManager('product')->persist($product);
$this->getObjectManager('product')->flush();
return $product;
}
示例15: getCouponAbsoluteValue
/**
* Calculate coupon absolute value.
*
* @param CartInterface $cart Cart
* @param CouponInterface $coupon Coupon
*
* @return MoneyInterface Absolute value for this coupon in this cart
*/
public function getCouponAbsoluteValue(CartInterface $cart, CouponInterface $coupon)
{
$currency = $this->currencyWrapper->get();
$couponPrice = Money::create(0, $currency);
foreach ($this->cartCouponApplicators as $cartCouponApplicator) {
if ($cartCouponApplicator->canBeApplied($cart, $coupon)) {
return $cartCouponApplicator->getCouponAbsoluteValue($cart, $coupon);
}
}
return $couponPrice;
}