示例#1
0
 /**
  * @param Models\Price\Group $entity
  * @return Struct\Product\PriceGroup
  */
 public function convertPriceGroup(Models\Price\Group $entity)
 {
     $struct = new Struct\Product\PriceGroup();
     $struct->setId($entity->getId());
     $struct->setName($entity->getName());
     $discounts = array();
     foreach ($entity->getDiscounts() as $discountEntity) {
         $discount = new Struct\Product\PriceDiscount();
         $discount->setId($discountEntity->getId());
         $discount->setPercent($discountEntity->getDiscount());
         $discount->setQuantity($discountEntity->getStart());
         $discounts[] = $discount;
     }
     $struct->setDiscounts($discounts);
     return $struct;
 }
示例#2
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;
 }