<?= form_open("ecommerce/addCart", ['method' => 'post']) ?>
<?= form_hidden("product_uid", $entity->getPrimaryKey()) ?>
<input type="hidden" id="price" name="price" value="<?= ($entity->getPrice() - $entity->getSale()) * 1 ?>">
<?php
$quantityOptions = [DEFAULTS['EMPTY'] => "구매수량 선택"];
for ($i = 1; $i <= $entity->getStock(); $i++) {
	$quantityOptions[$i] = $i . "개";
}
?>
구매 수량 : <?= form_dropdown('quantity', $quantityOptions, 1, ['onChange' => "cal_price(this.options[this.selectedIndex].value)"]); ?>
구매 금액 : <span id="order_price"><?= number_format(($entity->getPrice() - $entity->getSale()) * 1) ?></span>원
<?= form_submit('', '최소:1 ~ 최대:' . $entity->getStock(), array("class" => "btn btn-outline btn-primary")); ?>
<?= form_close(); ?>
<script>
	function cal_price(quantity) {
		var price = 0;
		price = (<?= $entity->getPrice() ?> - <?= $entity->getSale() ?>) * quantity;;
		document.getElementById('price').value = price;
		document.getElementById('order_price').textContent = new Intl.NumberFormat().format(price);
	}
</script>