✅ Frakt 29kr när du handlar för mer än 299kr
Main unit for Pro Airstyler Duo
Pro Airstyler Duo
/** * Hämta sålda antal för en produkt (och ev. attribut) under en period. * Summerar både direkt sålda och (framtida) via pacs/paket. * * @param int $id_product * @param int|null $id_product_attribute * @param string|null $from (format: 'YYYY-MM-DD') * @param string|null $to (format: 'YYYY-MM-DD') * @return int */ public static function getQtySold($id_product, $id_product_attribute = null, $from = null, $to = null) { $where = 'od.product_id = '.(int)$id_product; if ($id_product_attribute !== null) { $where .= ' AND od.product_attribute_id = '.(int)$id_product_attribute; } if ($from) { $where .= " AND o.date_add >= '".pSQL($from)."'"; } if ($to) { $where .= " AND o.date_add <= '".pSQL($to)."'"; } $sql = 'SELECT SUM(od.product_quantity - od.product_quantity_refunded) as qty_sold FROM '._DB_PREFIX_.'order_detail od INNER JOIN '._DB_PREFIX_.'orders o ON o.id_order = od.id_order WHERE '.$where; $qty = (int)Db::getInstance()->getValue($sql); // Här kan du i framtiden lägga till summering av sålda via pacs/paket // t.ex. hämta alla pacs som innehåller produkten och summera deras försäljning return $qty; }