コード例 #1
0
 function it_normalizes_product(SerializerInterface $serializer, ProductInterface $product, FamilyInterface $family, Completeness $completeness)
 {
     $serializer->implement('Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface');
     $this->setSerializer($serializer);
     $product->getFamily()->willReturn($family);
     $product->getGroups()->willReturn([]);
     $product->getValues()->willReturn([]);
     $product->getCompletenesses()->willReturn([$completeness]);
     $product->getCreated()->willReturn(null);
     $product->getUpdated()->willReturn(null);
     $product->isEnabled()->willReturn(true);
     $serializer->normalize($family, 'mongodb_json', [])->willReturn('family normalization');
     $serializer->normalize($completeness, 'mongodb_json', [])->willReturn(['completenessCode' => 'completeness normalization']);
     $this->normalize($product, 'mongodb_json', [])->shouldReturn([ProductNormalizer::FAMILY_FIELD => 'family normalization', ProductNormalizer::COMPLETENESSES_FIELD => array('completenessCode' => 'completeness normalization'), ProductNormalizer::ENABLED_FIELD => true]);
 }
 /**
  * @param  $product
  * @return array
  */
 public function getDefaultDrupalProduct(ProductInterface $product)
 {
     $labels = [];
     $attributeAsLabel = $product->getFamily()->getAttributeAsLabel();
     $availableLocales = $attributeAsLabel->getAvailableLocales();
     if (!is_null($availableLocales)) {
         foreach ($availableLocales as $availableLocale) {
             $labels[$availableLocale->getCode()] = $product->getLabel($availableLocale->getCode());
         }
     }
     // TODO: fix availableLocales doesn t must be NULL
     foreach ($attributeAsLabel->getTranslations() as $translation) {
         $labels[$translation->getLocale()] = $product->getLabel($translation->getLocale());
     }
     $defaultDrupalProduct = ['sku' => $product->getReference(), 'family' => $product->getFamily()->getCode(), 'created' => $product->getCreated()->format('c'), 'updated' => $product->getUpdated()->format('c'), 'status' => $product->isEnabled(), 'labels' => $labels, 'categories' => [], 'groups' => [], 'associations' => [], 'values' => []];
     return $defaultDrupalProduct;
 }
コード例 #3
0
 /**
  * Asserts that we have more than a minute interval between the product updated date and the argument
  *
  * @Then /^the (product "([^"]+)") updated date should not be close to "([^"]+)"$/
  */
 public function theProductUpdatedDateShouldNotBeCloseTo(ProductInterface $product, $identifier, $expected)
 {
     assertGreaterThan(60, abs(strtotime($expected) - $product->getUpdated()->getTimestamp()));
 }
コード例 #4
0
 /**
  * @param ProductInterface $product
  *
  * @return bool
  */
 protected function needsUpdate(ProductInterface $product)
 {
     $delta = $this->deltaRepository->findOneBy(['productId' => $product->getId(), 'jobInstance' => $this->stepExecution->getJobExecution()->getJobInstance()]);
     return null === $delta || $delta->getLastExport() < $product->getUpdated();
 }
コード例 #5
0
 /**
  * Get custom values (not provided by the PIM product)
  * @param ProductInterface  $product
  * @param MappingCollection $attributeCodeMapping
  * @param array             $parameters
  *
  * @return mixed
  */
 protected function getCustomValue(ProductInterface $product, MappingCollection $attributeCodeMapping, array $parameters = [])
 {
     return [strtolower($attributeCodeMapping->getTarget(self::VISIBILITY)) => $this->visibility, strtolower($attributeCodeMapping->getTarget(self::ENABLED)) => (string) $this->enabled ? 1 : 2, strtolower($attributeCodeMapping->getTarget('created_at')) => $product->getCreated()->format(AbstractNormalizer::DATE_FORMAT), strtolower($attributeCodeMapping->getTarget('updated_at')) => $product->getUpdated()->format(AbstractNormalizer::DATE_FORMAT), strtolower($attributeCodeMapping->getTarget('categories')) => $this->getProductCategories($product, $parameters['categoryMapping'], $parameters['scopeCode'])];
 }