Skip to content

Commit

Permalink
add feature:mode product
Browse files Browse the repository at this point in the history
  • Loading branch information
nik3n1984 committed Aug 18, 2020
1 parent 30d57c7 commit c2399ec
Show file tree
Hide file tree
Showing 10 changed files with 545 additions and 112 deletions.
45 changes: 9 additions & 36 deletions app/controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace app\controllers;


use app\models\BreadCrumbs;
use app\models\Product;

class ProductController extends AppController
Expand All @@ -27,45 +28,17 @@ public function viewAction(){
}


// function getVisitedProducts($product){
// if (!isset($_COOKIE["visitedProducts"])){
// $visitedProducts = [];
// }else{
// $visitedProducts = unserialize($_COOKIE["visitedProducts"]);
// }
//
// if (!in_array($product["id"], $visitedProducts)){
// if(count($visitedProducts) == 6){
// array_shift($visitedProducts);
// }
// $visitedProducts[]=$product["id"];
// }
//
// $dataProducts = \R::findLike( 'product', ['id' => $visitedProducts] );
// $resProducts = [];
// for($i = 0 ; $i < count($visitedProducts); $i++){
// $id = $visitedProducts[$i];
// foreach ($dataProducts as $val){
// if($val['id'] == $id){
// $resProducts[]=$val;
// }
// }
// }
//
// setcookie("visitedProducts", serialize($visitedProducts),time()*3600*24, "/" );
// array_pop($resProducts);
// return $resProducts;
//
// }

// $visitedProducts = getVisitedProducts($product);

$productModelInst = new Product();
$visitedProducts = $productModelInst->getDataProducts();
$visitedProducts = $productModelInst->rangeProducts($visitedProducts,3);
$visitedProducts = $productModelInst->getDataProducts(3);
$productModelInst->setProductId($product["id"]);
$breadCrumbs = array_reverse(BreadCrumbs::getBreadCrumbs($product["category_id"], $product["title"]));

$productModifications = \R::findAll("modification", "product_id = ?", [$product['id']]);

//debug($productModifications,1);


$this->set(compact('product', "related", "gallery","visitedProducts"));
$this->set(compact('product', "related", "gallery","visitedProducts","breadCrumbs","productModifications"));

}

Expand Down
36 changes: 36 additions & 0 deletions app/models/BreadCrumbs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php


namespace app\models;


use ishop\App;

class BreadCrumbs
{

public static $arrRes = [];
public static function getBreadCrumbs($id,$title=""){
if(!self::$arrRes){

self::$arrRes[] = ["title"=>$title];
}


$category = App::$app->getProperty("cats");

$upProduct = $category[$id];
self::$arrRes[] = ['title'=>$upProduct['title'],'alias'=>$upProduct['alias']];



$parentId = $upProduct['parent_id'];
if($parentId){
self::getBreadCrumbs($parentId);
}
return self::$arrRes;

}


}
9 changes: 8 additions & 1 deletion app/models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ public function getAllProductsId(){
}
}

public function getDataProducts(){
public function getDataProducts($tail = 0){
$visitedProducts = $this->getAllProductsId();


if ($visitedProducts){

if( $tail < count($visitedProducts) && $tail != 0 ){
$visitedProducts = $this->rangeProducts($visitedProducts, $tail);
}

$dataProducts = \R::findLike( 'product', ['id' => $visitedProducts] );
$resProducts = [];
for($i = 0 ; $i < count($visitedProducts); $i++){
Expand Down
2 changes: 1 addition & 1 deletion app/views/Main/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<div class="product-bottom">
<h3><a href="/product/<?= $product->alias ?>" /> <?= $product->title ?> </a></h3>
<p>Explore Now</p>
<h4><a class="add-to-cart-link" href="cart/add?id=<?= $product->id ?>"><i></i></a>
<h4><a data-id ='<?= $product->id ?>' class="add-to-cart-link item_add" href="cart/add?id=<?= $product->id ?>"><i></i></a>
<span class=" item_price"><?= $curr["symbol_left"] ?><?= round($product->price * $curr["value"]) ?><?= $curr["symbol_right"] ?></span>
<?php if($product->old_price): ?>
<small><del><?= $curr["symbol_left"] ?><?= round($product->old_price * $curr["value"]) ?></del></small>
Expand Down
215 changes: 145 additions & 70 deletions app/views/Product/view.php

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions app/views/layouts/watch.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<body>
<!--top-header-->


<div class="top-header">
<div class="container">
<div class="top-header-main">
Expand Down Expand Up @@ -169,6 +168,7 @@
</div>
</div>
<!--footer-end-->

<script src="/js/jquery-1.11.0.min.js"></script>
<script src="/js/simpleCart.min.js"> </script>
<script src="/js/jquery.easydropdown.js"></script>
Expand Down Expand Up @@ -227,7 +227,10 @@

});
</script>

<script>
var symbolLeft = '<?= $curr["symbol_left"]; ?>',
symbolRight = '<?= $curr["symbol_right"]; ?>';
</script>
<script src="/js/main.js"></script>

<!--start-menu-->
Expand Down
17 changes: 17 additions & 0 deletions public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,21 @@
$('#currency').change(function () {

window.location ="currency/change?curr=" + $(this).val();
});

$('.available select').on('change', function () {
var outputPrice = $("#base-price");

var price = $(this).find("option").filter(":selected").data('price') ;
var basePrice = outputPrice.data("base");


if(price){
outputPrice.text(symbolLeft + price + symbolRight);
}else{
outputPrice.text(symbolLeft + basePrice + symbolRight);

}


})
2 changes: 1 addition & 1 deletion tmp/cache/0832c1202da8d382318e329a7c133ea0.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a:2:{s:4:"data";a:14:{i:1;a:5:{s:5:"title";s:3:"Men";s:5:"alias";s:3:"men";s:9:"parent_id";s:1:"0";s:8:"keywords";s:3:"Men";s:11:"description";s:3:"Men";}i:2;a:5:{s:5:"title";s:5:"Women";s:5:"alias";s:5:"women";s:9:"parent_id";s:1:"0";s:8:"keywords";s:5:"Women";s:11:"description";s:5:"Women";}i:3;a:5:{s:5:"title";s:4:"Kids";s:5:"alias";s:4:"kids";s:9:"parent_id";s:1:"0";s:8:"keywords";s:4:"Kids";s:11:"description";s:4:"Kids";}i:4;a:5:{s:5:"title";s:22:"Электронные";s:5:"alias";s:11:"elektronnye";s:9:"parent_id";s:1:"1";s:8:"keywords";s:22:"Электронные";s:11:"description";s:22:"Электронные";}i:5;a:5:{s:5:"title";s:24:"Механические";s:5:"alias";s:13:"mehanicheskie";s:9:"parent_id";s:1:"1";s:8:"keywords";s:13:"mehanicheskie";s:11:"description";s:13:"mehanicheskie";}i:6;a:5:{s:5:"title";s:5:"Casio";s:5:"alias";s:5:"casio";s:9:"parent_id";s:1:"4";s:8:"keywords";s:5:"Casio";s:11:"description";s:5:"Casio";}i:7;a:5:{s:5:"title";s:7:"Citizen";s:5:"alias";s:7:"citizen";s:9:"parent_id";s:1:"4";s:8:"keywords";s:7:"Citizen";s:11:"description";s:7:"Citizen";}i:8;a:5:{s:5:"title";s:12:"Royal London";s:5:"alias";s:12:"royal-london";s:9:"parent_id";s:1:"5";s:8:"keywords";s:12:"Royal London";s:11:"description";s:12:"Royal London";}i:9;a:5:{s:5:"title";s:5:"Seiko";s:5:"alias";s:5:"seiko";s:9:"parent_id";s:1:"5";s:8:"keywords";s:5:"Seiko";s:11:"description";s:5:"Seiko";}i:10;a:5:{s:5:"title";s:4:"Epos";s:5:"alias";s:4:"epos";s:9:"parent_id";s:1:"5";s:8:"keywords";s:4:"Epos";s:11:"description";s:4:"Epos";}i:11;a:5:{s:5:"title";s:22:"Электронные";s:5:"alias";s:14:"elektronnye-11";s:9:"parent_id";s:1:"2";s:8:"keywords";s:22:"Электронные";s:11:"description";s:22:"Электронные";}i:12;a:5:{s:5:"title";s:24:"Механические";s:5:"alias";s:16:"mehanicheskie-12";s:9:"parent_id";s:1:"2";s:8:"keywords";s:24:"Механические";s:11:"description";s:24:"Механические";}i:13;a:5:{s:5:"title";s:9:"Adriatica";s:5:"alias";s:9:"adriatica";s:9:"parent_id";s:2:"11";s:8:"keywords";s:9:"Adriatica";s:11:"description";s:9:"Adriatica";}i:14;a:5:{s:5:"title";s:10:"Anne Klein";s:5:"alias";s:10:"anne-klein";s:9:"parent_id";s:2:"12";s:8:"keywords";s:10:"Anne Klein";s:11:"description";s:10:"Anne Klein";}}s:8:"time_end";i:1597664554;}
a:2:{s:4:"data";a:14:{i:1;a:5:{s:5:"title";s:3:"Men";s:5:"alias";s:3:"men";s:9:"parent_id";s:1:"0";s:8:"keywords";s:3:"Men";s:11:"description";s:3:"Men";}i:2;a:5:{s:5:"title";s:5:"Women";s:5:"alias";s:5:"women";s:9:"parent_id";s:1:"0";s:8:"keywords";s:5:"Women";s:11:"description";s:5:"Women";}i:3;a:5:{s:5:"title";s:4:"Kids";s:5:"alias";s:4:"kids";s:9:"parent_id";s:1:"0";s:8:"keywords";s:4:"Kids";s:11:"description";s:4:"Kids";}i:4;a:5:{s:5:"title";s:22:"Электронные";s:5:"alias";s:11:"elektronnye";s:9:"parent_id";s:1:"1";s:8:"keywords";s:22:"Электронные";s:11:"description";s:22:"Электронные";}i:5;a:5:{s:5:"title";s:24:"Механические";s:5:"alias";s:13:"mehanicheskie";s:9:"parent_id";s:1:"1";s:8:"keywords";s:13:"mehanicheskie";s:11:"description";s:13:"mehanicheskie";}i:6;a:5:{s:5:"title";s:5:"Casio";s:5:"alias";s:5:"casio";s:9:"parent_id";s:1:"4";s:8:"keywords";s:5:"Casio";s:11:"description";s:5:"Casio";}i:7;a:5:{s:5:"title";s:7:"Citizen";s:5:"alias";s:7:"citizen";s:9:"parent_id";s:1:"4";s:8:"keywords";s:7:"Citizen";s:11:"description";s:7:"Citizen";}i:8;a:5:{s:5:"title";s:12:"Royal London";s:5:"alias";s:12:"royal-london";s:9:"parent_id";s:1:"5";s:8:"keywords";s:12:"Royal London";s:11:"description";s:12:"Royal London";}i:9;a:5:{s:5:"title";s:5:"Seiko";s:5:"alias";s:5:"seiko";s:9:"parent_id";s:1:"5";s:8:"keywords";s:5:"Seiko";s:11:"description";s:5:"Seiko";}i:10;a:5:{s:5:"title";s:4:"Epos";s:5:"alias";s:4:"epos";s:9:"parent_id";s:1:"5";s:8:"keywords";s:4:"Epos";s:11:"description";s:4:"Epos";}i:11;a:5:{s:5:"title";s:22:"Электронные";s:5:"alias";s:14:"elektronnye-11";s:9:"parent_id";s:1:"2";s:8:"keywords";s:22:"Электронные";s:11:"description";s:22:"Электронные";}i:12;a:5:{s:5:"title";s:24:"Механические";s:5:"alias";s:16:"mehanicheskie-12";s:9:"parent_id";s:1:"2";s:8:"keywords";s:24:"Механические";s:11:"description";s:24:"Механические";}i:13;a:5:{s:5:"title";s:9:"Adriatica";s:5:"alias";s:9:"adriatica";s:9:"parent_id";s:2:"11";s:8:"keywords";s:9:"Adriatica";s:11:"description";s:9:"Adriatica";}i:14;a:5:{s:5:"title";s:10:"Anne Klein";s:5:"alias";s:10:"anne-klein";s:9:"parent_id";s:2:"12";s:8:"keywords";s:10:"Anne Klein";s:11:"description";s:10:"Anne Klein";}}s:8:"time_end";i:1597752783;}
2 changes: 1 addition & 1 deletion tmp/cache/9297fd88a237b4c249515d1022b29f09.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ a:2:{s:4:"data";s:1435:"


</li>
";s:8:"time_end";i:1597664554;}
";s:8:"time_end";i:1597752783;}
Loading

0 comments on commit c2399ec

Please sign in to comment.