src/Classes/Computed/ProductComputed.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Classes\Computed;
  3. use App\Model\Product;
  4. use Factory\SupportBundle\Contract\AbstractComputed;
  5. use Pimcore\Model\DataObject;
  6. use Pimcore\Model\DataObject\Concrete;
  7. use Pimcore\Model\DataObject\Data\CalculatedValue;
  8. use Pimcore\Model\DataObject\Data\QuantityValue;
  9. class ProductComputed extends AbstractComputed
  10. {
  11.     public function getPriceSystemRulePathCalculation(Product $object$context)
  12.     {
  13.         if ($rule $object->getPriceSystemRuleRelation()) {
  14.             return $rule->getPath() . $rule->getKey();
  15.         }
  16.         $category $object->getMainCategory();
  17.         if ($category && $rule $category->getPriceSystemRule()) {
  18.             return $rule->getPath() . $rule->getKey();
  19.         }
  20.         return '';
  21.     }
  22.     public function getMinBasePriceCalculation(Product $object$context)
  23.     {
  24.         if ($object->getProductType() == 'simple') {
  25.             return '';
  26.             $parents = new DataObject\Product\Listing();
  27.             $parents->setCondition(
  28.                 "oo_id IN (
  29.                     SELECT src_id FROM object_relations_Product WHERE dest_id = ".$object->getId()."
  30.                 ) AND ProductType = 'grouped'"
  31.             );
  32.             foreach ($parents as $parent) {
  33.                 if ($parent instanceof Product) {
  34.                     $parent->getMinBasePrice();
  35.                     $parent->save();
  36.                     return '';
  37.                 }
  38.                 return '';
  39.             }
  40.         }
  41.         if (!$object->getType() == Product::OBJECT_TYPE_OBJECT) {
  42.             return '';
  43.         }
  44.         $items $object->getProducts();
  45.         $items[] = $object;
  46.         $prices array_values(array_filter(array_map(function ($variant) {
  47.             $price $variant->getBasePrice();
  48.             if (!$price instanceof QuantityValue) {
  49.                 return floatval($price);
  50.             }
  51.             return floatval($price->getValue());
  52.         }, $items)));
  53.         if (empty($prices)) {
  54.             return '';
  55.         }
  56.         return min($prices);
  57.     }
  58.     public function getCalculatedValueForEditMode(Concrete $objectCalculatedValue $context): string
  59.     {
  60.         return parent::getCalculatedValueForEditMode($object$context); // TODO: Change the autogenerated stub
  61.     }
  62. }