/** * @param CurrencyInterface $currency * @param string $field * @param mixed $data */ protected function setData(CurrencyInterface $currency, $field, $data) { if ('code' == $field) { $currency->setCode($data); } elseif ('activated' == $field) { $currency->setActivated($data); } }
function let(CurrencyRepositoryInterface $repository, CurrencyInterface $eur, CurrencyInterface $usd, CurrencyInterface $gbp) { $this->beConstructedWith($repository); $repository->findBy(array('activated' => true))->willReturn([$eur, $usd]); $repository->findBy(array())->willReturn([$eur, $usd, $gbp]); $repository->getActivatedCurrencyCodes()->willReturn(['EUR', 'USD']); $eur->getCode()->willReturn('EUR'); $usd->getCode()->willReturn('USD'); $gbp->getCode()->willReturn('GBP'); }
public function it_succesfully_checks_incomplete_price_collection(ProductValueInterface $value, ChannelInterface $channel, LocaleInterface $locale, ArrayCollection $arrayCollection, CurrencyInterface $currency1, CurrencyInterface $currency2, ProductPriceInterface $price1) { $channel->getCurrencies()->willReturn($arrayCollection); $arrayCollection->toArray()->willReturn([$currency1, $currency2]); $currency1->getCode()->willReturn('USD'); $price1->getCurrency()->willReturn('USD'); $price1->getData()->willReturn(null); $value->getData()->willReturn([$price1]); $this->isComplete($value, $channel, $locale)->shouldReturn(false); }
function it_normalizes_channel(ChannelInterface $channel, CategoryInterface $category, CurrencyInterface $currencyUSD, CurrencyInterface $currencyEUR) { $units = ['weight_attribute' => WeightFamilyInterface::GRAM, 'length_attribute' => LengthFamilyInterface::CENTIMETER]; $channel->getCode()->willReturn('my_code'); $channel->getLabel()->willReturn('my_label'); $channel->getCurrencies()->willReturn([$currencyEUR, $currencyUSD]); $channel->getLocaleCodes()->willReturn(['fr_FR', 'en_US', 'de_DE', 'es_ES']); $channel->getCategory()->willReturn($category); $channel->getConversionUnits()->willReturn($units); $category->getCode()->willReturn('winter'); $currencyEUR->getCode()->willReturn('EUR'); $currencyUSD->getCode()->willReturn('USD'); $this->normalize($channel, 'standard', [])->shouldReturn(['code' => 'my_code', 'label' => 'my_label', 'currencies' => ['EUR', 'USD'], 'locales' => ['fr_FR', 'en_US', 'de_DE', 'es_ES'], 'category_tree' => 'winter', 'conversion_units' => $units]); }
function it_normalizes_channel(ChannelInterface $channel, CurrencyInterface $eur, CurrencyInterface $usd, LocaleInterface $en, LocaleInterface $fr, CategoryInterface $category) { $channel->getCode()->willReturn('ecommerce'); $channel->getLabel()->willReturn('Ecommerce'); $channel->getCurrencies()->willReturn([$eur, $usd]); $eur->getCode()->willReturn('EUR'); $usd->getCode()->willReturn('USD'); $channel->getLocales()->willReturn([$en, $fr]); $en->getCode()->willReturn('en_US'); $fr->getCode()->willReturn('fr_FR'); $channel->getCategory()->willReturn($category); $category->getCode()->willReturn('Master catalog'); $channel->getConversionUnits()->willReturn(['Weight' => 'Kilogram', 'Size' => 'Centimeter']); $this->normalize($channel)->shouldReturn(['code' => 'ecommerce', 'label' => 'Ecommerce', 'currencies' => 'EUR,USD', 'locales' => 'en_US,fr_FR', 'category' => 'Master catalog', 'conversion_units' => 'Weight: Kilogram, Size: Centimeter']); }
function it_normalizes_channel(ChannelInterface $channel, CurrencyInterface $eur, CurrencyInterface $usd, LocaleInterface $en, LocaleInterface $fr, CategoryInterface $category, CategoryTranslationInterface $translation) { $channel->getCode()->willReturn('ecommerce'); $channel->getLabel()->willReturn('Ecommerce'); $channel->getCurrencies()->willReturn([$eur, $usd]); $eur->getCode()->willReturn('EUR'); $usd->getCode()->willReturn('USD'); $channel->getLocales()->willReturn([$en, $fr]); $en->getCode()->willReturn('en_US'); $fr->getCode()->willReturn('fr_FR'); $channel->getCategory()->willReturn($category); $category->getCode()->willReturn('master'); $category->getId()->willReturn(42); $translation->getLabel()->willReturn('label'); $translation->getLocale()->willReturn('en_US'); $category->getTranslations()->willReturn([$translation]); $channel->getConversionUnits()->willReturn(['Weight' => 'Kilogram', 'Size' => 'Centimeter']); $this->normalize($channel)->shouldReturn(['code' => 'ecommerce', 'label' => 'Ecommerce', 'currencies' => ['EUR', 'USD'], 'locales' => ['en_US', 'fr_FR'], 'category' => ['id' => 42, 'code' => 'master', 'labels' => ['en_US' => 'label']], 'conversion_units' => 'Weight: Kilogram, Size: Centimeter']); }
function it_generates_prices_indexes_when_saving_enabled_currency($collection, $namingUtility, CurrencyInterface $eur, AttributeInterface $price) { $eur->getCode()->willReturn('EUR'); $eur->isActivated()->willReturn(true); $price->getCode()->willReturn('price'); $price->getBackendType()->willReturn('prices'); $price->isLocalizable()->willReturn(false); $price->isScopable()->willReturn(false); $price->isUseableAsGridFilter()->willReturn(true); $price->getAttributeType()->willReturn('pim_catalog_price_collection'); $namingUtility->getPricesAttributes()->willReturn([$price]); $namingUtility->getCurrencyCodes()->willReturn(['EUR', 'USD']); $namingUtility->appendSuffixes(['normalizedData.price', 'normalizedData.price'], ['EUR', 'USD'], '.')->willReturn(['normalizedData.price.EUR', 'normalizedData.price.USD']); $namingUtility->appendSuffixes(['normalizedData.price.EUR', 'normalizedData.price.USD'], ['data'], '.')->willReturn(['normalizedData.price.EUR.data', 'normalizedData.price.USD.data']); $namingUtility->getAttributeNormFields($price)->willReturn(['normalizedData.price', 'normalizedData.price']); $indexes = array_fill(0, 10, 'fake_index'); $collection->getIndexInfo()->willReturn($indexes); $options = ['background' => true, 'w' => 0]; $collection->ensureIndex(['normalizedData.price.EUR.data' => 1], $options)->shouldBeCalled(); $collection->ensureIndex(['normalizedData.price.USD.data' => 1], $options)->shouldBeCalled(); $this->ensureIndexesFromCurrency($eur); }
function it_removes_obsolete_price_indexes_when_currency_is_disabled($collection, CurrencyInterface $usd) { $usd->getCode()->willReturn('USD'); $usd->isActivated()->willReturn(false); $collection->getIndexInfo()->willReturn([["key" => ["_id" => 1]], ["key" => ["normalizedData.title-ecommerce-en_US" => 1]], ["key" => ["normalizedData.title-ecommerce-de_DE" => 1]], ["key" => ["normalizedData.title-mobile-de_DE" => 1]], ["key" => ["normalizedData.manufacturer_title" => 1]], ["key" => ["normalizedData.title_left-en_US" => 1]], ["key" => ["normalizedData.title_left-de_DE" => 1]], ["key" => ["normalizedData.price-ecommerce.EUR.data" => 1]], ["key" => ["normalizedData.price-mobile.USD.data" => 1]], ["key" => ["normalizedData.name-mobile" => 1]], ["key" => ["normalizedData.name-ecommerce" => 1]], ["key" => ["normalizedData.mobile_support.id" => 1]], ["key" => ["normalizedData.cost-en_US.USD.data" => 1]], ["key" => ["normalizedData.color-ecommerce-en_US.id" => 1]]]); $collection->deleteIndex('normalizedData.price-mobile.USD.data')->shouldBeCalled(); $collection->deleteIndex('normalizedData.cost-en_US.USD.data')->shouldBeCalled(); $this->purgeIndexesFromCurrency($usd); }
/** * Remove indexes associated with the provided currency * * @param CurrencyInterface $currency */ public function purgeIndexesFromCurrency(CurrencyInterface $currency) { $currencyPattern = sprintf('/%s\\..+\\.%s\\.data/', ProductQueryUtility::NORMALIZED_FIELD, $currency->getCode()); $indexesToRemove = $this->getIndexesMatching($currencyPattern); $this->removeIndexes($indexesToRemove); }
function it_removes_indexes_for_currency_when_disabling_it($indexPurger, CurrencyInterface $usd, LifecycleEventArgs $args) { $usd->isActivated()->willReturn(false); $args->getEntity()->willReturn($usd); $indexPurger->purgeIndexesFromCurrency($usd)->shouldBeCalled(); $this->postUpdate($args); }
function it_updates_a_currency(CurrencyInterface $currency) { $currency->setCode('USD')->shouldBeCalled(); $currency->setActivated(true)->shouldBeCalled(); $this->update($currency, ['code' => 'USD', 'activated' => true], []); }
function it_normalizes_locales(CurrencyInterface $currency) { $currency->getCode()->willReturn('EUR'); $currency->isActivated()->willReturn(true); $this->normalize($currency, 'json')->shouldReturn(['code' => 'EUR', 'activated' => true]); }