本文整理汇总了PHP中Pim\Bundle\CatalogBundle\Model\ProductValueInterface::getMetric方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductValueInterface::getMetric方法的具体用法?PHP ProductValueInterface::getMetric怎么用?PHP ProductValueInterface::getMetric使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Bundle\CatalogBundle\Model\ProductValueInterface
的用法示例。
在下文中一共展示了ProductValueInterface::getMetric方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isComplete
/**
* {@inheritdoc}
*/
public function isComplete(ProductValueInterface $productValue, ChannelInterface $channel = null, LocaleInterface $locale = null)
{
$metric = $productValue->getMetric();
if (!$metric || null === $metric->getData()) {
return false;
}
return true;
}
示例2:
function it_validates_product_value_with_metric_data($accessor, $context, ValidMetric $constraint, ProductValueInterface $value, MetricInterface $metric)
{
$value->getMetric()->willReturn($metric);
$metric->getUnit()->willReturn('cm');
$metric->getData()->willReturn(12);
$accessor->getValue($metric, 'family')->shouldBeCalled()->willReturn('Weight');
$accessor->getValue($metric, 'unit')->shouldBeCalled()->willReturn('kg');
$context->addViolationAt(Argument::any(), Argument::any())->shouldNotBeCalled();
$this->validate($value, $constraint)->shouldReturn(null);
}
示例3: addFromManyFields
/**
* The metric is built by many ordered calls, one for the data column, one for the unit column
*
* @param ProductValueInterface $value
* @param string $dataOrUnit
*
* @return \Pim\Bundle\CatalogBundle\Model\MetricInterface
*/
protected function addFromManyFields(ProductValueInterface $value, $dataOrUnit)
{
// TODO come from original implementation, really FRAGIL because depends on many ordered calls
if (null === ($metric = $value->getMetric())) {
$metric = $this->factory->createMetric($value->getAttribute()->getMetricFamily());
$metric->setData($dataOrUnit);
} else {
$metric->setUnit($dataOrUnit);
}
return $metric;
}
示例4:
function it_denormalizes_a_new_metric_from_a_single_field_and_set_data_and_unit(ProductValueInterface $metricValue, MetricInterface $metric, AttributeInterface $weight, $metricFactory)
{
$context = ['value' => $metricValue];
$metricValue->getMetric()->willReturn(null);
$metricValue->getAttribute()->willReturn($weight);
$weight->getMetricFamily()->willReturn('Weight');
$metricFactory->createMetric('Weight')->willReturn($metric);
$metric->setData('100')->shouldBeCalled();
$metric->setUnit('KILOGRAM')->shouldBeCalled();
$this->denormalize('100 KILOGRAM', 'className', null, $context)->shouldReturn($metric);
}
示例5: it_succesfully_checks_complete_metric
public function it_succesfully_checks_complete_metric(ProductValueInterface $value, ChannelInterface $channel, LocaleInterface $locale, MetricInterface $metric)
{
$value->getMetric()->willReturn(null);
$this->isComplete($value, $channel, $locale)->shouldReturn(false);
$value->getMetric()->willReturn([]);
$this->isComplete($value, $channel, $locale)->shouldReturn(false);
$metric->getData()->willReturn(null);
$value->getMetric()->willReturn($metric);
$this->isComplete($value, $channel, $locale)->shouldReturn(false);
$metric->getData()->willReturn('foobar');
$value->getMetric()->willReturn($metric);
$this->isComplete($value, $channel, $locale)->shouldReturn(true);
}
示例6: validate
/**
* Validate metric type and default metric unit
*
* @param AttributeInterface|MetricInterface|ProductValueInterface $object
* @param Constraint $constraint
*/
public function validate($object, Constraint $constraint)
{
if ($object instanceof AttributeInterface) {
$familyProperty = 'metricFamily';
$unitProperty = 'defaultMetricUnit';
} elseif ($object instanceof MetricInterface && null !== $object->getData()) {
$familyProperty = 'family';
$unitProperty = 'unit';
} elseif ($object instanceof ProductValueInterface && null !== $object->getMetric() && (null !== $object->getMetric()->getUnit() || null !== $object->getMetric()->getData())) {
$object = $object->getMetric();
$familyProperty = 'family';
$unitProperty = 'unit';
} else {
return;
}
$family = $this->propertyAccessor->getValue($object, $familyProperty);
$unit = $this->propertyAccessor->getValue($object, $unitProperty);
if (!array_key_exists($family, $this->measures)) {
$this->context->buildViolation($constraint->familyMessage)->atPath($familyProperty)->addViolation();
} elseif (!array_key_exists($unit, $this->measures[$family]['units'])) {
$this->context->buildViolation($constraint->unitMessage)->atPath($unitProperty)->addViolation();
}
}
示例7: validateMetric
/**
* Check if the metric value is not empty
*
* @param ProductValueInterface $value
* @param Constraint $constraint
*/
protected function validateMetric(ProductValueInterface $value, Constraint $constraint)
{
$metric = $value->getMetric();
if (!$metric || $metric->getData() === null) {
$this->context->addViolation($constraint->messageComplete);
}
}
示例8: Metric
function it_returns_null_when_unknown_backendtype($context, ProductValueComplete $constraint, ProductValueInterface $productValue, AttributeInterface $attribute)
{
$constraint->getChannel()->willReturn($this->getChannel());
$metric = new Metric();
$productValue->getMetric()->willReturn($metric);
$productValue->getData()->willReturn('data');
$attribute->getBackendType()->willReturn('unknown_metric');
$productValue->getAttribute()->willReturn($attribute);
$context->buildViolation(Argument::any())->shouldNotBeCalled();
$this->validate($productValue, $constraint);
}
示例9:
function it_returns_a_metric_if_the_data_is_empty(ProductValueInterface $metricValue, MetricInterface $metric)
{
$metricValue->getMetric()->willReturn($metric);
$this->denormalize('', 'className', null, ['value' => $metricValue])->shouldReturn($metric);
$this->denormalize(null, 'className', null, ['value' => $metricValue])->shouldReturn($metric);
}
示例10: setProductMetric
/**
* @param ProductValueInterface $productValue
* @param ProductValueInterface $value
*/
protected function setProductMetric(ProductValueInterface $productValue, ProductValueInterface $value)
{
if (null === ($metric = $productValue->getMetric())) {
$metric = $this->metricFactory->createMetric($value->getAttribute()->getMetricFamily());
$productValue->setMetric($metric);
}
$metric->setUnit($value->getMetric()->getUnit());
$metric->setData($value->getMetric()->getData());
}