카테고리 없음

Teddy's Promotion Idea

테디아저씨 2024. 8. 11. 22:00

저는 프로모션 테이블을 별도로 만들고 service_item 과 조인할 예정입니다.

create table promotion 
(
	p_no int not null AUTO_INCREMENT,
	p_name varchar(50) not null default '',    # Promotion name
	p_service int not null default 0,
	p_kind char(1) not null default 'P',    # P : price, R : rate
	p_value int not null default 0,
	p_sdate date,
	p_edate date,
	PRIMARY KEY (p_no),
	KEY (p_service) );

 

 

order_add.php 부분에서 오늘 날자에 해당하는 프로모션을 Left Join 하였습니다.

select si_cat, si_service_name, si_price, si_image1, si_image2, si_image3, 
	si_description , p_name, p_kind, p_value from service_item as s
left join promotion as p on ( 
    p.p_service = s.si_no and 
    p.p_sdate <= date_format(now(),'%Y-%m-%d') and 
    p.p_edate >= date_format(now(),'%Y-%m-%d') 
)

 

order 를 수정하는경우는 오늘이 아니라 구매한 날자를 사용하면 됩니다.

 

 

 

상품목록을 보여줄때 할인율/할인금액을 보여주기 위해 

 

    foreach ($categories as $cat => $cat_name) {
        echo "<div class='topic-container' id='$cat-section'>";
        echo "<h2>$cat_name</h2>";
        echo "<div class='nail-services'>";

        foreach ($services as $service) {
            if ($service['si_cat'] == $cat) {
                $service_name = htmlspecialchars($service['si_service_name']);
                $price = htmlspecialchars($service['si_price']);

                // add by Teddy
                $prokind = htmlspecialchars($service['p_kind']);
                $provalue = htmlspecialchars($service['p_value']);

                $image1 = htmlspecialchars($service['si_image1']);
                $image2 = htmlspecialchars($service['si_image2']);
                $image3 = htmlspecialchars($service['si_image3']);
                $description = htmlspecialchars($service['si_description']);
                
                // 아래에서 변수로 사용하기 위해 
                // data-prokind='$prokind' data-provalue='$provalue' 를 추가했습니다.
                
                echo "<div class='service' data-category='$cat' data-price='$price' data-prokind='$prokind' data-provalue='$provalue' data-images='$image1,$image2,$image3' data-description='$description'>";
                echo "<input type='checkbox' class='service-checkbox'> $service_name";
                echo "<div class='quantity-control' style='display: none;'>";
                echo "<button class='decrement'>-</button>";
                echo "<input type='text' value='1' class='quantity'>";
                echo "<button class='increment'>+</button>";
                echo "</div>";
                echo "<span>" . number_format($price) . "</span>";
                echo "</div>";
            }
        }

        echo "</div>";
        echo "</div>";
    }

 

스크립트 아래 세부분에서 

 

1) document.addEventListener('DOMContentLoaded', function() ...

 

2) incrementButtons.forEach(function(button) ...

 

3) decrementButtons.forEach(function(button) ...

 

아래 세부분에서 아래와 같이 price 를 변경해줍니다.

 

                // Add by Teddy.Cho
                var prokind = parseInt(this.parentElement.dataset.prokind);
                var provalue = parseInt(this.parentElement.dataset.provalue);

                // Add by Teddy.Cho
                if( prokind != "" && provalue != "" && provalue > 0 ) {
                    if( prokind == "P" ) {
                        price = price - provalue;
                    }

                    if( prokind == "R" ) {
                        price = price - (price * (provalue/100));
                    }
                }