+
diff --git a/assets/js/parts/main.js b/assets/js/parts/main.js
index ab440ea8..6bad2032 100644
--- a/assets/js/parts/main.js
+++ b/assets/js/parts/main.js
@@ -9,8 +9,15 @@ angular
{id: 3, name: "truc 3", price: 4, category: 2},
{id: 4, name: "truc 4", price: 1, category: 2},
];
+ $scope.categories = [];
+ $scope.recentSellings = [];
$scope.pausedSelling = [];
$scope.activeSelling = [];
+ $scope.activeFestival = {
+ name : "le festival",
+ dateCreation: new Date(),
+ commentaire : ""
+ };
$scope.CurrentSellingTotal = $scope.activeSelling.reduce(function (a, b) {
return a + b.price;
}, 0);
@@ -22,18 +29,16 @@ angular
$scope.pauseSelling = function (selling) {
$scope.pausedSelling.push(selling);
};
- $scope.addProduct = function (id) {
- let found = $scope.productsFromDB.find({id: id});
- if (found) {
- $scope.productsToRecord.push(found);
- }
+ $scope.addProduct = function (product) {
+ $scope.activeSelling.push(product);
};
$scope.fetchProductsFromDB = function () {
console.log('fetch products...');
- $http.get('get-my-products').then((data) => {
+ $http.get('get-my-products').then((rep) => {
- console.log('ok');
- $scope.productsFromDB = data;
+ console.log('ok', rep);
+ $scope.categories = rep.data.categories;
+ $scope.recentSellings = rep.data.history;
}, (err) => {
console.log(err);
});
@@ -45,7 +50,10 @@ angular
console.log('log test ok');
};
$scope.sendForm = function () {
- let lesParams = {};
+ let lesParams = {
+ activeSelling : $scope.activeSelling,
+ activeFestival: $scope.activeFestival
+ };
$http({
method: 'POST',
url : '/add-selling',
diff --git a/src/AppBundle/Controller/DefaultController.php b/src/AppBundle/Controller/DefaultController.php
index ca6f4e01..7721983f 100644
--- a/src/AppBundle/Controller/DefaultController.php
+++ b/src/AppBundle/Controller/DefaultController.php
@@ -56,22 +56,53 @@ class DefaultController extends Controller {
] );
}
+ /**
+ * get user products
+ * @return JsonResponse
+ */
public function getMyProductsAction() {
$m = $this->getDoctrine()->getManager();
$currentUser = $this->getUser();
if ( ! $currentUser ) {
return new JsonResponse( [
'categories' => [ [ 'name' => 'demo category', 'products' => [] ] ],
- 'recentSells' => [['']],
+ 'recentSells' => [ [ '' ] ],
] );
}
$categRepo = $m->getRepository( 'AppBundle:ProductCategory' );
$sellingRepo = $m->getRepository( 'AppBundle:SellRecord' );
$categories = $currentUser->getCategories();
- if ( ! $categories ) {
- $defaultCategories = $categRepo->find( [ 1, 2 ] );
+ if ( ! count( $categories ) ) {
+ $categories = $defaultCategories = $categRepo->findById( [ 1, 2 ] );
$currentUser->setCategories( $defaultCategories );
+ $m->persist( $currentUser );
}
+ $serializedCategories = [];
+
+ foreach ( $categories as $category ) {
+ $products = $category->getProducts();
+ if ( $products ) {
+ $listOfProductsInArray = [];
+ foreach ( $products as $product ) {
+ $listOfProductsInArray[] = [
+ 'id' => $product->getId(),
+ 'name' => $product->getName(),
+ 'category' => $category->getId(),
+ 'price' => 1 * $product->getPrice(),
+ ];
+ }
+ $products = $listOfProductsInArray;
+ }
+ $serializedCategories[] =
+ [
+ 'id' => $category->getId(),
+ 'name' => $category->getName(),
+ 'products' => $products ? $products : null,
+ ];
+
+ }
+ $categories = $serializedCategories;
+
$recentSells = $sellingRepo->findBy( [ 'user' => $currentUser->getId() ], [ 'id' => 'desc' ], 0, 5 );
return new JsonResponse( [
diff --git a/src/AppBundle/Entity/ProductSold.php b/src/AppBundle/Entity/ProductSold.php
index 70104343..1e216848 100644
--- a/src/AppBundle/Entity/ProductSold.php
+++ b/src/AppBundle/Entity/ProductSold.php
@@ -10,8 +10,12 @@ use Doctrine\ORM\Mapping as ORM;
class ProductSold extends Product {
/**
- * @ORM\OneToMany(targetEntity="SellRecord", mappedBy="products")
+ * @ORM\ManyToOne(targetEntity="SellRecord", inversedBy="productsSold")
*/
private $sellRecords;
+ /**
+ * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="productsSold")
+ */
+ private $user;
}
diff --git a/src/AppBundle/Entity/SellRecord.php b/src/AppBundle/Entity/SellRecord.php
index 07315901..0592e12a 100644
--- a/src/AppBundle/Entity/SellRecord.php
+++ b/src/AppBundle/Entity/SellRecord.php
@@ -9,10 +9,12 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Entity(repositoryClass="AppBundle\Repository\SellRecordRepository")
*/
class SellRecord {
+
+ use Commentable;
/**
- * @ORM\ManyToOne(targetEntity="Product", inversedBy="sellRecords")
+ * @ORM\OneToMany(targetEntity="AppBundle\Entity\ProductSold", mappedBy="sellRecords")
*/
- private $products;
+ private $productsSold;
/**
* @ORM\Id
@@ -36,9 +38,40 @@ class SellRecord {
*/
private $festival;
- use Commentable;
+ /**
+ * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="sellRecords")
+ */
+ private $user;
+ /**
+ * @return mixed
+ */
+ public function getComment() {
+ return $this->comment;
+ }
+
+ /**
+ * @param mixed $comment
+ */
+ public function setComment( $comment ) {
+ $this->comment = $comment;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getProductsSold() {
+ return $this->productsSold;
+ }
+
+ /**
+ * @param mixed $productsSold
+ */
+ public function setProductsSold( $productsSold ) {
+ $this->productsSold = $productsSold;
+ }
+
/**
* @return mixed
*/
@@ -54,11 +87,6 @@ class SellRecord {
}
- /**
- * @ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="products")
- */
- private $user;
-
/**
* @return mixed
*/
diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php
index 96869db8..2dc815d4 100644
--- a/src/AppBundle/Entity/User.php
+++ b/src/AppBundle/Entity/User.php
@@ -29,13 +29,36 @@ class User extends BaseUser {
private $googleAccessToken;
/**
+ * templates products
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Product", mappedBy="user")
*/
private $products;
+
/**
+ * variabilised products sold
* @ORM\OneToMany(targetEntity="AppBundle\Entity\ProductSold", mappedBy="user")
*/
private $productsSold;
+
+ /**
+ * @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", inversedBy="users")
+ */
+ private $categories;
+
+ /**
+ * @return mixed
+ */
+ public function getProductsSold() {
+ return $this->productsSold;
+ }
+
+ /**
+ * @param mixed $productsSold
+ */
+ public function setProductsSold( $productsSold ) {
+ $this->productsSold = $productsSold;
+ }
+
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\SellRecord", mappedBy="user")
*/
@@ -83,11 +106,6 @@ class User extends BaseUser {
$this->products = $products;
}
- /**
- * @ORM\ManyToMany(targetEntity="AppBundle\Entity\ProductCategory", mappedBy="user")
- */
- private $categories;
-
/**
* @return mixed
*/