Esempio n. 1
0
 /**
  * @param Product $product
  * @return Basket
  */
 public function add(Product $product)
 {
     $basket = $this->session->get('basket', []);
     if (!array_key_exists($product->getId(), $basket)) {
         $basket[$product->getId()] = ['name' => $product->getName(), 'price' => $product->getPrice(), 'quantity' => 1];
     } else {
         $basket[$product->getId()]['quantity']++;
     }
     $this->session->set('basket', $basket);
     return $this;
 }
Esempio n. 2
0
 /**
  * @param Product  $product
  * @param int      $nbProduct
  * @param Currency $currency
  *
  * @return float
  */
 public function convertPrice(Product $product, $nbProduct = 1, Currency $currency = null)
 {
     if (!$currency instanceof Currency) {
         $currency = $this->basketManager->getCurrencyWanted();
     }
     $price = $product->getPrice() * $nbProduct;
     if ($currency->getCode() !== $product->getCurrency()->getCode()) {
         $rate = $this->ratesCaller->getRateFor($product->getCurrency(), $currency);
         $price = $rate * $price;
     }
     return $price;
 }
Esempio n. 3
0
 /**
  * Add product to basket
  *
  * @param Product $product
  * @return Basket
  */
 public function add(Product $product)
 {
     // get basket
     $basket = $this->session->get('basket', []);
     // Add or update product with basket
     if (!array_key_exists($product->getId(), $basket)) {
         $basket[$product->getId()] = ['name' => $product->getName(), 'price' => $product->getPrice(), 'quantity' => 1];
     } else {
         $basket[$product->getId()]['quantity']++;
     }
     // Set new basket session
     $this->session->set('basket', $basket);
     return $this;
 }
 private function generateProduct()
 {
     $product = new Product();
     $name = array();
     for ($i = 0; $i < rand(3, 6); $i++) {
         array_push($name, $this->genstr(rand(3, 8)));
     }
     $product->setName(implode(' ', $name));
     $product->setPrice(rand(32, 999) / 10);
     $product->setPriceDiscounted($product->getPrice() * 0.9);
     $product->setSoldNo(rand(0, 500));
     $product->setUpdateAt($this->rand_date('2013-01-01', '2015-10-06'));
     $product->setBrand($this->genstr(rand(3, 8)));
     $product->setInventory(rand(0, 200));
     $product->setDescription($this->genstr(rand(3, 8)) . ' ' . $this->genstr(rand(3, 8)) . ' ' . $this->genstr(rand(3, 8)));
     $product->setProductKey(substr(uniqid(), 0, 10));
     $product->setWeight(rand(0, 1200));
     $product->setClick(rand(0, 1000));
     $product->setImageLink(uniqid());
     return $product;
 }
 /**
  * {@inheritDoc}
  */
 public function getPrice()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getPrice', array());
     return parent::getPrice();
 }
Esempio n. 6
0
 /**
  * @Given /^supplier "([^"]*)" exists with product:$/
  */
 public function supplierExistsWithProduct($name, TableNode $table)
 {
     $data = $table->getRowsHash();
     $supplier = $this->supplierExists($name);
     $product = new Product($data['Name'], (double) $data['Price'], $supplier);
     if (isset($data['Description'])) {
         $product->setDescription($data['Description']);
     }
     var_dump($product->getPrice());
     $this->getEntityManager()->persist($product);
     $this->getEntityManager()->flush();
     $this->getParameterBag()->set('product', $product);
 }
 /**
  * Return the total price (tax included).
  *
  * @return float
  */
 public function getTotalPrice()
 {
     return $this->product->getPrice() * $this->quantity * (1 + $this->taxRate);
 }