Welcome Guest, Not a member yet? Register   Sign In
How to update product prices dynamically?
#1

I have a form with a list of product details that includes checkboxes, ids, names, and prices. How can I update the price of the checked products with a user-specified percentage using a button click? I've tried to retrieve the data of the checked checkboxes and update the price, but my code is not working properly. Can someone help me with this issue?

Here is the current code I'm using in my model:

php

public function update__all($id, $price)
{
    $this->db->set('price', 'price *'. ((100 + $price)/100) .'',false);
    $this->db->where("id", $id )
    $this->db->update(self::TABLE_NAME1);
    return $this->db->affected_rows();
}
And here is my view code:

php

<tr>
    <td class="px-6 py-4 whitespace-nowrap text-xs font-medium text-gray-900">
        <input id="price_check" name="price_check" type="checkbox" value="1" <?php echo set_checkbox('price_check', '1'); ?> class="rounded focus:ring-blue-500 h-4 w-4 text-blue-600 border-gray-300">
    </td>
    <td class="px-3 py-4 whitespace-nowrap text-xs font-medium text-gray-900">
        <input type="hidden"name="id" id="id" value="<?=$motor->id?>"> <?=$motor->product_id?>
    </td>
    <td class="px-3 py-4 whitespace-nowrap text-xs font-medium text-gray-900">
        <input type="hidden"name="motortype" id="motortype" value="<?=$motor->type_motor?>"><?=$motor->type_motor?>
    </td>
    <td class="px-3 py-4 whitespace-nowrap text-xs font-medium text-gray-900">
        <?php if($this->session->userdata('admin') == 0):?>
        <input type="number" step="0.01" name="price" id="price" value="<?= set_value('price', $motor->price ?? null) ?>" class="max-w-lg block shadow-sm focus:ring-blue-500 focus:border-blue-500 sm:max-w-xs sm:text-xs border-gray-300 rounded-md">
        <?php else:?>
        <?=$fmt->formatCurrency($motor->price, "EUR") ?>
        <?php endif?>
    </td>
    <?php if($this->session->userdata('admin') == 0):?>
    <td class="px-3 py-4 whitespace-nowrap text-xs font-medium text-gray-900">
        <?= date_format(new DateTime($motor->modified_on),"Y-m-d") ?? "nvt" ?>
    </td>
    <td class="px-3 py-4 whitespace-nowrap text-left text-xs text-gray-500 px-3 py-3">
        <button type="submit" class="inline-flex items-center px-5 py-2 border border-transparent text-sm leading-4 font-medium rounded-md shadow-sm text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
            Aanpassen
        </button>
    </td>
    <?php endif?>
</tr>
Reply




Theme © iAndrew 2016 - Forum software by © MyBB