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);
     }
 }
Example #2
0
 /**
  * @param Models\Customer\Group $group
  * @return Struct\Customer\Group
  */
 public function convertCustomerGroup(Models\Customer\Group $group)
 {
     $customerGroup = new Struct\Customer\Group();
     $customerGroup->setKey($group->getKey());
     $customerGroup->setUseDiscount($group->getMode());
     $customerGroup->setId($group->getId());
     $customerGroup->setPercentageDiscount($group->getDiscount());
     $customerGroup->setDisplayGrossPrices($group->getTax());
     $customerGroup->setMinimumOrderValue($group->getMinimumOrder());
     $customerGroup->setSurcharge($group->getMinimumOrderSurcharge());
     return $customerGroup;
 }
Example #3
0
 public function createCustomerGroup($data = array())
 {
     $data = array_merge(array('key' => 'PHP', 'name' => 'Unit test', 'tax' => true, 'taxInput' => true, 'mode' => false, 'discount' => 0), $data);
     $this->deleteCustomerGroup($data['key']);
     $customer = new Models\Customer\Group();
     $customer->fromArray($data);
     $this->entityManager->persist($customer);
     $this->entityManager->flush($customer);
     $this->entityManager->clear();
     $this->createdCustomerGroups[] = $customer->getKey();
     return $customer;
 }
Example #4
0
 public function testCanCreateEntityWithNewGroup()
 {
     $this->em->clear();
     $groupKey = $this->generateRandomString(5);
     $group = new Group();
     $group->setKey($groupKey);
     $customer = new Customer();
     $customer->setGroup($group);
     $this->assertEmpty($customer->getId());
     $this->assertEquals($group, $customer->getGroup());
     $this->assertEmpty($customer->getGroup()->getId());
     $this->assertEquals($groupKey, $customer->getGroup()->getKey());
     return $customer;
 }
 /**
  * {@inheritDoc}
  */
 public function setManyToOne($data, $model, $property)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setManyToOne', array($data, $model, $property));
     return parent::setManyToOne($data, $model, $property);
 }