function let(Builder $queryBuilder, CatalogContext $context)
 {
     $context->getLocaleCode()->willReturn('en_US');
     $context->getScopeCode()->willReturn('mobile');
     $this->beConstructedWith($queryBuilder, $context);
     $queryBuilder->field(Argument::any())->willReturn($queryBuilder);
 }
 function let(QueryBuilder $qb, CatalogContext $context)
 {
     $context->getLocaleCode()->willReturn('en_US');
     $context->getScopeCode()->willReturn('mobile');
     $this->beConstructedWith($qb, $context);
     $qb->getRootAliases()->willReturn(array('p'));
 }
 function it_does_not_configure_scope_for_other_objects(CatalogContext $context, LifecycleEventArgs $args)
 {
     $object = new \stdClass();
     $args->getObject()->willReturn($object);
     $context->hasScopeCode()->willReturn(true);
     $context->getScopeCode()->shouldNotBeCalled();
     $this->postLoad($args);
 }
 /**
  * {@inheritdoc}
  */
 public function apply(FilterDatasourceAdapterInterface $ds, $data)
 {
     $channelCode = $this->parseData($data);
     if (!$channelCode) {
         $channelCode = $this->userContext->getUserChannelCode();
     }
     $this->catalogContext->setScopeCode($channelCode);
     return true;
 }
 /**
  * @return array
  */
 protected function prepareParameters()
 {
     $queryParameters = parent::prepareParameters();
     $dataLocale = $this->getLocale($queryParameters);
     $queryParameters['dataLocale'] = $dataLocale;
     $this->catalogContext->setLocaleCode($dataLocale);
     $dataScope = $this->getScope();
     $queryParameters['scopeCode'] = $dataScope;
     return $queryParameters;
 }
 /**
  * After load
  *
  * @param LifecycleEventArgs $args
  */
 public function postLoad(LifecycleEventArgs $args)
 {
     $object = $args->getObject();
     if (!$object instanceof ProductInterface) {
         return;
     }
     if ($this->context->hasScopeCode()) {
         $object->setScope($this->context->getScopeCode());
     }
 }
 /**
  * After load
  *
  * @param LifecycleEventArgs $args
  */
 public function postLoad(LifecycleEventArgs $args)
 {
     $object = $args->getObject();
     if (!$object instanceof ProductInterface && !$object instanceof AttributeOptionInterface) {
         return;
     }
     if ($this->context->hasLocaleCode()) {
         $object->setLocale($this->context->getLocaleCode());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function addFieldFilter($field, $operator, $value)
 {
     $field = sprintf("%s.%s.%s-%s", ProductQueryUtility::NORMALIZED_FIELD, 'completenesses', $this->context->getScopeCode(), $this->context->getLocaleCode());
     $value = intval($value);
     if ($operator === '=') {
         $this->qb->field($field)->equals($value);
     } else {
         $this->qb->field($field)->lt($value);
     }
     return $this;
 }
 /**
  * @return array
  */
 protected function prepareParameters()
 {
     $queryParameters = parent::prepareParameters();
     $dataLocale = $this->getLocale($queryParameters);
     $queryParameters['dataLocale'] = $dataLocale;
     // TODO : strange that we need to set it here, would expect from the datasource
     $this->catalogContext->setLocaleCode($dataLocale);
     $dataScope = $this->getScope();
     $queryParameters['scopeCode'] = $dataScope;
     return $queryParameters;
 }
 /**
  * Prepare join to attribute condition with current locale and scope criterias
  *
  * @param AbstractAttribute $attribute the attribute
  * @param string            $joinAlias the value join alias
  *
  * @return string
  */
 public function prepareCondition(AbstractAttribute $attribute, $joinAlias)
 {
     $condition = $joinAlias . '.attribute = ' . $attribute->getId();
     if ($attribute->isLocalizable()) {
         $condition .= ' AND ' . $joinAlias . '.locale = ' . $this->qb->expr()->literal($this->context->getLocaleCode());
     }
     if ($attribute->isScopable()) {
         $condition .= ' AND ' . $joinAlias . '.scope = ' . $this->qb->expr()->literal($this->context->getScopeCode());
     }
     return $condition;
 }
 /**
  * Prepare attributes list for CSV headers
  *
  * @param array $attributesList
  *
  * @return array
  */
 protected function prepareAttributesList(array $attributesList)
 {
     $scopeCode = $this->catalogContext->getScopeCode();
     $localeCodes = $this->localeManager->getActiveCodes();
     $fieldsList = array();
     foreach ($attributesList as $attribute) {
         $attCode = $attribute->getCode();
         if ($attribute->isLocalizable() && $attribute->isScopable()) {
             foreach ($localeCodes as $localeCode) {
                 $fieldsList[] = sprintf('%s-%s-%s', $attCode, $localeCode, $scopeCode);
             }
         } elseif ($attribute->isLocalizable()) {
             foreach ($localeCodes as $localeCode) {
                 $fieldsList[] = sprintf('%s-%s', $attCode, $localeCode);
             }
         } elseif ($attribute->isScopable()) {
             $fieldsList[] = sprintf('%s-%s', $attCode, $scopeCode);
         } elseif ($attribute->getAttributeType() === 'pim_catalog_identifier') {
             array_unshift($fieldsList, $attCode);
         } elseif ($attribute->getAttributeType() === 'pim_catalog_price_collection') {
             foreach ($this->currencyManager->getActiveCodes() as $currencyCode) {
                 $fieldsList[] = sprintf('%s-%s', $attCode, $currencyCode);
             }
         } else {
             $fieldsList[] = $attCode;
         }
     }
     return $fieldsList;
 }
 /**
  * Prepare attributes list for CSV headers
  *
  * @param array $attributesList
  *
  * @return array
  */
 protected function prepareAttributesList(array $attributesList)
 {
     $scopeCode = $this->catalogContext->getScopeCode();
     $localeCodes = $this->localeRepository->getActivatedLocaleCodes();
     $fieldsList = [];
     foreach ($attributesList as $attribute) {
         $attCode = $attribute->getCode();
         if ($attribute->isLocalizable() && $attribute->isScopable()) {
             foreach ($localeCodes as $localeCode) {
                 $fieldsList[] = sprintf('%s-%s-%s', $attCode, $localeCode, $scopeCode);
             }
         } elseif ($attribute->isLocalizable()) {
             foreach ($localeCodes as $localeCode) {
                 $fieldsList[] = sprintf('%s-%s', $attCode, $localeCode);
             }
         } elseif ($attribute->isScopable()) {
             $fieldsList[] = sprintf('%s-%s', $attCode, $scopeCode);
         } elseif (AttributeTypes::IDENTIFIER === $attribute->getAttributeType()) {
             array_unshift($fieldsList, $attCode);
         } elseif (AttributeTypes::PRICE_COLLECTION === $attribute->getAttributeType()) {
             foreach ($this->currencyManager->getActiveCodes() as $currencyCode) {
                 $fieldsList[] = sprintf('%s-%s', $attCode, $currencyCode);
             }
         } else {
             $fieldsList[] = $attCode;
         }
     }
     return $fieldsList;
 }
 /**
  * {@inheritdoc}
  */
 public function initialize()
 {
     $locale = $this->getLocale()->getCode();
     $this->catalogContext->setLocaleCode($locale);
     $this->allAttributes = null;
     $this->values = new ArrayCollection();
     $allAttributes = $this->getAllAttributes();
     $this->values = new ArrayCollection();
     foreach ($allAttributes as $attribute) {
         $this->addValues($attribute, $this->getLocale());
     }
 }
 /**
  * Initializes self::commonAtributes with values from the repository
  * Attribute is not available for mass editing if:
  *   - it is an identifier
  *   - it is unique
  *   - without value AND not link to family
  *   - is not common to every products
  *
  * @param array $productIds
  */
 protected function initializeCommonAttributes(array $productIds)
 {
     // Set attribute options locale
     $currentLocaleCode = $this->getLocale()->getCode();
     $this->catalogContext->setLocaleCode($currentLocaleCode);
     // Get common attributes
     $attributes = $this->massActionManager->findCommonAttributes($productIds);
     foreach ($attributes as $attribute) {
         $attribute->setLocale($currentLocaleCode);
         $attribute->getGroup()->setLocale($currentLocaleCode);
         $this->commonAttributes[] = $attribute;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function addFieldSorter($field, $direction)
 {
     $field = sprintf("%s.%s.label.%s", ProductQueryUtility::NORMALIZED_FIELD, $field, $this->context->getLocaleCode());
     $this->qb->sort($field, $direction);
     return $this;
 }
 /**
  * Normalize the field name from attribute and catalog context
  *
  * @param AbstractAttribute $attribute
  * @param CatalogContext    $context
  *
  * @return string
  */
 public static function getNormalizedValueFieldFromAttribute(AbstractAttribute $attribute, CatalogContext $context)
 {
     return self::getNormalizedValueField($attribute->getCode(), $attribute->isLocalizable(), $attribute->isScopable(), $attribute->isLocalizable() ? $context->getLocaleCode() : null, $attribute->isScopable() ? $context->getScopeCode() : null);
 }
 /**
  * {@inheritdoc}
  */
 protected function createFilename()
 {
     $dateTime = new \DateTime();
     return sprintf('products_export_%s_%s_%s.%s', $this->catalogContext->getLocaleCode(), $this->catalogContext->getScopeCode(), $dateTime->format('Y-m-d_H-i-s'), $this->getFormat());
 }
 /**
  * Define locale and scope in CatalogContext
  */
 protected function configureCatalogContext()
 {
     $this->catalogContext->setLocaleCode($this->userContext->getCurrentLocaleCode());
     $this->catalogContext->setScopeCode($this->userContext->getUserChannelCode());
 }
 function let(CatalogContext $context)
 {
     $context->getLocaleCode()->willReturn('en_US');
     $context->getScopeCode()->willReturn('mobile');
     $this->beConstructedWith($context);
 }