diff --git a/app/appfront/modules/Catalog/block/product/CustomOption.php b/app/appfront/modules/Catalog/block/product/CustomOption.php index a76acfa570b60093efb9a9f396017c9560cac775..9eea19a3e54f584fe6191951b3d40099d5988550 100644 --- a/app/appfront/modules/Catalog/block/product/CustomOption.php +++ b/app/appfront/modules/Catalog/block/product/CustomOption.php @@ -20,6 +20,7 @@ class CustomOption { public $custom_option; public $attr_group; + public $product_id; public $middle_img_width; # 图片的宽度。 protected $_custom_option_arr; @@ -28,6 +29,7 @@ class CustomOption { //var_dump($items);exit; return [ 'items' => $items , + 'product_id' => $this->product_id, 'custom_option_arr' => json_encode($this->_custom_option_arr), 'middle_img_width' => $this->middle_img_width, ]; diff --git a/app/appfront/modules/Catalog/controllers/ProductController.php b/app/appfront/modules/Catalog/controllers/ProductController.php index 989b696893ceb47b55175e08dbd1fdaceb754a15..69b7b64ced08002b81b0555ae9c80ecc007e68c6 100644 --- a/app/appfront/modules/Catalog/controllers/ProductController.php +++ b/app/appfront/modules/Catalog/controllers/ProductController.php @@ -29,6 +29,36 @@ class ProductController extends AppfrontController return $this->render($this->action->id,$data); } + # ajax 得到产品加入购物车的价格。 + public function actionGetcoprice(){ + $custom_option_sku = Yii::$app->request->get('custom_option_sku'); + $product_id = Yii::$app->request->get('product_id'); + $qty = Yii::$app->request->get('qty'); + $cart_price = 0; + $custom_option_price = 0; + $product = Yii::$service->product->getByPrimaryKey($product_id); + $cart_price = Yii::$service->product->price->getCartPriceByProductId($product_id,$qty,$custom_option_sku); + if(!$cart_price){ + return; + } + $price_info = [ + 'price' => $cart_price, + ]; + + $priceView = [ + 'view' => 'catalog/product/index/price.php' + ]; + $priceParam = [ + 'price_info' => $price_info, + ]; + + echo json_encode([ + 'price' =>Yii::$service->page->widget->render($priceView,$priceParam), + ]); + exit; + + } + } diff --git a/app/appfront/modules/Checkout/block/cart/Index.php b/app/appfront/modules/Checkout/block/cart/Index.php new file mode 100644 index 0000000000000000000000000000000000000000..4601c926fc3829f86d455219dec59ab72a68a77b --- /dev/null +++ b/app/appfront/modules/Checkout/block/cart/Index.php @@ -0,0 +1,59 @@ +initHead(); + return [ + + ]; + } + + public function getCartInfo(){ + + # 得到单个产品的价格 + //Yii::$service->product->price->getCartPriceByProductId($productId,$qty,$custom_option_sku); + } + + public function initHead(){ + + Yii::$app->view->registerMetaTag([ + 'name' => 'keywords', + 'content' => 'checkout cart', + ]); + + Yii::$app->view->registerMetaTag([ + 'name' => 'description', + 'content' => 'checkout cart page', + ]); + $this->_title = 'checkout cart page'; + Yii::$app->view->title = $this->_title; + } + +} + + + + + + + + + + + + + + + + diff --git a/app/appfront/modules/Checkout/controllers/CartController.php b/app/appfront/modules/Checkout/controllers/CartController.php index e341c15be795f5422ddd169da3101987915016ed..d902c9cc4b5fe319038f1ea63747bd3fed80a698 100644 --- a/app/appfront/modules/Checkout/controllers/CartController.php +++ b/app/appfront/modules/Checkout/controllers/CartController.php @@ -19,6 +19,13 @@ class CartController extends AppfrontController { public $enableCsrfValidation = false; + + public function actionIndex(){ + $data = $this->getBlock()->getLastData(); + return $this->render($this->action->id,$data); + + } + public function actionAdd(){ $this->enableCsrfValidation = true; $custom_option = Yii::$app->request->post('custom_option'); diff --git a/app/appfront/theme/base/front/assets/css/style.css b/app/appfront/theme/base/front/assets/css/style.css index f6012499773c354b94f6b8c4775d04e03ab5a011..a05eacd2a03887696e01027ddfeb1933d5d8908d 100644 --- a/app/appfront/theme/base/front/assets/css/style.css +++ b/app/appfront/theme/base/front/assets/css/style.css @@ -531,6 +531,7 @@ del.my_shop_price { #footer { color: #7f7f7f; overflow-x: hidden; + width:100%; } .footer-container { margin-top: 50px; @@ -2371,6 +2372,263 @@ a.next_images { +.shopping-cart-img { + background: rgba(0, 0, 0, 0) url("../images/scart_step1.gif") repeat scroll 0 0; + height: 36px; + margin: 20px auto 5px; + width: 834px; +} +.shopping-cart-div { + position: relative; +} +.data-table { + width: 100%; +} + +.data-table thead { + background-color: #f2f2f2; +} +.shopping-cart-div .data-table thead tr { + border: medium none; +} + + +.shopping-cart-div .data-table tr th { + border: medium none; +} + +.shopping-cart-div .data-table tr { + border-bottom: 1px solid #ccc; +} + +.shopping-cart-div .data-table tr td { + border: medium none; +} +#shopping-cart-table .a-right { + text-align: center !important; +} + +.cartqtydown { + background: rgba(0, 0, 0, 0) url("../images/jj.png") no-repeat scroll -4px -1px; + float: left; + height: 10px; + margin: 12px 4px 0 0; + width: 10px; +} + + +#shopping-cart-table .qty { + float: left; + text-align: center; + width: 15px !important; +} + +a.cartqtyup { + background: rgba(0, 0, 0, 0) url("../images/jj.png") no-repeat scroll -4px -25px; + float: left; + height: 10px; + margin: 12px 0 0 3px; + width: 10px; +} + +.cart .cart-collaterals { + padding: 25px 0 0; +} +.btn-remove2 { + background: rgba(0, 0, 0, 0) url("../images/btn_trash.gif") no-repeat scroll 0 0; + display: block; + font-size: 0; + height: 16px; + line-height: 0; + overflow: hidden; + text-indent: -999em; + width: 16px; +} + + +#discount-coupon-form .discount-form label { + color: #999; + display: block; + font-size: 11px; + font-weight: 100; + margin: 8px 0 10px; +} + +#discount-coupon-form .input-box { + float: left; +} + +body #discount-coupon-form div.buttons-cou { + float: left; +} + + +.discount-form .submitbutton { + background: #ccc none repeat scroll 0 0; + border-radius: 0; + font-size: 14px; + height: 31px; + line-height: 31px; +} + + + +.cart .totals { + float: right; + width: 494px; +} + +.cart .cart-collaterals .col2-set { + float: left; + width: 400px; +} +.proceed_to_checkout { + margin-top: 35px; + text-align: right; +} + +#shopping-cart-totals-table2 { + border-top: 1px solid #333; + font-size: 14px; + margin: 16px 0 0; +} + +.cart .totals table th, .cart .totals table td { + padding: 5px; +} + +.std b, .std strong { + font-weight: bold; +} + + +.price { + white-space: nowrap !important; +} +* { + margin: 0; + padding: 0; +} +.std b, .std strong { + font-weight: bold; +} +strong { + font-weight: bold; +} +#shopping-cart-totals-table2 .a-right { + color: #2ab4c4; + font-size: 18px; +} +#shopping-cart-totals-table2 .a-right { + color: #2ab4c4; + font-size: 18px; +} + + +.proceed_to_checkout { + margin-top: 35px; + text-align: right; +} + + + +.proceed_to_checkout button.button { + display: block; + float: right; +} + + +a.express_paypal{ + background: rgba(0, 0, 0, 0) url("../images/paypaltopay.jpg") repeat scroll 0 0; + display: block; + float: right; + height: 30px; + width: 154px; +} + +.proceed_to_checkout .or{ + display: block; + float: right; + font-weight: bold; + line-height: 32px; + margin: 0 5px; +} + +.proceed_to_checkout button.button span { + font-size: 20px; +} + + +.cart-collaterals .col2-set .col-2 { + float: left; +} + + + +#discount-coupon-form .discount { + width: 500px; +} + + + + + +#discount-coupon-form .input-box { + float: left; +} + +body #discount-coupon-form div.buttons-cou { + float: left; +} +#discount-coupon-form #coupon_code { + border-radius: 0; + height: 29px; + width: 200px; +} + +.discount-form .submitbutton:hover{ + background-color:#4c8b99; +} + +h2 { + font-size: 18px; + font-weight: normal; + line-height: 1.25; + padding:0 0 2px 0; +} + +.a-center { + text-align: center !important; +} +.product-name { + font-size: 1em; + font-weight: normal; +} + + +.product_info .price_info .no-special { + line-height: 30px; + margin-right: 10px; + color: #cc0000; + font-size: 25px; +} + + + + + + + + + + + + + + + + + diff --git a/app/appfront/theme/base/front/assets/images/btn_trash.gif b/app/appfront/theme/base/front/assets/images/btn_trash.gif new file mode 100644 index 0000000000000000000000000000000000000000..5c604abb2f385f9c08f76a4b76b523f926467e53 Binary files /dev/null and b/app/appfront/theme/base/front/assets/images/btn_trash.gif differ diff --git a/app/appfront/theme/base/front/assets/images/jj.png b/app/appfront/theme/base/front/assets/images/jj.png new file mode 100644 index 0000000000000000000000000000000000000000..e0160855ed5a2192b807fd3bbb3760aa4cfb4860 Binary files /dev/null and b/app/appfront/theme/base/front/assets/images/jj.png differ diff --git a/app/appfront/theme/base/front/assets/images/paypaltopay.jpg b/app/appfront/theme/base/front/assets/images/paypaltopay.jpg new file mode 100644 index 0000000000000000000000000000000000000000..764e13adb8268569cb7b2900a92350129bb29dce Binary files /dev/null and b/app/appfront/theme/base/front/assets/images/paypaltopay.jpg differ diff --git a/app/appfront/theme/base/front/assets/images/scart_step1.gif b/app/appfront/theme/base/front/assets/images/scart_step1.gif new file mode 100644 index 0000000000000000000000000000000000000000..77febc59acca6afe3f0b153423d554713bf233a0 Binary files /dev/null and b/app/appfront/theme/base/front/assets/images/scart_step1.gif differ diff --git a/app/appfront/theme/base/front/catalog/product/index.php b/app/appfront/theme/base/front/catalog/product/index.php index 1c04d595a63e5e34ab6a6c8ea30b763e906ed6f4..f6f6bd7a58f4af4c04bca0bf38ad8d97844272ca 100644 --- a/app/appfront/theme/base/front/catalog/product/index.php +++ b/app/appfront/theme/base/front/catalog/product/index.php @@ -46,6 +46,7 @@ page->widget->render($optionsView,$optionsParam); ?> +
'catalog/product/index/custom_option.php', 'custom_option' => $custom_option, 'attr_group' => $attr_group, + 'product_id' => $_id , 'middle_img_width' => $media_size['middle_img_width'], ]; $optionsParam = [ @@ -238,7 +240,7 @@ if(data.status == 'success'){ items_count = data.items_count; $("#js_cart_items").html(items_count); - alert('add to cart success'); + window.location.href="url->getUrl("checkout/cart") ?>"; }else{ alert('add to cart fail'); } @@ -260,6 +262,57 @@ window.location.href = url; } }); + // 鏀瑰彉涓暟鐨勬椂鍊欙紝浠锋牸闅忎箣鍙樺姩 + $(".qty").blur(function(){ + // 濡傛灉鍏ㄩ儴閫夋嫨瀹屾垚锛岄渶瑕佸埌ajax璇锋眰锛屽緱鍒版渶鍚庣殑浠锋牸 + i = 1; + $(".product_custom_options .pg .rg ul.required").each(function(){ + val = $(this).find("li.current a.current").attr("value"); + attr = $(this).find("li.current a.current").attr("attr"); + if(!val){ + i = 0; + } + }); + if(i){ + getCOUrl = "url->getUrl('catalog/product/getcoprice'); ?>"; + product_id = ""; + qty = $(".qty").val(); + custom_option_sku = ''; + for(x in custom_option_arr){ + one = custom_option_arr[x]; + j = 1; + $(".product_custom_options .pg .rg ul.required").each(function(){ + val = $(this).find("li.current a.current").attr("value"); + attr = $(this).find("li.current a.current").attr("attr"); + if(one[attr] != val){ + j = 0; + //break; + } + }); + if(j){ + custom_option_sku = one['sku']; + break; + } + } + $data = { + custom_option_sku:custom_option_sku, + qty:qty, + product_id:product_id + }; + jQuery.ajax({ + async:true, + timeout: 6000, + dataType: 'json', + type:'get', + data: $data, + url:getCOUrl, + success:function(data, textStatus){ + $(".price_info").html(data.price); + }, + error:function (XMLHttpRequest, textStatus, errorThrown){} + }); + } + }); }); endBlock(); ?> registerJs($this->blocks['add_to_cart'],\yii\web\View::POS_END);//灏嗙紪鍐欑殑js浠g爜娉ㄥ唽鍒伴〉闈㈠簳閮 ?> diff --git a/app/appfront/theme/base/front/catalog/product/index/custom_option.php b/app/appfront/theme/base/front/catalog/product/index/custom_option.php index 10bd5c0eb8da5dbc0189254392ef6445dd775a55..70dec6835dcd9490b9d760e22775e7d098c5c9d0 100644 --- a/app/appfront/theme/base/front/catalog/product/index/custom_option.php +++ b/app/appfront/theme/base/front/catalog/product/index/custom_option.php @@ -173,6 +173,52 @@ $(document).ready(function(){ }); }); + // 濡傛灉鍏ㄩ儴閫夋嫨瀹屾垚锛岄渶瑕佸埌ajax璇锋眰锛屽緱鍒版渶鍚庣殑浠锋牸 + i = 1; + $(".product_custom_options .pg .rg ul.required").each(function(){ + val = $(this).find("li.current a.current").attr("value"); + attr = $(this).find("li.current a.current").attr("attr"); + if(!val){ + i = 0; + } + }); + if(i){ + for(x in custom_option_arr){ + one = custom_option_arr[x]; + j = 1; + $(".product_custom_options .pg .rg ul.required").each(function(){ + val = $(this).find("li.current a.current").attr("value"); + attr = $(this).find("li.current a.current").attr("attr"); + if(one[attr] != val){ + j = 0; + //break; + } + }); + if(j){ + getCOUrl = "url->getUrl('catalog/product/getcoprice'); ?>"; + custom_option_sku = one['sku']; + product_id = ""; + qty = $(".qty").val(); + $data = { + custom_option_sku:custom_option_sku, + qty:qty, + product_id:product_id + }; + jQuery.ajax({ + async:true, + timeout: 6000, + dataType: 'json', + type:'get', + data: $data, + url:getCOUrl, + success:function(data, textStatus){ + $(".price_info").html(data.price); + }, + error:function (XMLHttpRequest, textStatus, errorThrown){} + }); + } + } + } } }); @@ -182,6 +228,7 @@ $(document).ready(function(){ + }); endBlock(); ?> diff --git a/app/appfront/theme/base/front/catalog/product/index/price.php b/app/appfront/theme/base/front/catalog/product/index/price.php index ba47d3c5dcc90ed8ddfc4f94f239e2a1eef6f652..a9d2c40ad01227f2f9aed47855cdaf622cda146a 100644 --- a/app/appfront/theme/base/front/catalog/product/index/price.php +++ b/app/appfront/theme/base/front/catalog/product/index/price.php @@ -9,8 +9,7 @@
-
- - +
+
\ No newline at end of file diff --git a/app/appfront/theme/base/front/checkout/cart/index.php b/app/appfront/theme/base/front/checkout/cart/index.php new file mode 100644 index 0000000000000000000000000000000000000000..3f835ada4727b3d2213da686a854a704ce68b898 --- /dev/null +++ b/app/appfront/theme/base/front/checkout/cart/index.php @@ -0,0 +1,171 @@ +
+
+
+ +
+
+
+ +
+
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 Product NameUnit PriceQtySubtotal 
+ + 2121 + + +

+ Retro Deep V-neck Irregular Tassels Hem Sleeveless Dress +

+
  • Color:Black
  • Size:S
+
+ + $19.00 + + + +
+ + + +
+
+
+ + $19.00 + + + Remove item +
+ +
+
+
+
+
+
+
+
+
+

Discount Codes

+
+ + +
+ +
+ +
+
+
+
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + +
+ Item Subtotal: + $19.00
+ Shipping + $0.00
+ Coupon: + -$0.00
+ + + + + + + + + + + +
+ Grand Total + + $19.00 +
+
+
+ + + + - OR - + + + +
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/services/Cart.php b/services/Cart.php index a58ffa296d0772c13cc1a166ea895afc2ffc7b8d..724f5815a72130dacadc70c0b7105f7c5fcb9c34 100644 --- a/services/Cart.php +++ b/services/Cart.php @@ -63,6 +63,10 @@ class Cart extends Service } + protected function actionGetCartInfo(){ + return Yii::$service->cart->quote->getCartInfo(); + } + /** * 鍒濆鍖 */ diff --git a/services/Product.php b/services/Product.php index 652fa2b59799d5da65e38ede1bd41a3b82c2598f..b88bf52d28b5b10d40fc42aad73b6c7b35ddee2f 100644 --- a/services/Product.php +++ b/services/Product.php @@ -101,6 +101,10 @@ class Product extends Service return true; } + protected function actionIsActive($status){ + return ($status == 1) ? true : false; + } + protected function actionGetCustomOptionAttrInfo($productAttrGroup){ $arr = []; if($productAttrGroup == $this->_defaultAttrGroup){ diff --git a/services/cart/Quote.php b/services/cart/Quote.php index 7140c7dec777223e123f9a525c56fdfadaea3dd9..53ba8490389035cbc87df7548984e452006b1dd7 100644 --- a/services/cart/Quote.php +++ b/services/cart/Quote.php @@ -124,6 +124,22 @@ class Quote extends Service } + public function getCartInfo(){ + $cart_id = $this->getCartId(); + if(!$cart_id){ + return ; + } + + $this->getMyCart(); + $items_qty = $this->_my_cart['items_count']; + if($items_qty <= 0){ + return ; + } + + $cart_product = Yii::$service->cart->quoteItem->getCartProductInfo(); + + } + } \ No newline at end of file diff --git a/services/cart/QuoteItem.php b/services/cart/QuoteItem.php index 8a05cdd06c4b847101ad8082289006d87057a7f2..2625e3be5a6a3b85b6226aedf571c4d6db8a45d4 100644 --- a/services/cart/QuoteItem.php +++ b/services/cart/QuoteItem.php @@ -101,6 +101,41 @@ class QuoteItem extends Service return $item_qty; } + /** + * 寰楀埌褰撳墠璐墿杞︾殑浜у搧浠锋牸淇℃伅銆 + */ + public function getCartProductInfo(){ + $cart_id = Yii::$service->cart->quote->getCartId(); + $products = []; + $product_total = 0; + if($cart_id){ + $data = MyCartItem::find()->where([ + 'cart_id' => $cart_id + ])->all(); + if(is_array($data) && !empty($data)){ + foreach($data as $one){ + $product_id = $one['product_id']; + $qty = $one['qty']; + $custom_option_sku = $one['custom_option_sku']; + $product_price = Yii::$service->product->price->getCartPriceByProductId($product_id,$qty,$custom_option_sku); + $product_row_price = $product_price * $qty; + $product_total += $product_row_total; + $products[] = [ + 'product_id' => $product_id , + 'qty' => $qty , + 'custom_option_sku' => $custom_option_sku , + 'product_price' => $product_price , + 'product_row_price' => $product_row_price , + ]; + } + return [ + 'products' => $products, + 'product_total' => $product_total, + ]; + } + } + } + } \ No newline at end of file diff --git a/services/product/Price.php b/services/product/Price.php index c85310d53079b83145ba238f1611da10978e88b9..80c5d24c7e6cb4266aa37e05204c7bdf8c392dba 100644 --- a/services/product/Price.php +++ b/services/product/Price.php @@ -77,6 +77,70 @@ class Price extends Service } return $return_price; } + + /** + * @property $productId | String + * @property $qty | Int + * @property $custom_option_sku | String + * 閫氳繃浜у搧浠ュ強涓暟锛宑ustonOptionSku 寰楀埌浜у搧鐨勬渶缁堜环鏍 + */ + protected function actionGetCartPriceByProductId($productId,$qty,$custom_option_sku){ + $product = Yii::$service->product->getByPrimaryKey($productId); + $custom_option_price = 0; + $status = isset($product['status']) ? $product['status'] : 0; + + if($product['price'] && Yii::$service->product->isActive($status)){ + $price = $product['price']; + $special_price = isset($product['special_price']) ? $product['special_price'] : 0; + $special_from = isset($product['special_from']) ? $product['special_from'] : ''; + $special_to = isset($product['special_to']) ? $product['special_to'] : ''; + $tier_price = isset($product['tier_price']) ? $product['tier_price'] : []; + $custom_option = isset($product['custom_option']) ? $product['custom_option'] : ''; + + if(!empty($custom_option) && $custom_option_sku && isset($custom_option[$custom_option_sku])){ + if($co = $custom_option[$custom_option_sku]){ + $custom_option_price = isset($co['price']) ? $co['price'] : 0; + } + } + return $this->getCartPrice( + $price , $special_price, + $special_from , $special_to, + $qty , $custom_option_price, + $tier_price + ); + } + + } + + # 浜у搧鍔犲叆璐墿杞︼紝寰楀埌鐩稿簲涓暟鐨勬渶缁堜环鏍笺 + protected function actionGetCartPrice( + $price , $special_price, + $special_from , $special_to, + $qty='' , $custom_option_price, + $tier_price=[] , $format = 1 + ){ + if($this->specialPriceisActive($price,$special_price,$special_from,$special_to)){ + $return_price = $special_price; + }else{ + $return_price = $price; + } + + if($qty > 1){ + $return_price = $this->getTierPrice($qty,$tier_price,$return_price); + + } + $return_price = $return_price + $custom_option_price; + if($format){ + $format_price = $this->formatPrice($return_price); + return $format_price ; + }else{ + return $return_price; + } + + + } + + /** * @property $qty | Int * @property $price | Float 涓涓骇鍝佺殑鍗曚环(濡傛灉鏈夌壒浠凤紝閭d箞杩欎釜鍊兼槸涓涓骇鍝佺殑鐗逛环) @@ -93,14 +157,18 @@ class Price extends Service } $t_price = $price; if(is_array($tier_price_arr) && !empty($tier_price_arr)){ + foreach($tier_price_arr as $one){ + $t_qty = $one['qty']; - if($t_qty <= $qty){ + $t_price = $one['price']; + + if($t_qty < $qty){ continue; }else{ + return $t_price; } - $t_price = $one['price']; } } return $t_price;