Back to PhocacartDiscountCart class

Method storeDiscountProductsById

public static
storeDiscountProductsById
(mixed $itemString, mixed $discountId)

Method storeDiscountProductsById - Source code

/*
 * Static part - administration
 */
public static function storeDiscountProductsById($itemString, $discountId)
{
    if ((int) $discountId > 0) {
        $db = Factory::getDBO();
        $query = ' DELETE ' . ' FROM #__phocacart_discount_products' . ' WHERE discount_id = ' . (int) $discountId;
        $db->setQuery($query);
        $db->execute();
        if (isset($itemString) && $itemString != '') {
            $couponArray = explode(",", $itemString);
            $values = array();
            $valuesString = '';
            foreach ($couponArray as $k => $v) {
                $values[] = ' (' . (int) $discountId . ', ' . (int) $v . ')';
            }
            if (!empty($values)) {
                $valuesString = implode(',', $values);
                $query = ' INSERT INTO #__phocacart_discount_products (discount_id, product_id)' . ' VALUES ' . (string) $valuesString;
                $db->setQuery($query);
                $db->execute();
            }
        }
    }
}