Пример #1
0
 /**
  * @param Customer $entity
  */
 protected function processChangeAttributes(Customer $entity)
 {
     foreach ($entity->getAddresses() as $address) {
         $address->setOriginId(null);
     }
     $entity->setWebsite($entity->getStore()->getWebsite());
     $this->setDefaultGroup($entity);
 }
Пример #2
0
 /**
  * @param $firstName
  * @param $lastname
  */
 protected function createCustomer($firstName, $lastname)
 {
     $customer = new Customer();
     $customer->setChannel($this->getReference('integration'));
     $customer->setDataChannel($this->getReference('default_channel'));
     $customer->setFirstName($firstName);
     $customer->setLastName($lastname);
     $customer->setEmail(strtolower($firstName . '_' . $lastname . '@example.com'));
     $customer->setIsActive(true);
     $customer->setWebsite($this->getReference('website'));
     $customer->setStore($this->getReference('store'));
     $customer->setAccount($this->getReference('account'));
     $customer->setGender(Gender::MALE);
     $customer->setGroup($this->getReference('customer_group'));
     $customer->setCreatedAt(new \DateTime('now'));
     $customer->setUpdatedAt(new \DateTime('now'));
     $customer->setOwner($this->user);
     $customer->setOrganization($this->organization);
     $this->em->persist($customer);
 }
Пример #3
0
 /**
  * @param                $oid
  * @param Account        $account
  * @param MagentoAddress $address
  *
  * @return Customer
  */
 protected function createCustomer($oid, Account $account, MagentoAddress $address)
 {
     $customer = new Customer();
     $customer->setChannel($this->integration);
     $customer->setDataChannel($this->channel);
     $customer->setFirstName('John');
     $customer->setLastName('Doe');
     $customer->setEmail('*****@*****.**');
     $customer->setOriginId($oid);
     $customer->setIsActive(true);
     $customer->setWebsite($this->website);
     $customer->setStore($this->store);
     $customer->setAccount($account);
     $customer->setGender(Gender::MALE);
     $customer->setGroup($this->customerGroup);
     $customer->setCreatedAt(new \DateTime('now'));
     $customer->setUpdatedAt(new \DateTime('now'));
     $customer->addAddress($address);
     $customer->setOwner($this->getUser());
     $customer->setOrganization($this->organization);
     $this->em->persist($customer);
     return $customer;
 }
Пример #4
0
 /**
  * Update $entity with new data from imported $store, $website, $group
  *
  * @param Customer      $entity
  * @param Store         $store
  * @param Website       $website
  * @param CustomerGroup $group
  *
  * @return $this
  */
 protected function updateStoresAndGroup(Customer $entity, Store $store, Website $website, CustomerGroup $group)
 {
     // do not allow to change code/website name by imported entity
     $doNotUpdateFields = ['id', 'code', 'name'];
     if (!isset($this->websiteEntityCache[$website->getCode()])) {
         $this->websiteEntityCache[$website->getCode()] = $this->findAndReplaceEntity($website, MagentoConnectorInterface::WEBSITE_TYPE, ['code' => $website->getCode(), 'channel' => $website->getChannel(), 'originId' => $website->getOriginId()], $doNotUpdateFields);
     }
     $this->websiteEntityCache[$website->getCode()] = $this->merge($this->websiteEntityCache[$website->getCode()]);
     if (!isset($this->storeEntityCache[$store->getCode()])) {
         $this->storeEntityCache[$store->getCode()] = $this->findAndReplaceEntity($store, MagentoConnectorInterface::STORE_TYPE, ['code' => $store->getCode(), 'channel' => $store->getChannel(), 'originId' => $store->getOriginId()], $doNotUpdateFields);
     }
     $this->storeEntityCache[$store->getCode()] = $this->merge($this->storeEntityCache[$store->getCode()]);
     if (!isset($this->groupEntityCache[$group->getName()])) {
         $this->groupEntityCache[$group->getName()] = $this->findAndReplaceEntity($group, MagentoConnectorInterface::CUSTOMER_GROUPS_TYPE, ['name' => $group->getName(), 'channel' => $group->getChannel(), 'originId' => $group->getOriginId()], $doNotUpdateFields);
     }
     $this->groupEntityCache[$group->getName()] = $this->merge($this->groupEntityCache[$group->getName()]);
     $entity->setWebsite($this->websiteEntityCache[$website->getCode()])->setStore($this->storeEntityCache[$store->getCode()])->setGroup($this->groupEntityCache[$group->getName()]);
     $entity->getStore()->setWebsite($entity->getWebsite());
 }
Пример #5
0
 /**
  * @param                $oid
  * @param Account        $account
  * @param MagentoAddress $address
  *
  * @return Customer
  */
 protected function createCustomer($oid, Account $account, MagentoAddress $address)
 {
     $customer = new Customer();
     $customer->setChannel($this->integration);
     $customer->setDataChannel($this->channel);
     $customer->setFirstName('John');
     $customer->setLastName('Doe');
     $customer->setEmail('*****@*****.**');
     $customer->setOriginId($oid);
     $customer->setIsActive(true);
     $customer->setWebsite($this->website);
     $customer->setStore($this->store);
     $customer->setAccount($account);
     $customer->setGender(Gender::MALE);
     $customer->setGroup($this->customerGroup);
     // TODO: DateTimeZones should be removed in BAP-8710. Tests should be passed for:
     //  - OroCRM\Bundle\MagentoBundle\Tests\Functional\Controller\Api\Rest\CustomerControllerTest
     //  - OroCRM\Bundle\MagentoBundle\Tests\Functional\Controller\Api\Rest\MagentoCustomerControllerTest
     $customer->setCreatedAt(new \DateTime('now', new \DateTimezone('UTC')));
     $customer->setUpdatedAt(new \DateTime('now', new \DateTimezone('UTC')));
     $customer->addAddress($address);
     $customer->setOwner($this->getUser());
     $customer->setOrganization($this->organization);
     $this->em->persist($customer);
     return $customer;
 }
Пример #6
0
 /**
  * @param ObjectManager $om
  * @param Website       $website
  * @param Store         $store
  * @param CustomerGroup $group
  * @param Integration   $integration
  */
 protected function persistDemoCustomers(ObjectManager $om, Website $website, Store $store, CustomerGroup $group, Integration $integration)
 {
     $accounts = $om->getRepository('OroCRMAccountBundle:Account')->findAll();
     $contacts = $om->getRepository('OroCRMContactBundle:Contact')->findAll();
     $buffer = range(0, 48);
     shuffle($buffer);
     for ($i = 0; $i < 49; ++$i) {
         $birthday = $this->generateBirthday();
         /** @var Contact $contact */
         $contact = $contacts[$buffer[$i]];
         $customer = new Customer();
         if (is_null($accounts[$buffer[$i]])) {
             var_dump($buffer[$i]);
         }
         $customer->setWebsite($website)->setChannel($integration)->setStore($store)->setFirstName($contact->getFirstName())->setLastName($contact->getLastName())->setEmail($contact->getPrimaryEmail())->setBirthday($birthday)->setVat(self::VAT)->setGroup($group)->setCreatedAt(new \DateTime('now'))->setUpdatedAt(new \DateTime('now'))->setOriginId($i + 1)->setAccount($accounts[$buffer[$i]])->setContact($contact)->setOrganization($this->organization)->setOwner($this->getRandomOwner());
         $customer->setDataChannel($this->dataChannel);
         $om->persist($customer);
     }
 }
Пример #7
0
 protected function setWebsite(Customer $object, array $data, $format = null, array $context = array())
 {
     /** @var Website $website */
     $website = $this->denormalizeObject($data, 'website', MagentoConnectorInterface::WEBSITE_TYPE, $format, $context);
     if ($website) {
         $website->setChannel($object->getChannel());
         $object->setWebsite($website);
     }
 }