<?php
namespace App\Classes\Computed;
use App\Model\Product;
use Factory\SupportBundle\Contract\AbstractComputed;
use Pimcore\Model\DataObject;
use Pimcore\Model\DataObject\Concrete;
use Pimcore\Model\DataObject\Data\CalculatedValue;
use Pimcore\Model\DataObject\Data\QuantityValue;
class ProductComputed extends AbstractComputed
{
public function getPriceSystemRulePathCalculation(Product $object, $context)
{
if ($rule = $object->getPriceSystemRuleRelation()) {
return $rule->getPath() . $rule->getKey();
}
$category = $object->getMainCategory();
if ($category && $rule = $category->getPriceSystemRule()) {
return $rule->getPath() . $rule->getKey();
}
return '';
}
public function getMinBasePriceCalculation(Product $object, $context)
{
if ($object->getProductType() == 'simple') {
return '';
$parents = new DataObject\Product\Listing();
$parents->setCondition(
"oo_id IN (
SELECT src_id FROM object_relations_Product WHERE dest_id = ".$object->getId()."
) AND ProductType = 'grouped'"
);
foreach ($parents as $parent) {
if ($parent instanceof Product) {
$parent->getMinBasePrice();
$parent->save();
return '';
}
return '';
}
}
if (!$object->getType() == Product::OBJECT_TYPE_OBJECT) {
return '';
}
$items = $object->getProducts();
$items[] = $object;
$prices = array_values(array_filter(array_map(function ($variant) {
$price = $variant->getBasePrice();
if (!$price instanceof QuantityValue) {
return floatval($price);
}
return floatval($price->getValue());
}, $items)));
if (empty($prices)) {
return '';
}
return min($prices);
}
public function getCalculatedValueForEditMode(Concrete $object, CalculatedValue $context): string
{
return parent::getCalculatedValueForEditMode($object, $context); // TODO: Change the autogenerated stub
}
}