Пример #1
0
 /**
  * Allow to set password only for new customer.
  * Allow to set password for existing customer if Oro Bridge extension is installed.
  *
  * @param Customer|null $data
  * @return bool
  */
 protected function isPasswordSetAllowed($data)
 {
     if ($data && $data instanceof Customer && $data->getChannel() && $data->getChannel()->getTransport()) {
         /** @var MagentoSoapTransport $transport */
         $transport = $data->getChannel()->getTransport();
         return !$data->getId() || $transport->isSupportedExtensionVersion();
     }
     return true;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 protected function getPermissionForAttribute($class, $identifier, $attribute)
 {
     if (is_a($this->object, $this->className, true) && ($attribute === self::ATTRIBUTE_EDIT && (!$this->object->getOriginId() && !$this->object->isGuest()))) {
         return self::ACCESS_DENIED;
     }
     if (is_a($this->object, $this->className, true) && $this->object->getChannel() && !$this->settingsProvider->isChannelApplicable($this->object->getChannel()->getId(), false)) {
         return self::ACCESS_DENIED;
     }
     if (!$this->settingsProvider->hasApplicableChannels(false)) {
         return self::ACCESS_DENIED;
     }
     return self::ACCESS_ABSTAIN;
 }
Пример #3
0
 /**
  * @param Customer $entity
  */
 protected function setDefaultGroup(Customer $entity)
 {
     if (!$entity->getGroup() && $entity->getWebsite()->getDefaultGroupId()) {
         $em = $this->strategyHelper->getEntityManager('OroCRMMagentoBundle:CustomerGroup');
         $group = $em->getRepository('OroCRMMagentoBundle:CustomerGroup')->findOneBy(['originId' => $entity->getWebsite()->getDefaultGroupId(), 'channel' => $entity->getChannel()]);
         $entity->setGroup($group);
     }
 }
 /**
  * @param Customer $value
  * @return array
  */
 protected function getRemoteCustomers($value)
 {
     $this->transport->init($value->getChannel()->getTransport());
     $filter = new BatchFilterBag();
     $filter->addComplexFilter('email', ['key' => 'email', 'value' => ['key' => 'eq', 'value' => $value->getEmail()]]);
     $filter->addComplexFilter('store_id', ['key' => 'store_id', 'value' => ['key' => 'eq', 'value' => $value->getStore()->getOriginId()]]);
     $filters = $filter->getAppliedFilters();
     $customers = $this->transport->call(SoapTransport::ACTION_CUSTOMER_LIST, $filters);
     return (array) $customers;
 }
Пример #5
0
 /**
  * @Route(
  *   "/customer_sync/{id}",
  *   name="orocrm_magento_orderplace_new_customer_order_sync", requirements={"id"="\d+"})
  * )
  * @AclAncestor("oro_workflow")
  * @param Customer $customer
  * @return JsonResponse
  */
 public function customerSyncAction(Customer $customer)
 {
     $em = $this->get('doctrine.orm.entity_manager');
     try {
         $isOrderLoaded = $this->loadOrderInformation($customer->getChannel(), ['filters' => ['customer_id' => $customer->getOriginId()]]);
         if (!$isOrderLoaded) {
             throw new \LogicException('Unable to load order.');
         }
         $order = $em->getRepository('OroCRMMagentoBundle:Order')->getLastPlacedOrderBy($customer, 'customer');
         if (null === $order) {
             throw new \LogicException('Unable to load order.');
         }
         $redirectUrl = $this->generateUrl('orocrm_magento_order_view', ['id' => $order->getId()]);
         $message = $this->get('translator')->trans('orocrm.magento.controller.synchronization_success');
         $status = self::SYNC_SUCCESS;
     } catch (\Exception $e) {
         $redirectUrl = $this->generateUrl('orocrm_magento_customer_view', ['id' => $customer->getId()]);
         $message = $this->get('translator')->trans('orocrm.magento.controller.sync_error_with_magento');
         $status = self::SYNC_ERROR;
     }
     return new JsonResponse(['statusType' => $status, 'message' => $message, 'url' => $redirectUrl]);
 }
Пример #6
0
 /**
  * Update $entity with new contact data
  *
  * @param Customer $remoteData
  * @param Customer $localData
  * @param Contact  $contact
  */
 protected function updateContact(Customer $remoteData, Customer $localData, Contact $contact)
 {
     $helper = new ContactImportHelper($localData->getChannel(), $this->addressHelper);
     if ($localData->getContact() && $localData->getContact()->getId()) {
         $helper->merge($remoteData, $localData, $localData->getContact());
     } else {
         $addresses = $localData->getAddresses();
         // loop by imported addresses, add new only
         /** @var \OroCRM\Bundle\ContactBundle\Entity\ContactAddress $address */
         foreach ($contact->getAddresses() as $key => $address) {
             $helper->prepareAddress($address);
             if (!$address->getCountry()) {
                 $contact->removeAddress($address);
                 continue;
             }
             // @TODO find possible solution
             // guess parent address by key
             if ($entity = $addresses->get($key)) {
                 $entity->setContactAddress($address);
             }
         }
         // @TODO find possible solution
         // guess parent $phone by key
         foreach ($contact->getPhones() as $key => $phone) {
             $contactPhone = $this->getContactPhoneFromContact($contact, $phone);
             if ($entity = $addresses->get($key)) {
                 $entity->setContactPhone($contactPhone ? $contactPhone : $phone);
             }
         }
         // populate default owner only for new contacts
         $this->defaultOwnerHelper->populateChannelOwner($contact, $localData->getChannel());
         $localData->setContact($contact);
     }
 }
Пример #7
0
 /**
  * @param Customer $magentoCustomer
  *
  * @return bool
  */
 protected function isTwoWaySyncEnabled($magentoCustomer)
 {
     return $magentoCustomer && $magentoCustomer->getChannel()->getSynchronizationSettings()->offsetGetOr('isTwoWaySyncEnabled', false) && $magentoCustomer->getChannel()->getEnabled();
 }
Пример #8
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);
     }
 }