作者:jacko97
项目:pim-community-de
/**
* {@inheritdoc}
*/
public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
{
try {
$options = $this->resolver->resolve($options);
} catch (\Exception $e) {
throw InvalidArgumentException::expectedFromPreviousException($e, $attribute->getCode(), 'filter', 'options');
}
$this->checkLocaleAndScope($attribute, $locale, $scope, 'options');
if ($operator != Operators::IS_EMPTY) {
$this->checkValue($options['field'], $value);
}
$joinAlias = $this->getUniqueAlias('filter' . $attribute->getCode());
$joinAliasOpt = $this->getUniqueAlias('filterO' . $attribute->getCode());
$backendField = sprintf('%s.%s', $joinAliasOpt, 'id');
if (Operators::IS_EMPTY === $operator) {
$this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope));
$this->qb->leftJoin($joinAlias . '.' . $attribute->getBackendType(), $joinAliasOpt)->andWhere($this->qb->expr()->isNull($backendField));
} else {
if (FieldFilterHelper::getProperty($options['field']) === FieldFilterHelper::CODE_PROPERTY) {
$value = $this->objectIdResolver->getIdsFromCodes('option', $value);
}
$this->qb->innerJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope))->innerJoin($joinAlias . '.' . $attribute->getBackendType(), $joinAliasOpt, 'WITH', $this->qb->expr()->in($backendField, $value));
}
return $this;
}
作者:vpetrovyc
项目:pim-community-de
function it_throws_an_error_if_an_option_code_is_unknown_on_attribute_data_set($attrOptionRepository, ProductInterface $product, AttributeInterface $attribute)
{
$attribute->getCode()->willReturn('attributeCode');
$data = ['unknown code'];
$attrOptionRepository->findOneBy(['code' => 'unknown code', 'attribute' => $attribute])->shouldBeCalledTimes(1)->willReturn(null);
$this->shouldThrow(InvalidArgumentException::arrayInvalidKey('attributeCode', 'code', 'The option does not exist', 'adder', 'multi select', 'unknown code'))->during('addAttributeData', [$product, $attribute, $data, ['locale' => 'fr_FR', 'scope' => 'mobile']]);
}
作者:ashutosh-srija
项目:findit_akene
function it_throws_an_error_if_an_option_code_is_unknown($attrOptionRepository, AttributeInterface $attribute)
{
$attribute->getCode()->willReturn('attributeCode');
$data = ['unknown code'];
$attrOptionRepository->findOneBy(['code' => 'unknown code', 'attribute' => $attribute])->shouldBeCalledTimes(1)->willReturn(null);
$this->shouldThrow(InvalidArgumentException::arrayInvalidKey('attributeCode', 'code', 'The option does not exist', 'setter', 'multi select', 'unknown code'))->during('setValue', [[], $attribute, $data, 'fr_FR', 'mobile']);
}
作者:vpetrovyc
项目:pim-community-de
function it_fails_if_the_group_code_is_not_found($groupRepository, ProductInterface $product, GroupInterface $pack, GroupTypeInterface $nonVariantType)
{
$groupRepository->findOneByIdentifier('not valid code')->willReturn(null);
$pack->getType()->willReturn($nonVariantType);
$nonVariantType->isVariant()->willReturn(false);
$this->shouldThrow(InvalidArgumentException::expected('variant_group', 'existing variant group code', 'setter', 'variant_group', 'not valid code'))->during('setFieldData', [$product, 'variant_group', 'not valid code']);
}
作者:ashutosh-srija
项目:findit_akene
function it_throws_an_error_if_data_value_does_not_contain_valid_currency($currencyManager, AttributeInterface $attribute)
{
$attribute->getCode()->willReturn('attributeCode');
$currencyManager->getActiveCodes()->willReturn(['EUR', 'USD']);
$data = [['data' => 123, 'currency' => 'invalid currency']];
$this->shouldThrow(InvalidArgumentException::arrayInvalidKey('attributeCode', 'currency', 'The currency does not exist', 'setter', 'prices collection', 'invalid currency'))->during('setValue', [[], $attribute, $data, 'fr_FR', 'mobile']);
}
作者:ashutosh-srija
项目:findit_akene
/**
* {@inheritdoc}
*/
public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
{
try {
$options = $this->resolver->resolve($options);
} catch (\Exception $e) {
throw InvalidArgumentException::expectedFromPreviousException($e, $attribute->getCode(), 'filter', 'option');
}
$this->checkLocaleAndScope($attribute, $locale, $scope, 'option');
$field = $options['field'];
if (Operators::IS_EMPTY !== $operator) {
$this->checkValue($field, $value);
}
$joinAlias = $this->getUniqueAlias('filter' . $attribute->getCode(), true);
// prepare join value condition
$optionAlias = $joinAlias . '.option';
if (Operators::IS_EMPTY === $operator) {
$this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope));
$this->qb->andWhere($this->qb->expr()->isNull($optionAlias));
} else {
// inner join to value
$condition = $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope);
if (FieldFilterHelper::getProperty($field) === FieldFilterHelper::CODE_PROPERTY) {
$value = $this->objectIdResolver->getIdsFromCodes('option', $value);
}
$condition .= ' AND ( ' . $this->qb->expr()->in($optionAlias, $value) . ' ) ';
$this->qb->innerJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $condition);
}
return $this;
}
作者:ashutosh-srija
项目:findit_akene
function it_throws_an_exception_when_unit_families_are_not_consistent($attrValidatorHelper, AttributeInterface $fromAttribute, AttributeInterface $toAttribute)
{
$e = new \LogicException('Metric families are not the same for attributes: "fromCode" and "toCode".');
$fromAttribute->getCode()->willReturn('fromCode');
$toAttribute->getCode()->willReturn('toCode');
$attrValidatorHelper->validateUnitFamilies($fromAttribute, $toAttribute)->willThrow($e);
$this->shouldThrow(InvalidArgumentException::expectedFromPreviousException($e, 'fromCode && toCode', 'copier', 'concrete'))->during('testUnitFamily', [$fromAttribute, $toAttribute]);
}
作者:vpetrovyc
项目:pim-community-de
function it_throws_an_error_if_attribute_data_unit_does_not_exist(AttributeInterface $attribute, ProductInterface $product, $measureManager)
{
$attribute->getCode()->willReturn('attributeCode');
$attribute->getMetricFamily()->willReturn('Weight');
$data = ['data' => 42, 'unit' => 'incorrect unit'];
$measureManager->getUnitSymbolsForFamily('Weight')->shouldBeCalled()->willReturn(['KILOGRAM' => 'kg', 'GRAM' => 'g']);
$this->shouldThrow(InvalidArgumentException::arrayInvalidKey('attributeCode', 'unit', 'The unit does not exist', 'setter', 'metric', 'incorrect unit'))->during('setAttributeData', [$product, $attribute, $data, ['locale' => 'fr_FR', 'scope' => 'mobile']]);
}
作者:ashutosh-srija
项目:findit_akene
/**
* Check that unit families of 2 attributes are consistent.
*
* @param AttributeInterface $fromAttribute
* @param AttributeInterface $toAttribute
* @param string $type
*
* @throws \Pim\Bundle\CatalogBundle\Exception\InvalidArgumentException
*/
protected function checkUnitFamily(AttributeInterface $fromAttribute, AttributeInterface $toAttribute, $type)
{
try {
$this->attrValidatorHelper->validateUnitFamilies($fromAttribute, $toAttribute);
} catch (\LogicException $e) {
throw InvalidArgumentException::expectedFromPreviousException($e, $fromAttribute->getCode() . ' && ' . $toAttribute->getCode(), 'copier', $type);
}
}
作者:noglitchy
项目:pim-community-de
function it_fails_if_one_of_the_associated_group_does_not_exist($productBuilder, $groupRepository, ProductInterface $product, AssociationInterface $xsellAssociation)
{
$product->getAssociations()->willReturn([$xsellAssociation]);
$productBuilder->addMissingAssociations($product)->shouldBeCalled();
$product->getAssociationForTypeCode('xsell')->willReturn($xsellAssociation);
$groupRepository->findOneByIdentifier('not existing group')->willReturn(null);
$this->shouldThrow(InvalidArgumentException::expected('associations', 'existing group code', 'adder', 'association', 'not existing group'))->during('addFieldData', [$product, 'associations', ['xsell' => ['groups' => ['not existing group'], 'products' => []]]]);
}
作者:techpu
项目:EnhancedConnectorBundl
/**
* {@inheritdoc}
*/
protected function checkValue($field, $value, $locale, $scope)
{
if (!is_numeric($value)) {
throw InvalidArgumentException::numericExpected($field, 'filter', 'completeness', gettype($value));
}
if (null === $scope) {
throw new InvalidArgumentException('Scope expected for completeness filter. None given.');
}
}
作者:noglitchy
项目:pim-community-de
/**
* Check if value is valid
*
* @param string $field
* @param mixed $value
* @param string|null $locale
* @param string|null $scope
*/
protected function checkValue($field, $value, $locale, $scope)
{
if (!is_numeric($value)) {
throw InvalidArgumentException::numericExpected($field, 'filter', 'completeness', gettype($value));
}
if (null === $locale || null === $scope) {
throw InvalidArgumentException::localeAndScopeExpected($field, 'filter', 'completeness');
}
}
作者:qrz-i
项目:pim-community-de
/**
* Check locale and scope are valid
*
* @param AttributeInterface $attribute
* @param string $locale
* @param string $scope
* @param string $type
*
* @throws \Pim\Bundle\CatalogBundle\Exception\InvalidArgumentException
*/
protected function checkLocaleAndScope(AttributeInterface $attribute, $locale, $scope, $type)
{
try {
$this->attrValidatorHelper->validateLocale($attribute, $locale);
$this->attrValidatorHelper->validateScope($attribute, $scope);
} catch (\LogicException $e) {
throw InvalidArgumentException::expectedFromPreviousException($e, $attribute->getCode(), 'copier', $type);
}
}
作者:vpetrovyc
项目:pim-community-de
/**
* Check if data is valid
*
* @param AttributeInterface $attribute
* @param mixed $data
*/
protected function checkData(AttributeInterface $attribute, $data)
{
if (null === $data) {
return;
}
if (!is_string($data)) {
throw InvalidArgumentException::stringExpected($attribute->getCode(), 'setter', 'simple select', gettype($data));
}
}
作者:noglitchy
项目:pim-community-de
/**
* {@inheritdoc}
*/
public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
{
if (!is_bool($value)) {
throw InvalidArgumentException::booleanExpected($field, 'filter', 'boolean', gettype($value));
}
$field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, FieldFilterHelper::getCode($field));
$this->qb->field($field)->equals($value);
return $this;
}
作者:noglitchy
项目:pim-community-de
function it_fails_if_the_group_code_does_not_correspond_to_a_simple_group($groupRepository, ProductInterface $product, GroupInterface $pack, GroupInterface $variant, GroupTypeInterface $nonVariantType, GroupTypeInterface $variantType)
{
$groupRepository->findOneByIdentifier('pack')->willReturn($pack);
$pack->getType()->willReturn($nonVariantType);
$nonVariantType->isVariant()->willReturn(false);
$groupRepository->findOneByIdentifier('variant')->willReturn($variant);
$variant->getType()->willReturn($variantType);
$variantType->isVariant()->willReturn(true);
$this->shouldThrow(InvalidArgumentException::expected('groups', 'non variant group code', 'remover', 'groups', 'variant'))->during('removeFieldData', [$product, 'groups', ['pack', 'variant']]);
}
作者:ashutosh-srija
项目:findit_akene
/**
* {@inheritdoc}
*/
public function setValue(array $products, AttributeInterface $attribute, $data, $locale = null, $scope = null)
{
$this->checkLocaleAndScope($attribute, $locale, $scope, 'text');
if (null !== $data && !is_string($data)) {
throw InvalidArgumentException::stringExpected($attribute->getCode(), 'setter', 'text', gettype($data));
}
foreach ($products as $product) {
$this->setData($attribute, $product, $data, $locale, $scope);
}
}
作者:noglitchy
项目:pim-community-de
function it_throws_an_exception_when_scope_is_expected_but_not_existing($attrValidatorHelper, AttributeInterface $attribute)
{
$e = new \LogicException('Attribute "attributeCode" expects an existing scope, "ecommerce" given.');
$attribute->getCode()->willReturn('attributeCode');
$attribute->isLocalizable()->willReturn(false);
$attribute->isScopable()->willReturn(true);
$attrValidatorHelper->validateLocale($attribute, null)->shouldBeCalled();
$attrValidatorHelper->validateScope($attribute, 'ecommerce')->willThrow($e);
$this->shouldThrow(InvalidArgumentException::expectedFromPreviousException($e, 'attributeCode', 'setter', 'concrete'))->during('testLocaleAndScope', [$attribute, null, 'ecommerce']);
}
作者:noglitchy
项目:pim-community-de
/**
* {@inheritdoc}
*/
public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
{
if (!is_numeric($value) && !is_array($value)) {
throw InvalidArgumentException::expected($field, 'array or numeric value', 'filter', 'productId', $value);
}
$field = current($this->qb->getRootAliases()) . '.' . $field;
$condition = $this->prepareCriteriaCondition($field, $operator, $value);
$this->qb->andWhere($condition);
return $this;
}
作者:noglitchy
项目:pim-community-de
/**
* {@inheritdoc}
*/
public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
{
if (!is_bool($value)) {
throw InvalidArgumentException::booleanExpected($field, 'filter', 'boolean', gettype($value));
}
$field = current($this->qb->getRootAliases()) . '.' . FieldFilterHelper::getCode($field);
$condition = $this->prepareCriteriaCondition($field, $operator, $value);
$this->qb->andWhere($condition);
return $this;
}