Example #1
0
 /**
  * Helper function to save discounts for a given group.
  * @param array $discounts
  * @param \Shopware\Models\Customer\Group $group
  */
 private function saveDiscounts($discounts, $group)
 {
     $oldDiscounts = $group->getDiscounts();
     foreach ($oldDiscounts as $oldDiscount) {
         if (!in_array($oldDiscount, $discounts)) {
             $this->getManager()->remove($oldDiscount);
         }
     }
     $this->getManager()->flush();
     /** @var \Shopware\Models\Customer\Discount $discount */
     foreach ($discounts as $discount) {
         $discount->setGroup($group);
         $this->getManager()->persist($discount);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getDiscounts()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getDiscounts', array());
     return parent::getDiscounts();
 }