Ejemplo n.º 1
0
 public function createPriceGroup($discounts = array())
 {
     if (empty($discounts)) {
         $discounts = array(array('key' => 'PHP', 'quantity' => 1, 'discount' => 10), array('key' => 'PHP', 'quantity' => 5, 'discount' => 20), array('key' => 'PHP', 'quantity' => 10, 'discount' => 30));
     }
     $this->removePriceGroup();
     $priceGroup = new Models\Price\Group();
     $priceGroup->setName('TEST-GROUP');
     $repo = $this->entityManager->getRepository('Shopware\\Models\\Customer\\Group');
     $collection = array();
     foreach ($discounts as $data) {
         $discount = new Models\Price\Discount();
         $discount->setCustomerGroup($repo->findOneBy(array('key' => $data['key'])));
         $discount->setGroup($priceGroup);
         $discount->setStart($data['quantity']);
         $discount->setDiscount($data['discount']);
         $collection[] = $discount;
     }
     $priceGroup->setDiscounts($collection);
     $this->entityManager->persist($priceGroup);
     $this->entityManager->flush();
     $this->entityManager->clear();
     return $priceGroup;
 }