. * */ namespace Vvveb\Component\Product; use \Vvveb\Sql\Product_VariantSQL; use \Vvveb\Sql\ProductSQL; use Vvveb\System\Cart\Currency; use Vvveb\System\Cart\Tax; use Vvveb\System\Component\ComponentBase; use Vvveb\System\Event; use Vvveb\System\Images; class Variants extends ComponentBase { public static $defaultOptions = [ 'start' => 0, 'limit' => NULL, 'site_id' => NULL, 'language_id' => NULL, 'product_id' => 'url', 'parent_id' => NULL, 'search' => NULL, ]; public $cacheExpire = 0; //no cache function results() { $productSql = new ProductSQL(); $variantSql = new Product_VariantSQL(); $product = []; if ($this->options['product_id']) { $product = $productSql->get(['product_id' => $this->options['product_id']]); } $results = $variantSql->getAll($this->options); $count = 0; if ($results && isset($results['product_variant'])) { $variants = &$results['product_variant']; $tax = Tax::getInstance($this->options); $currency = Currency::getInstance($this->options); if ($variants) { foreach ($variants as &$variant) { $count++; if ($variant['image']) { $variant['image'] = Images::image($variant['image'], 'option', $this->options['image_size']); } if ($variant['price']) { $variant['price_tax'] = $tax->addTaxes($variant['price'], $product['tax_type_id'] ?? 0); $variant['price_formatted'] = $currency->format($variant['price_tax']); } } } } $results['count'] = $count; list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results); return $results; } }