本文整理汇总了PHP中Pim\Component\Catalog\Model\ProductValueInterface::getMetric方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductValueInterface::getMetric方法的具体用法?PHP ProductValueInterface::getMetric怎么用?PHP ProductValueInterface::getMetric使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Component\Catalog\Model\ProductValueInterface
的用法示例。
在下文中一共展示了ProductValueInterface::getMetric方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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->buildViolation(Argument::cetera())->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 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: 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);
}
示例5: 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();
}
}
示例6:
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);
}
示例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->buildViolation($constraint->messageComplete)->addViolation();
}
}
示例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);
}