/** * Test getter/setter for defaultValue property */ public function testGetSetDefaultValue() { $this->assertEquals('', $this->attribute->getDefaultValue()); $expectedDefaultValue = 'test-default-value'; $this->assertEntity($this->attribute->setDefaultValue($expectedDefaultValue)); $this->assertEquals($expectedDefaultValue, $this->attribute->getDefaultValue()); }
/** * Get normalized default value for attribute * @param AbstractAttribute $attribute * @param string $defaultLocale * @param array $magentoAttributes * @param array $magentoAttributesOptions * @param MappingCollection $attributeMapping * * @return string */ protected function getNormalizedDefaultValue(AbstractAttribute $attribute, $defaultLocale, array $magentoAttributes, array $magentoAttributesOptions, MappingCollection $attributeMapping) { $attributeCode = strtolower($attributeMapping->getTarget($attribute->getCode())); $context = ['identifier' => null, 'scopeCode' => null, 'localeCode' => $defaultLocale, 'onlyLocalized' => false, 'magentoAttributes' => [$attributeCode => ['scope' => !$attribute->isLocalizable() ? ProductValueNormalizer::GLOBAL_SCOPE : '']], 'magentoAttributesOptions' => $magentoAttributesOptions, 'attributeCodeMapping' => $attributeMapping, 'currencyCode' => '']; if ($attribute->getDefaultValue() instanceof ProductValueInterface) { return reset($this->productValueNormalizer->normalize($attribute->getDefaultValue(), 'MagentoArray', $context)); } elseif ($attribute->getDefaultValue() instanceof AttributeOption) { $productValue = $this->productValueManager->createProductValueForDefaultOption($attribute); $normalizedOption = $this->productValueNormalizer->normalize($productValue, 'MagentoArray', $context); return null != $normalizedOption ? reset($normalizedOption) : null; } else { return null !== $attribute->getDefaultValue() ? (string) $attribute->getDefaultValue() : ''; } }
/** * Normalize default value * * @param AbstractAttribute $attribute * * @return array */ protected function normalizeDefaultValue(AbstractAttribute $attribute) { $defaultValue = $attribute->getDefaultValue(); if ($defaultValue instanceof \DateTime) { return $defaultValue->format(\DateTime::ISO8601); } elseif ($defaultValue instanceof ArrayCollection || $defaultValue instanceof AttributeOption) { return $this->normalizeDefaultOptions($attribute); } else { return (string) $defaultValue; } }