init
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Api;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaInterface;
|
||||
|
||||
interface AvatrRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Save Avatr
|
||||
* @param \Stemcell\Customer\Api\Data\AvatrInterface $avatr
|
||||
* @return \Stemcell\Customer\Api\Data\AvatrInterface
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function save(
|
||||
\Stemcell\Customer\Api\Data\AvatrInterface $avatr
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve Avatr
|
||||
* @param string $avatrId
|
||||
* @return \Stemcell\Customer\Api\Data\AvatrInterface
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function get($avatrId);
|
||||
|
||||
/**
|
||||
* Retrieve Clue
|
||||
* @param string $telephone
|
||||
* @param string $model
|
||||
* @return \Stemcell\Customer\Api\Data\AvatrInterface
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function getByTelephone(string $telephone, string $model): Data\AvatrInterface;
|
||||
|
||||
/**
|
||||
* Retrieve Avatr matching the specified criteria.
|
||||
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
|
||||
* @return \Stemcell\Customer\Api\Data\AvatrSearchResultsInterface
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function getList(
|
||||
\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
|
||||
);
|
||||
|
||||
/**
|
||||
* Delete Avatr
|
||||
* @param \Stemcell\Customer\Api\Data\AvatrInterface $avatr
|
||||
* @return bool true on success
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function delete(
|
||||
\Stemcell\Customer\Api\Data\AvatrInterface $avatr
|
||||
);
|
||||
|
||||
/**
|
||||
* Delete Avatr by ID
|
||||
* @param string $avatrId
|
||||
* @return bool true on success
|
||||
* @throws \Magento\Framework\Exception\NoSuchEntityException
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function deleteById($avatrId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Api\Data;
|
||||
|
||||
interface AddressInterface extends \Magento\Customer\Api\Data\AddressInterface
|
||||
{
|
||||
const CITY_CODE = 'city_code';
|
||||
|
||||
const DISTRICT = 'district';
|
||||
|
||||
const DISTRICT_CODE = 'district_code';
|
||||
|
||||
const TOWN = 'town';
|
||||
|
||||
const TOWN_CODE = 'town_code';
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Api\Data;
|
||||
|
||||
interface AvatrInterface
|
||||
{
|
||||
|
||||
const PROVINCE_ID = 'province_id';
|
||||
const IS_SENT = 'is_sent';
|
||||
const TELEPHONE = 'telephone';
|
||||
const NAME = 'name';
|
||||
const FAVORITE_VEHICLE = 'favorite_vehicle';
|
||||
const CITY_ID = 'city_id';
|
||||
|
||||
const RESPONSE = 'response';
|
||||
|
||||
const CREATED_AT = 'created_at';
|
||||
|
||||
/**
|
||||
* Get name
|
||||
* @return string|null
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Set name
|
||||
* @param string $name
|
||||
* @return \Stemcell\Customer\Avatr\Api\Data\AvatrInterface
|
||||
*/
|
||||
public function setName($name);
|
||||
|
||||
/**
|
||||
* Get telephone
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTelephone();
|
||||
|
||||
/**
|
||||
* Set telephone
|
||||
* @param string $telephone
|
||||
* @return \Stemcell\Customer\Avatr\Api\Data\AvatrInterface
|
||||
*/
|
||||
public function setTelephone($telephone);
|
||||
|
||||
/**
|
||||
* Get favorite_vehicle
|
||||
* @return string|null
|
||||
*/
|
||||
public function getFavoriteVehicle();
|
||||
|
||||
/**
|
||||
* Set favorite_vehicle
|
||||
* @param string $favoriteVehicle
|
||||
* @return \Stemcell\Customer\Avatr\Api\Data\AvatrInterface
|
||||
*/
|
||||
public function setFavoriteVehicle($favoriteVehicle);
|
||||
|
||||
/**
|
||||
* Get province_id
|
||||
* @return string|null
|
||||
*/
|
||||
public function getProvinceId();
|
||||
|
||||
/**
|
||||
* Set province_id
|
||||
* @param string $provinceId
|
||||
* @return \Stemcell\Customer\Avatr\Api\Data\AvatrInterface
|
||||
*/
|
||||
public function setProvinceId($provinceId);
|
||||
|
||||
/**
|
||||
* Get city_id
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCityId();
|
||||
|
||||
/**
|
||||
* Set city_id
|
||||
* @param string $cityId
|
||||
* @return \Stemcell\Customer\Avatr\Api\Data\AvatrInterface
|
||||
*/
|
||||
public function setCityId($cityId);
|
||||
|
||||
/**
|
||||
* Get is_sent
|
||||
* @return string|null
|
||||
*/
|
||||
public function getIsSent();
|
||||
|
||||
/**
|
||||
* Set is_sent
|
||||
* @param string $isSent
|
||||
* @return \Stemcell\Customer\Avatr\Api\Data\AvatrInterface
|
||||
*/
|
||||
public function setIsSent($isSent);
|
||||
|
||||
/**
|
||||
* @param string $isSent
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCreatedAt();
|
||||
|
||||
/**
|
||||
* Get is_sent
|
||||
* @return string|null
|
||||
*/
|
||||
public function getResponse();
|
||||
|
||||
/**
|
||||
* Set is_sent
|
||||
* @param string $response
|
||||
* @return \Stemcell\Customer\Avatr\Api\Data\AvatrInterface
|
||||
*/
|
||||
public function setResponse(string $response);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Api\Data;
|
||||
|
||||
interface AvatrSearchResultsInterface extends \Magento\Framework\Api\SearchResultsInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Get Avatr list.
|
||||
* @return \Stemcell\Customer\Api\Data\AvatrInterface[]
|
||||
*/
|
||||
public function getItems();
|
||||
|
||||
/**
|
||||
* Set id list.
|
||||
* @param \Stemcell\Customer\Api\Data\AvatrInterface[] $items
|
||||
* @return $this
|
||||
*/
|
||||
public function setItems(array $items);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Api\Data\Http;
|
||||
|
||||
interface JsonResponse {
|
||||
|
||||
public function setErrors(bool $status) : self;
|
||||
|
||||
public function getErrors() : bool;
|
||||
|
||||
public function setMessages(array $status) : self;
|
||||
|
||||
public function getMessages() : array;
|
||||
|
||||
public function setData(array $data) : self;
|
||||
|
||||
public function toArray(array $keys = []) : array;
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Api\Data;
|
||||
|
||||
interface LabInterface
|
||||
{
|
||||
const LAB_ID = 'lab_id';
|
||||
const IS_ACTIVE = 'is_active';
|
||||
const BOOKING_ACCOUNT = 'booking_account';
|
||||
const PI_SAP_ID = 'pi_sap_id';
|
||||
const VENDOR_NAME = 'customer_id';
|
||||
const LAB_CODE = 'lab_code';
|
||||
|
||||
const SALESPERSON_ID = 'salesperson_id';
|
||||
|
||||
|
||||
/**
|
||||
* Get lab_code
|
||||
* @return int|null
|
||||
*/
|
||||
public function getLabId();
|
||||
|
||||
/**
|
||||
* Set lab_code
|
||||
* @param int $labId
|
||||
* @return self
|
||||
*/
|
||||
public function setLabId(int $labId);
|
||||
/**
|
||||
* Get lab_code
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLabCode();
|
||||
|
||||
/**
|
||||
* Set lab_code
|
||||
* @param string $labCode
|
||||
* @return self
|
||||
*/
|
||||
public function setLabCode($labCode);
|
||||
|
||||
/**
|
||||
* Get booking_account
|
||||
* @return string|null
|
||||
*/
|
||||
public function getBookingAccount();
|
||||
|
||||
/**
|
||||
* Set booking_account
|
||||
* @param string $bookingAccount
|
||||
* @return self
|
||||
*/
|
||||
public function setBookingAccount($bookingAccount);
|
||||
|
||||
/**
|
||||
* Get pi_sap_id
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPiSapId();
|
||||
|
||||
/**
|
||||
* Set pi_sap_id
|
||||
* @param string $piSapId
|
||||
* @return self
|
||||
*/
|
||||
public function setPiSapId($piSapId);
|
||||
|
||||
/**
|
||||
* Get vendor_name
|
||||
* @return int|null
|
||||
*/
|
||||
public function getVendorName();
|
||||
|
||||
/**
|
||||
* Set vendor_name
|
||||
* @param int $vendorName
|
||||
* @return self
|
||||
*/
|
||||
public function setVendorName($vendorName);
|
||||
|
||||
/**
|
||||
* Get is_active
|
||||
* @return string|null
|
||||
*/
|
||||
public function getIsActive();
|
||||
|
||||
/**
|
||||
* Set is_active
|
||||
* @param string $isActive
|
||||
* @return self
|
||||
*/
|
||||
public function setIsActive($isActive);
|
||||
|
||||
/**
|
||||
* @param int $salespersonId
|
||||
* @return self
|
||||
*/
|
||||
public function setSalespersonId(int $salespersonId): LabInterface;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getSalespersonId();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Api\Data;
|
||||
|
||||
interface LabSearchResultsInterface extends \Magento\Framework\Api\SearchResultsInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Get Lab list.
|
||||
* @return \Stemcell\Customer\Api\Data\LabInterface[]
|
||||
*/
|
||||
public function getItems();
|
||||
|
||||
/**
|
||||
* Set lab_id list.
|
||||
* @param \Stemcell\Customer\Api\Data\LabInterface[] $items
|
||||
* @return $this
|
||||
*/
|
||||
public function setItems(array $items);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Api\Data;
|
||||
|
||||
interface SalespersonInterface
|
||||
{
|
||||
const SALESPERSON_ID = 'salesperson_id';
|
||||
const IS_ACTIVE = 'is_active';
|
||||
const TELEPHONE = 'telephone';
|
||||
const NAME = 'name';
|
||||
const EMAIL = 'email';
|
||||
const CSR_EMAIL = 'csr_email';
|
||||
const SISR_EMAIL = 'sisr_email';
|
||||
const RSM_EMAIL = 'rsm_email';
|
||||
|
||||
/**
|
||||
* Get name
|
||||
* @return int|null
|
||||
*/
|
||||
public function getSalespersonId();
|
||||
|
||||
/**
|
||||
* Set name
|
||||
* @param int $salespersonId
|
||||
* @return self
|
||||
*/
|
||||
public function setSalespersonId($salespersonId);
|
||||
|
||||
/**
|
||||
* Get name
|
||||
* @return string|null
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Set name
|
||||
* @param string $name
|
||||
* @return self
|
||||
*/
|
||||
public function setName($name);
|
||||
|
||||
/**
|
||||
* Get email
|
||||
* @return string|null
|
||||
*/
|
||||
public function getEmail();
|
||||
|
||||
/**
|
||||
* Set email
|
||||
* @param string $email
|
||||
* @return self
|
||||
*/
|
||||
public function setEmail($email);
|
||||
|
||||
/**
|
||||
* Get telephone
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTelephone();
|
||||
|
||||
/**
|
||||
* Set telephone
|
||||
* @param string $telephone
|
||||
* @return self
|
||||
*/
|
||||
public function setTelephone($telephone);
|
||||
|
||||
/**
|
||||
* Get rsm_email
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRsmEmail();
|
||||
|
||||
/**
|
||||
* Set rsm_email
|
||||
* @param string $rsmEmail
|
||||
* @return self
|
||||
*/
|
||||
public function setRsmEmail($rsmEmail);
|
||||
|
||||
/**
|
||||
* Get sisr_email
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSisrEmail();
|
||||
|
||||
/**
|
||||
* Set sisr_email
|
||||
* @param string $sisrEmail
|
||||
* @return self
|
||||
*/
|
||||
public function setSisrEmail($sisrEmail);
|
||||
|
||||
/**
|
||||
* Get csr_email
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCsrEmail();
|
||||
|
||||
/**
|
||||
* Set csr_email
|
||||
* @param string $csrEmail
|
||||
* @return self
|
||||
*/
|
||||
public function setCsrEmail($csrEmail);
|
||||
|
||||
/**
|
||||
* Get is_active
|
||||
* @return string|null
|
||||
*/
|
||||
public function getIsActive();
|
||||
|
||||
/**
|
||||
* Set is_active
|
||||
* @param string $isActive
|
||||
* @return self
|
||||
*/
|
||||
public function setIsActive($isActive);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Api\Data;
|
||||
|
||||
interface SalespersonSearchResultsInterface extends \Magento\Framework\Api\SearchResultsInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Get Salesperson list.
|
||||
* @return \Stemcell\Customer\Api\Data\SalespersonInterface[]
|
||||
*/
|
||||
public function getItems();
|
||||
|
||||
/**
|
||||
* Set salesperson_id list.
|
||||
* @param \Stemcell\Customer\Api\Data\SalespersonInterface[] $items
|
||||
* @return $this
|
||||
*/
|
||||
public function setItems(array $items);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Api;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Stemcell\Customer\Api\Data\LabInterface;
|
||||
use Stemcell\Customer\Model\ResourceModel\Lab;
|
||||
|
||||
interface LabRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Save Lab
|
||||
* @param \Stemcell\Customer\Api\Data\LabInterface $lab
|
||||
* @return \Stemcell\Customer\Api\Data\LabInterface
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function save(
|
||||
\Stemcell\Customer\Api\Data\LabInterface $lab
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve Lab
|
||||
* @param string $labId
|
||||
* @return \Stemcell\Customer\Api\Data\LabInterface
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function get($labId);
|
||||
|
||||
/**
|
||||
* Retrieve Lab matching the specified criteria.
|
||||
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
|
||||
* @return \Stemcell\Customer\Api\Data\LabSearchResultsInterface
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function getList(
|
||||
\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
|
||||
);
|
||||
|
||||
/**
|
||||
* Delete Lab
|
||||
* @param \Stemcell\Customer\Api\Data\LabInterface $lab
|
||||
* @return bool true on success
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function delete(
|
||||
\Stemcell\Customer\Api\Data\LabInterface $lab
|
||||
);
|
||||
|
||||
/**
|
||||
* Delete Lab by ID
|
||||
* @param string $labId
|
||||
* @return bool true on success
|
||||
* @throws \Magento\Framework\Exception\NoSuchEntityException
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function deleteById($labId);
|
||||
|
||||
/**
|
||||
* @param int $customerId
|
||||
* @return Lab\Collection
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function getByDealerId(int $customerId);
|
||||
|
||||
/**
|
||||
* @param $labCode \Stemcell\Customer\Model\Lab Code
|
||||
* @return LabInterface
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
public function getByLabCode($labCode);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Api;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaInterface;
|
||||
|
||||
interface SalespersonRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Save Salesperson
|
||||
* @param \Stemcell\Customer\Api\Data\SalespersonInterface $salesperson
|
||||
* @return \Stemcell\Customer\Api\Data\SalespersonInterface
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function save(
|
||||
\Stemcell\Customer\Api\Data\SalespersonInterface $salesperson
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve Salesperson
|
||||
* @param string $salespersonId
|
||||
* @return \Stemcell\Customer\Api\Data\SalespersonInterface
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function get($salespersonId);
|
||||
|
||||
/**
|
||||
* Retrieve Salesperson matching the specified criteria.
|
||||
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
|
||||
* @return \Stemcell\Customer\Api\Data\SalespersonSearchResultsInterface
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function getList(
|
||||
\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
|
||||
);
|
||||
|
||||
/**
|
||||
* Delete Salesperson
|
||||
* @param \Stemcell\Customer\Api\Data\SalespersonInterface $salesperson
|
||||
* @return bool true on success
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function delete(
|
||||
\Stemcell\Customer\Api\Data\SalespersonInterface $salesperson
|
||||
);
|
||||
|
||||
/**
|
||||
* Delete Salesperson by ID
|
||||
* @param string $salespersonId
|
||||
* @return bool true on success
|
||||
* @throws \Magento\Framework\Exception\NoSuchEntityException
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function deleteById($salespersonId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Block\Account;
|
||||
|
||||
class Forgotpassword extends \Magento\Customer\Block\Account\Forgotpassword
|
||||
{
|
||||
/**
|
||||
* Get config
|
||||
*
|
||||
* @param string $path
|
||||
* @return string|null
|
||||
*/
|
||||
public function getConfig($path)
|
||||
{
|
||||
return $this->_scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Block\Address;
|
||||
|
||||
use Magento\Customer\Api\AddressRepositoryInterface;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Customer\Block\Address\Grid;
|
||||
use Magento\Customer\Helper\Session\CurrentCustomer;
|
||||
use Magento\Customer\Model\Address\Config;
|
||||
use Magento\Customer\Model\Address\Mapper;
|
||||
use Magento\Customer\Model\ResourceModel\Address\Collection;
|
||||
use Magento\Customer\Model\ResourceModel\Address\CollectionFactory;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Magento\Theme\Block\Html\Pager;
|
||||
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
class Book extends \Magento\Customer\Block\Address\Book
|
||||
{
|
||||
/**
|
||||
* @var Collection
|
||||
*/
|
||||
protected $addressCollection;
|
||||
|
||||
/**
|
||||
* @var CollectionFactory
|
||||
*/
|
||||
protected CollectionFactory $addressCollectionFactory;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
AddressRepositoryInterface $addressRepository,
|
||||
CurrentCustomer $currentCustomer,
|
||||
Config $addressConfig,
|
||||
Mapper $addressMapper,
|
||||
CollectionFactory $addressCollectionFactory,
|
||||
CustomerRepositoryInterface $customerRepository = null,
|
||||
array $data = [],
|
||||
Grid $addressesGrid = null
|
||||
) {
|
||||
parent::__construct(
|
||||
$context,
|
||||
$customerRepository,
|
||||
$addressRepository,
|
||||
$currentCustomer,
|
||||
$addressConfig,
|
||||
$addressMapper,
|
||||
$data,
|
||||
$addressesGrid
|
||||
);
|
||||
$this->addressCollectionFactory = $addressCollectionFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NoSuchEntityException
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
protected function _prepareLayout(): Book
|
||||
{
|
||||
parent::_prepareLayout();
|
||||
$pager = $this->getChildBlock('pager');
|
||||
if ($pager===false) {
|
||||
$pager = $this->getLayout()->createBlock(Pager::class, 'customer.addresses.pager');
|
||||
$this->setChild('pager', $pager);
|
||||
}
|
||||
$pager->setCollection($this->getAddressCollection());
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get customer addresses collection.
|
||||
*
|
||||
* Filters collection by customer id
|
||||
*
|
||||
* @return Collection
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
public function getAddressCollection(): Collection
|
||||
{
|
||||
if (null === $this->addressCollection) {
|
||||
if (null === $this->getCustomer()) {
|
||||
throw new NoSuchEntityException(__('Customer not logged in'));
|
||||
}
|
||||
$collection = $this->addressCollectionFactory->create();
|
||||
$collection->setOrder('entity_id', 'desc');
|
||||
|
||||
$collection->setCustomerFilter([$this->getCustomer()->getId()]);
|
||||
$this->addressCollection = $collection;
|
||||
}
|
||||
return $this->addressCollection;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Block\Address;
|
||||
|
||||
use Magento\Framework\Api\AttributeInterface;
|
||||
|
||||
class Edit extends \Magento\Customer\Block\Address\Edit
|
||||
{
|
||||
public function getCustomAttributeValue(String $attributeCode) {
|
||||
|
||||
$attribute = $this->getAddress()->getCustomAttribute($attributeCode);
|
||||
|
||||
return $attribute instanceof AttributeInterface? $attribute->getValue():'';
|
||||
}
|
||||
|
||||
public function getRegionId()
|
||||
{
|
||||
return (int)$this->getAddress()->getRegionId();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Block\Adminhtml\Edit;
|
||||
|
||||
use Magento\Customer\Block\Adminhtml\Edit\GenericButton;
|
||||
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
|
||||
|
||||
class SampleButton extends GenericButton implements ButtonProviderInterface
|
||||
{
|
||||
|
||||
public function getButtonData()
|
||||
{
|
||||
return [
|
||||
'label' => __('下载模版文件'),
|
||||
'class' => 'save primary',
|
||||
'on_click' => sprintf("location.href = '%s';", $this->getSampleUrl()),
|
||||
'sort_order' => 90,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getSampleUrl()
|
||||
{
|
||||
return $this->getUrl('stemcell_customer/lab/sample');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Block\Adminhtml\Edit;
|
||||
|
||||
use Magento\Customer\Api\AccountManagementInterface;
|
||||
use Magento\Customer\Block\Adminhtml\Edit\GenericButton;
|
||||
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
|
||||
|
||||
/**
|
||||
* Class SaveButton
|
||||
* @package Magento\Customer\Block\Adminhtml\Edit
|
||||
*/
|
||||
class SaveButton extends GenericButton implements ButtonProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var AccountManagementInterface
|
||||
*/
|
||||
protected $customerAccountManagement;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \Magento\Backend\Block\Widget\Context $context
|
||||
* @param \Magento\Framework\Registry $registry
|
||||
* @param AccountManagementInterface $customerAccountManagement
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Backend\Block\Widget\Context $context,
|
||||
\Magento\Framework\Registry $registry,
|
||||
AccountManagementInterface $customerAccountManagement
|
||||
) {
|
||||
parent::__construct($context, $registry);
|
||||
$this->customerAccountManagement = $customerAccountManagement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getButtonData()
|
||||
{
|
||||
return [
|
||||
'label' => __('Save'),
|
||||
'class' => 'save primary',
|
||||
'data_attribute' => [
|
||||
'mage-init' => ['button' => ['event' => 'save']],
|
||||
'form-role' => 'save',
|
||||
],
|
||||
'sort_order' => 90,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Block\Adminhtml\Edit\Tab;
|
||||
|
||||
class View extends \Magento\Customer\Block\Adminhtml\Edit\Tab\View
|
||||
{
|
||||
public function canShowTab()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isHidden()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Block\Adminhtml\Salesperson;
|
||||
|
||||
use Magento\Customer\Block\Adminhtml\Edit\GenericButton;
|
||||
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
|
||||
|
||||
class SampleButton extends GenericButton implements ButtonProviderInterface
|
||||
{
|
||||
public function getButtonData()
|
||||
{
|
||||
return [
|
||||
'label' => __('下载模版文件'),
|
||||
'class' => 'save primary',
|
||||
'on_click' => sprintf("location.href = '%s';", $this->getSampleUrl()),
|
||||
'sort_order' => 90,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getSampleUrl()
|
||||
{
|
||||
return $this->getUrl('stemcell_customer/salesperson/sample');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Block;
|
||||
|
||||
use Magento\Customer\ViewModel\CookieSettings;
|
||||
use Magento\Customer\ViewModel\Customer\Auth;
|
||||
use Magento\Customer\ViewModel\Customer\JsonSerializer;
|
||||
|
||||
class CustomerData extends \Magento\Customer\Block\CustomerData
|
||||
{
|
||||
public function __construct(
|
||||
\Magento\Framework\View\Element\Template\Context $context,
|
||||
private Auth $auth,
|
||||
private JsonSerializer $jsonSerializer,
|
||||
private CookieSettings $cookieSettings,
|
||||
array $data = [],
|
||||
array $expirableSectionNames = []
|
||||
) {
|
||||
parent::__construct($context, $data, $expirableSectionNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Auth
|
||||
*/
|
||||
public function getAuth()
|
||||
{
|
||||
return $this->auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JsonSerializer
|
||||
*/
|
||||
public function getJsonSerializer()
|
||||
{
|
||||
return $this->jsonSerializer;
|
||||
}
|
||||
|
||||
public function getCookieSettings()
|
||||
{
|
||||
return $this->cookieSettings;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Block\Widget\Product;
|
||||
|
||||
class ProductsList extends \Magento\CatalogWidget\Block\Product\ProductsList
|
||||
{
|
||||
protected ?string $moreLink = null;
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLinkAttributes(): ?string
|
||||
{
|
||||
if ($this->moreLink) {
|
||||
return $this->moreLink;
|
||||
}
|
||||
|
||||
$more = (string)$this->getData('more');
|
||||
if ($more && !\Zend_Uri::check($more)) {
|
||||
return $this->moreLink = $this->_urlBuilder->getUrl($more);
|
||||
}
|
||||
return $this->moreLink = $more;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
Copyright © 2022-present
|
||||
|
||||
This file is part of Stemcell/Customer.
|
||||
|
||||
Stemcell/Customer is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
Please see LICENSE.txt for the full text of GNU General Public License
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Stemcell\Customer\Controller\Account;
|
||||
|
||||
|
||||
use Magento\Customer\Controller\Account;
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
|
||||
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\Exception\InputException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class ResetPasswordPost extends Account\ResetPasswordPost implements HttpPostActionInterface
|
||||
{
|
||||
public function execute()
|
||||
{
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
$password = (string)$this->getRequest()->getPost('password');
|
||||
$passwordConfirmation = (string)$this->getRequest()->getPost('password_confirmation');
|
||||
|
||||
if ($password !== $passwordConfirmation) {
|
||||
$this->messageManager->addErrorMessage(__("New Password and Confirm New Password values didn't match."));
|
||||
$resultRedirect->setPath('customer/account/forgotpassword');
|
||||
|
||||
return $resultRedirect;
|
||||
}
|
||||
|
||||
if (iconv_strlen($password) <= 0) {
|
||||
$this->messageManager->addErrorMessage(__('Please enter a new password.'));
|
||||
$resultRedirect->setPath('customer/account/forgotpassword');
|
||||
|
||||
return $resultRedirect;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->accountManagement->resetPassword(
|
||||
$this->_request->getParam('email'),
|
||||
null,
|
||||
$password
|
||||
);
|
||||
// logout from current session if password changed.
|
||||
if ($this->session->isLoggedIn()) {
|
||||
$this->session->logout();
|
||||
$this->session->start();
|
||||
}
|
||||
$this->session->unsRpToken();
|
||||
$this->messageManager->addSuccessMessage(__('You updated your password.'));
|
||||
$resultRedirect->setPath('customer/account/login');
|
||||
|
||||
return $resultRedirect;
|
||||
} catch (InputException $e) {
|
||||
$this->messageManager->addErrorMessage(__('Something went wrong while saving the new password.'));
|
||||
foreach ($e->getErrors() as $error) {
|
||||
$this->messageManager->addErrorMessage($error->getMessage());
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
$this->messageManager->addErrorMessage($exception->getMessage());
|
||||
}
|
||||
$resultRedirect->setPath('customer/account/forgotpassword');
|
||||
|
||||
return $resultRedirect;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Lab;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Stemcell\Customer\Api\LabRepositoryInterface;
|
||||
use Stemcell\Customer\Model\SalespersonRepository;
|
||||
|
||||
class Edit extends \Magento\Backend\App\Action implements HttpGetActionInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
protected PageFactory $resultPageFactory;
|
||||
protected LabRepositoryInterface $repository;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
PageFactory $resultPageFactory,
|
||||
LabRepositoryInterface $repository
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute view action
|
||||
*
|
||||
* @return ResultInterface
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
try {
|
||||
$salesperson = $this->repository->get($this->getRequest()->getParam('id'))->getData();
|
||||
} catch (NoSuchEntityException $e) {
|
||||
$salesperson = [];
|
||||
}
|
||||
$this->_getSession()->setLab($salesperson);
|
||||
return $this->resultPageFactory->create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Lab;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface;
|
||||
use Magento\Framework\App\Response\Http\FileFactory;
|
||||
use Magento\Ui\Component\MassAction\Filter;
|
||||
use Magento\Ui\Model\Export\ConvertToCsv;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Export extends \Magento\Ui\Controller\Adminhtml\Export\GridToCsv
|
||||
{
|
||||
public function __construct(
|
||||
Context $context,
|
||||
ConvertToCsv $converter,
|
||||
FileFactory $fileFactory,
|
||||
protected \Stemcell\Customer\Model\Lab\Export $exportModel,
|
||||
Filter $filter = null,
|
||||
LoggerInterface $logger = null
|
||||
){
|
||||
parent::__construct($context, $converter, $fileFactory, $filter, $logger);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
return $this->fileFactory->create('Labs-'.date('YmdHis').'.xlsx', $this->exportModel->getExcelFile(), 'var');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Lab;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Stemcell\Customer\Model\SalespersonRepository;
|
||||
|
||||
class Import extends \Magento\Backend\App\Action implements HttpGetActionInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
protected PageFactory $resultPageFactory;
|
||||
protected SalespersonRepository $repository;
|
||||
protected \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
PageFactory $resultPageFactory,
|
||||
\Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory,
|
||||
SalespersonRepository $repository
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute view action
|
||||
*
|
||||
* @return ResultInterface
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
return $this->resultPageFactory->create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Lab;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Customer\Model\Customer;
|
||||
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
|
||||
use \PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface;
|
||||
use Magento\Framework\Controller\ResultFactory;
|
||||
use Magento\Framework\Exception\FileSystemException;
|
||||
use Magento\Framework\Filesystem\Driver\File;
|
||||
use Magento\MediaStorage\Model\File\UploaderFactory;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Exception;
|
||||
use Stemcell\Customer\Api\Data\LabInterface;
|
||||
use Stemcell\Customer\Api\LabRepositoryInterface;
|
||||
use Stemcell\Customer\Model\LabFactory;
|
||||
use Stemcell\Customer\Model\ResourceModel\Salesperson\CollectionFactory;
|
||||
use Stemcell\Customer\Model\Salesperson;
|
||||
|
||||
/**
|
||||
* 由于生产服务器是两台,只有media目录是两台服务器共享,因此将文件上传到media下面
|
||||
*/
|
||||
class ImportPost extends \Magento\Backend\App\Action implements HttpPostActionInterface
|
||||
{
|
||||
private UploaderFactory $fileUploaderFactory;
|
||||
private Filesystem\Directory\WriteInterface $mediaDirectory;
|
||||
private StoreManagerInterface $storeManager;
|
||||
private Filesystem $fileSystem;
|
||||
private File $driverFile;
|
||||
private Customer $customer;
|
||||
private LabRepositoryInterface $labRepository;
|
||||
private LabInterface $lab;
|
||||
private LabFactory $labFactory;
|
||||
private CustomerCollectionFactory $customerCollection;
|
||||
private CollectionFactory $salespersonCollection;
|
||||
|
||||
protected array $salespersons = [];
|
||||
|
||||
protected array $customers = [];
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
UploaderFactory $fileUploaderFactory,
|
||||
Filesystem $filesystem,
|
||||
StoreManagerInterface $storeManager,
|
||||
Filesystem $fileSystem,
|
||||
File $driverFile,
|
||||
CustomerCollectionFactory $customerCollection,
|
||||
LabRepositoryInterface $labRepository,
|
||||
LabFactory $labFactory,
|
||||
LabInterface $lab,
|
||||
CollectionFactory $salespersonCollection
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->fileUploaderFactory = $fileUploaderFactory;
|
||||
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
|
||||
$this->storeManager = $storeManager;
|
||||
$this->fileSystem = $fileSystem;
|
||||
$this->driverFile = $driverFile;
|
||||
$this->customerCollection = $customerCollection;
|
||||
$this->labRepository = $labRepository;
|
||||
$this->labFactory = $labFactory;
|
||||
$this->lab = $lab;
|
||||
$this->salespersonCollection = $salespersonCollection;
|
||||
}
|
||||
|
||||
protected function chineseEncoding(string $str)
|
||||
{
|
||||
return mb_convert_encoding($str, 'UTF-8', ['gb2312', 'gbk']);
|
||||
}
|
||||
|
||||
|
||||
protected function getSalesPersonId(string $name)
|
||||
{
|
||||
$name = trim($name);
|
||||
if (isset($this->salespersons[$name])) {
|
||||
return $this->salespersons[$name];
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $this->lab->getResource()->getConnection()
|
||||
->query("select salesperson_id from salesperson where name = '$name' limit 1")
|
||||
->fetch();
|
||||
if (is_array($result)) {
|
||||
$this->salespersons[$name] = $result['salesperson_id'];
|
||||
return $this->salespersons[$name];
|
||||
}
|
||||
} catch (\Zend_Db_Statement_Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function getCustomerId(string $name)
|
||||
{
|
||||
$name = trim($name);
|
||||
if (isset($this->customers[$name])) {
|
||||
return $this->customers[$name];
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $this->lab->getResource()->getConnection()
|
||||
->query("select entity_id from customer_entity where `firstname` = '$name' limit 1")
|
||||
->fetch();
|
||||
if (is_array($result)) {
|
||||
$this->customers[$name] = $result['entity_id'];
|
||||
return $this->customers[$name];
|
||||
}
|
||||
} catch (\Zend_Db_Statement_Exception $e) {
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$jsonResult = $this->resultFactory->create(ResultFactory::TYPE_JSON);
|
||||
try {
|
||||
$fileUploader = $this->fileUploaderFactory->create([
|
||||
'fileId' => 'lab[import]'
|
||||
]);
|
||||
$fileUploader->setAllowedExtensions(['xls', 'xlsx']);
|
||||
$fileUploader->setAllowRenameFiles(true);
|
||||
$fileUploader->setAllowCreateFolders(true);
|
||||
$fileUploader->setFilesDispersion(false);
|
||||
|
||||
$dir = $this->mediaDirectory->getAbsolutePath(DirectoryList::VAR_IMPORT_EXPORT.'/lab');
|
||||
!is_dir($dir) && mkdir($dir, 0755, true);
|
||||
$data = $fileUploader->save($dir);
|
||||
/* @var $logger \Psr\Log\LoggerInterface */
|
||||
$logger = \Magento\Framework\App\ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class);
|
||||
|
||||
try {
|
||||
$spreadsheet = IOFactory::load($dir.'/'.$fileUploader->getUploadedFileName());
|
||||
$data = $spreadsheet->getActiveSheet()->toArray();
|
||||
array_shift($data);
|
||||
foreach ($data as $content) {
|
||||
array_walk($content, function (&$value){
|
||||
if (is_string($value)) {
|
||||
$value = trim($value);
|
||||
}
|
||||
});
|
||||
if (empty(array_filter($content))) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
$content = array_slice($content, 0, 5);
|
||||
$row = array_combine(['lab_code', 'booking_account', 'pi_sap_id', 'customer_name', 'salesperson'], $content);
|
||||
|
||||
$column = 'lab_code, booking_account, pi_sap_id';
|
||||
$duplicate = 'booking_account = new.booking_account, pi_sap_id = new.pi_sap_id';
|
||||
$row['salesperson_id'] = $row['customer_id']= null;
|
||||
if ($row['customer_name']) {
|
||||
$customerId = $this->getCustomerId((string)$row['customer_name']);
|
||||
if ($customerId) {
|
||||
$column .= ',customer_id';
|
||||
$duplicate .= ', customer_id = new.customer_id';
|
||||
$row['customer_id'] .= ', '. $customerId;
|
||||
}
|
||||
|
||||
unset($row['customer_name']);
|
||||
|
||||
}
|
||||
if ($row['salesperson']) {
|
||||
/* @var $salesperson Salesperson */
|
||||
$salespersonId = $this->getSalesPersonId((string)$row['salesperson']);
|
||||
|
||||
if ($salespersonId) {
|
||||
$column .= ',salesperson_id';
|
||||
$row['salesperson_id'] .= ', '.$salespersonId;
|
||||
$duplicate .= ', salesperson_id = new.salesperson_id';
|
||||
// $this->lab->setData($row);
|
||||
}
|
||||
}
|
||||
if ($row['lab_code']) {
|
||||
$sql = "
|
||||
INSERT INTO lab ($column)
|
||||
VALUES ('{$row['lab_code']}', '{$row['booking_account']}', '{$row['pi_sap_id']}' {$row['customer_id']} {$row['salesperson_id']}) AS new
|
||||
ON DUPLICATE KEY UPDATE
|
||||
$duplicate;
|
||||
";
|
||||
$this->labFactory->create()->getResource()->getConnection()->query($sql);
|
||||
}
|
||||
|
||||
$this->lab->unsetData();
|
||||
} catch (FileSystemException | \Exception $e) {
|
||||
$logger->critical('导入lab失败,原因:'.$e->getMessage(), ['data' => $row]);
|
||||
}
|
||||
}
|
||||
// $logger->info('$this->customers', $this->customers);
|
||||
// $logger->info('$this->salespersons', $this->salespersons);
|
||||
$this->driverFile->deleteFile($dir.'/'.$fileUploader->getUploadedFileName());
|
||||
} catch (FileSystemException | Exception $exception) {
|
||||
$logger->debug($exception->getMessage());
|
||||
}
|
||||
return $jsonResult->setData($data);
|
||||
} catch (LocalizedException|Exception $error) {
|
||||
return $jsonResult->setData(['errorcode' => 0, 'error' => $error->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Lab;
|
||||
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
class Index implements HttpGetActionInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
protected $resultPageFactory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param PageFactory $resultPageFactory
|
||||
*/
|
||||
public function __construct(PageFactory $resultPageFactory)
|
||||
{
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute view action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
return $this->resultPageFactory->create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Lab;
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface;
|
||||
use Magento\Framework\Controller\Result\Redirect;
|
||||
use Magento\Ui\Component\MassAction\Filter;
|
||||
use Stemcell\Customer\Api\LabRepositoryInterface;
|
||||
use Stemcell\Customer\Model\ResourceModel\Lab\CollectionFactory;
|
||||
|
||||
class MassDelete extends Action implements HttpPostActionInterface
|
||||
{
|
||||
public const ADMIN_RESOURCE = 'Stemcell_Customer::salesperson_index';
|
||||
|
||||
private Filter $filter;
|
||||
|
||||
private CollectionFactory $collectionFactory;
|
||||
|
||||
private LabRepositoryInterface $labRepository;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Filter $filter,
|
||||
CollectionFactory $collectionFactory,
|
||||
LabRepositoryInterface $labRepository
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->filter = $filter;
|
||||
$this->collectionFactory = $collectionFactory;
|
||||
$this->labRepository = $labRepository;
|
||||
}
|
||||
|
||||
public function execute(): Redirect
|
||||
{
|
||||
$collection = $this->filter->getCollection($this->collectionFactory->create());
|
||||
$deleted = 0;
|
||||
|
||||
foreach ($collection as $lab) {
|
||||
$this->labRepository->delete($lab);
|
||||
++$deleted;
|
||||
}
|
||||
|
||||
if ($deleted) {
|
||||
$this->messageManager->addSuccessMessage(
|
||||
__('A total of %1 lab record(s) have been deleted.', $deleted)
|
||||
);
|
||||
}
|
||||
|
||||
return $this->resultRedirectFactory->create()->setPath('stemcell_customer/lab/index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Lab;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Stemcell\Customer\Model\SalespersonRepository;
|
||||
|
||||
class NewAction extends \Magento\Backend\App\Action implements HttpGetActionInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
protected PageFactory $resultPageFactory;
|
||||
protected SalespersonRepository $repository;
|
||||
protected \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
PageFactory $resultPageFactory,
|
||||
\Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory,
|
||||
SalespersonRepository $repository
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->resultForwardFactory = $resultForwardFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute view action
|
||||
*
|
||||
* @return ResultInterface
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$resultForward = $this->resultForwardFactory->create();
|
||||
$resultForward->forward('edit');
|
||||
return $resultForward;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Lab;
|
||||
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
|
||||
class Sample implements HttpGetActionInterface
|
||||
{
|
||||
protected \Magento\Framework\App\Response\Http\FileFactory $fileFactory;
|
||||
private \Magento\Framework\Module\Dir $moduleDir;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
|
||||
\Magento\Framework\Module\Dir $moduleDir
|
||||
) {
|
||||
$this->fileFactory = $fileFactory;
|
||||
$this->moduleDir = $moduleDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$file = $this->moduleDir->getDir('Stemcell_Customer').'/data/Sample.xlsx';
|
||||
$content['type'] = 'filename';
|
||||
$content['value'] = $file;
|
||||
$content['rm'] = 0;
|
||||
return $this->fileFactory->create('Sample.xlsx', $content);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Lab;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Stemcell\Customer\Api\Data\LabInterface;
|
||||
use Stemcell\Customer\Api\Data\SalespersonInterface;
|
||||
use Stemcell\Customer\Api\LabRepositoryInterface;
|
||||
use Stemcell\Customer\Api\SalespersonRepositoryInterface;
|
||||
|
||||
class Save extends \Magento\Backend\App\Action implements HttpPostActionInterface
|
||||
{
|
||||
protected LabInterface $salesperson;
|
||||
protected LabRepositoryInterface $salespersonRepository;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
LabInterface $salesperson,
|
||||
LabRepositoryInterface $salespersonRepository
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->salesperson = $salesperson;
|
||||
$this->salespersonRepository = $salespersonRepository;
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$returnToEdit = false;
|
||||
$salesperson = $this->getRequest()->getParam('lab');
|
||||
$this->salesperson->setData($salesperson);
|
||||
try {
|
||||
$this->salespersonRepository->save($this->salesperson);
|
||||
$this->messageManager->addSuccessMessage(__('Lab Data saved.'));
|
||||
} catch (\Exception $e) {
|
||||
$this->messageManager->addExceptionMessage($e);
|
||||
$this->_getSession()->setLab($salesperson);
|
||||
$returnToEdit = true;
|
||||
}
|
||||
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
if ($returnToEdit) {
|
||||
if (isset($salesperson['salesperson_id'])) {
|
||||
$resultRedirect->setPath(
|
||||
'stemcell_customer/lab/edit',
|
||||
['id' => $salesperson['salesperson_id'], '_current' => true]
|
||||
);
|
||||
} else {
|
||||
$resultRedirect->setPath(
|
||||
'stemcell_customer/lab/new',
|
||||
['_current' => true]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$resultRedirect->setPath('stemcell_customer/lab/index');
|
||||
}
|
||||
|
||||
|
||||
return $resultRedirect;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Salesperson;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Stemcell\Customer\Model\SalespersonRepository;
|
||||
|
||||
class Edit extends \Magento\Backend\App\Action implements HttpGetActionInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
protected PageFactory $resultPageFactory;
|
||||
protected SalespersonRepository $repository;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
PageFactory $resultPageFactory,
|
||||
SalespersonRepository $repository
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute view action
|
||||
*
|
||||
* @return ResultInterface
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
try {
|
||||
$salesperson = $this->repository->get($this->getRequest()->getParam('id'))->getData();
|
||||
} catch (NoSuchEntityException $e) {
|
||||
$salesperson = [];
|
||||
}
|
||||
$this->_getSession()->setSalesperson($salesperson);
|
||||
return $this->resultPageFactory->create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Salesperson;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Stemcell\Customer\Model\SalespersonRepository;
|
||||
|
||||
class Import extends \Magento\Backend\App\Action implements HttpGetActionInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
protected PageFactory $resultPageFactory;
|
||||
protected SalespersonRepository $repository;
|
||||
protected \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
PageFactory $resultPageFactory,
|
||||
\Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory,
|
||||
SalespersonRepository $repository
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute view action
|
||||
*
|
||||
* @return ResultInterface
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
return $this->resultPageFactory->create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Salesperson;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Customer\Model\Customer;
|
||||
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface;
|
||||
use Magento\Framework\Controller\ResultFactory;
|
||||
use Magento\Framework\Exception\FileSystemException;
|
||||
use Magento\Framework\Filesystem\Driver\File;
|
||||
use Magento\MediaStorage\Model\File\UploaderFactory;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Exception;
|
||||
use Stemcell\Customer\Api\Data\SalespersonInterface;
|
||||
use Stemcell\Customer\Api\SalespersonRepositoryInterface;
|
||||
|
||||
/**
|
||||
* 由于生产服务器是两台,只有media目录是两台服务器共享,因此将文件上传到media下面
|
||||
*/
|
||||
class ImportPost extends \Magento\Backend\App\Action implements HttpPostActionInterface
|
||||
{
|
||||
private UploaderFactory $fileUploaderFactory;
|
||||
private Filesystem\Directory\WriteInterface $mediaDirectory;
|
||||
private StoreManagerInterface $storeManager;
|
||||
private Filesystem $fileSystem;
|
||||
private File $driverFile;
|
||||
private CustomerCollectionFactory $customerCollection;
|
||||
private SalespersonInterface $salesperson;
|
||||
private SalespersonRepositoryInterface $salespersonRepository;
|
||||
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
UploaderFactory $fileUploaderFactory,
|
||||
Filesystem $filesystem,
|
||||
StoreManagerInterface $storeManager,
|
||||
Filesystem $fileSystem,
|
||||
File $driverFile,
|
||||
CustomerCollectionFactory $customerCollection,
|
||||
SalespersonRepositoryInterface $salespersonRepository,
|
||||
SalespersonInterface $salesperson
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->fileUploaderFactory = $fileUploaderFactory;
|
||||
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
|
||||
$this->storeManager = $storeManager;
|
||||
$this->fileSystem = $fileSystem;
|
||||
$this->driverFile = $driverFile;
|
||||
$this->customerCollection = $customerCollection;
|
||||
$this->salespersonRepository = $salespersonRepository;
|
||||
$this->salesperson = $salesperson;
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$jsonResult = $this->resultFactory->create(ResultFactory::TYPE_JSON);
|
||||
try {
|
||||
$fileUploader = $this->fileUploaderFactory->create([
|
||||
'fileId' => 'salesperson[import]'
|
||||
]);
|
||||
$fileUploader->setAllowedExtensions(['xls', 'xlsx']);
|
||||
$fileUploader->setAllowRenameFiles(true);
|
||||
$fileUploader->setAllowCreateFolders(true);
|
||||
$fileUploader->setFilesDispersion(false);
|
||||
|
||||
$dir = $this->mediaDirectory->getAbsolutePath(DirectoryList::VAR_IMPORT_EXPORT.'/salesperson');
|
||||
!is_dir($dir) && mkdir($dir, 0755, true);
|
||||
$data = $fileUploader->save($dir);
|
||||
$resource = $this->driverFile->fileOpen($dir.'/'.$fileUploader->getUploadedFileName(), 'r');
|
||||
|
||||
/* @var $logger \Psr\Log\LoggerInterface */
|
||||
$logger = \Magento\Framework\App\ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class);
|
||||
|
||||
try {
|
||||
$spreadsheet = IOFactory::load($dir.'/'.$fileUploader->getUploadedFileName());
|
||||
$data = $spreadsheet->getActiveSheet()->toArray();
|
||||
array_shift($data);
|
||||
|
||||
foreach ($data as $content) {
|
||||
|
||||
try {
|
||||
array_walk($content, function (&$value) {
|
||||
if (is_string($value)) {
|
||||
$value = trim($value);
|
||||
}
|
||||
});
|
||||
if (empty(array_filter($content))) {
|
||||
continue;
|
||||
}
|
||||
$content = array_slice($content, 0, 5);
|
||||
$row = array_combine(
|
||||
['name', 'email', 'telephone', 'rsm_email', 'sisr_email', 'csr_email'],
|
||||
$content
|
||||
);
|
||||
$this->salesperson->setData($row);
|
||||
$this->salespersonRepository->save($this->salesperson);
|
||||
$this->salesperson->unsetData();
|
||||
} catch (FileSystemException | \Exception $e) {
|
||||
$logger->critical('导入销售失败,原因:'.$e->getMessage(), ['data' => $row]);
|
||||
}
|
||||
|
||||
}
|
||||
$this->driverFile->fileClose($resource);
|
||||
$this->driverFile->deleteFile($dir.'/'.$fileUploader->getUploadedFileName());
|
||||
} catch (FileSystemException $exception) {
|
||||
$logger->debug($exception->getMessage());
|
||||
}
|
||||
return $jsonResult->setData($data);
|
||||
} catch (LocalizedException | \Exception $error) {
|
||||
return $jsonResult->setData(['errorcode' => 0, 'error' => $error->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Salesperson;
|
||||
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
class Index implements HttpGetActionInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
protected $resultPageFactory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param PageFactory $resultPageFactory
|
||||
*/
|
||||
public function __construct(PageFactory $resultPageFactory)
|
||||
{
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute view action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
return $this->resultPageFactory->create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Salesperson;
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface;
|
||||
use Magento\Framework\Controller\Result\Redirect;
|
||||
use Magento\Ui\Component\MassAction\Filter;
|
||||
use Stemcell\Customer\Api\SalespersonRepositoryInterface;
|
||||
use Stemcell\Customer\Model\ResourceModel\Salesperson\CollectionFactory;
|
||||
|
||||
class MassDelete extends Action implements HttpPostActionInterface
|
||||
{
|
||||
public const ADMIN_RESOURCE = 'Stemcell_Customer::salesperson_index';
|
||||
|
||||
private Filter $filter;
|
||||
|
||||
private CollectionFactory $collectionFactory;
|
||||
|
||||
private SalespersonRepositoryInterface $salespersonRepository;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Filter $filter,
|
||||
CollectionFactory $collectionFactory,
|
||||
SalespersonRepositoryInterface $salespersonRepository
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->filter = $filter;
|
||||
$this->collectionFactory = $collectionFactory;
|
||||
$this->salespersonRepository = $salespersonRepository;
|
||||
}
|
||||
|
||||
public function execute(): Redirect
|
||||
{
|
||||
$collection = $this->filter->getCollection($this->collectionFactory->create());
|
||||
$deleted = 0;
|
||||
|
||||
foreach ($collection as $salesperson) {
|
||||
$this->salespersonRepository->delete($salesperson);
|
||||
++$deleted;
|
||||
}
|
||||
|
||||
if ($deleted) {
|
||||
$this->messageManager->addSuccessMessage(
|
||||
__('A total of %1 salesperson record(s) have been deleted.', $deleted)
|
||||
);
|
||||
}
|
||||
|
||||
return $this->resultRedirectFactory->create()->setPath('stemcell_customer/salesperson/index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Salesperson;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Stemcell\Customer\Model\SalespersonRepository;
|
||||
|
||||
class NewAction extends \Magento\Backend\App\Action implements HttpGetActionInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var PageFactory
|
||||
*/
|
||||
protected PageFactory $resultPageFactory;
|
||||
protected SalespersonRepository $repository;
|
||||
protected \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
PageFactory $resultPageFactory,
|
||||
\Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory,
|
||||
SalespersonRepository $repository
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->resultForwardFactory = $resultForwardFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute view action
|
||||
*
|
||||
* @return ResultInterface
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$resultForward = $this->resultForwardFactory->create();
|
||||
$resultForward->forward('edit');
|
||||
return $resultForward;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Salesperson;
|
||||
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
|
||||
class Sample implements HttpGetActionInterface
|
||||
{
|
||||
protected \Magento\Framework\App\Response\Http\FileFactory $fileFactory;
|
||||
private \Magento\Framework\Module\Dir $moduleDir;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
|
||||
\Magento\Framework\Module\Dir $moduleDir
|
||||
) {
|
||||
$this->fileFactory = $fileFactory;
|
||||
$this->moduleDir = $moduleDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$file = $this->moduleDir->getDir('Stemcell_Customer').'/data/sample/salesperson.xlsx';
|
||||
$content['type'] = 'filename';
|
||||
$content['value'] = $file;
|
||||
$content['rm'] = 0;
|
||||
return $this->fileFactory->create('salesperson.xlsx', $content);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Controller\Adminhtml\Salesperson;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Stemcell\Customer\Api\Data\SalespersonInterface;
|
||||
use Stemcell\Customer\Api\SalespersonRepositoryInterface;
|
||||
|
||||
class Save extends \Magento\Backend\App\Action implements HttpPostActionInterface
|
||||
{
|
||||
protected SalespersonInterface $salesperson;
|
||||
protected SalespersonRepositoryInterface $salespersonRepository;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
SalespersonInterface $salesperson,
|
||||
SalespersonRepositoryInterface $salespersonRepository
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->salesperson = $salesperson;
|
||||
$this->salespersonRepository = $salespersonRepository;
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$returnToEdit = false;
|
||||
$salesperson = $this->getRequest()->getParam('salesperson');
|
||||
$this->salesperson->setData($salesperson);
|
||||
try {
|
||||
$this->salespersonRepository->save($this->salesperson);
|
||||
$this->messageManager->addSuccessMessage(__('Salesperson saved.'));
|
||||
} catch (\Exception $e) {
|
||||
$this->messageManager->addExceptionMessage($e);
|
||||
$this->_getSession()->setSalesperson($salesperson);
|
||||
$returnToEdit = true;
|
||||
}
|
||||
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
if ($returnToEdit) {
|
||||
if (isset($salesperson['salesperson_id'])) {
|
||||
$resultRedirect->setPath(
|
||||
'stemcell_customer/salesperson/edit',
|
||||
['id' => $salesperson['salesperson_id'], '_current' => true]
|
||||
);
|
||||
} else {
|
||||
$resultRedirect->setPath(
|
||||
'stemcell_customer/salesperson/new',
|
||||
['_current' => true]
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$resultRedirect->setPath('stemcell_customer/salesperson/index');
|
||||
}
|
||||
|
||||
|
||||
return $resultRedirect;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Controller\Avatr;
|
||||
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Stemcell\Customer\Helper\Avatr as AvatrHelper;
|
||||
use Stemcell\Customer\Model\AvatrFactory;
|
||||
|
||||
class Index implements HttpGetActionInterface
|
||||
{
|
||||
private \Magento\Framework\View\Result\PageFactory $resultPageFactory;
|
||||
private AvatrHelper $avatrHelper;
|
||||
private AvatrFactory $avatrFactory;
|
||||
private \Magento\Framework\App\RequestInterface $request;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
|
||||
AvatrHelper $avatrHelper,
|
||||
AvatrFactory $avatrFactory,
|
||||
\Magento\Framework\App\RequestInterface $request
|
||||
) {
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
$this->avatrHelper = $avatrHelper;
|
||||
$this->avatrFactory = $avatrFactory;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
/** @var \Magento\Framework\View\Result\Page $resultPage */
|
||||
return $this->resultPageFactory->create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Controller\Avatr;
|
||||
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface;
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\Controller\Result\RedirectFactory;
|
||||
use Magento\Framework\Exception\FileSystemException;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\MediaStorage\Model\File\UploaderFactory;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\Framework\Message\ManagerInterface as MessageManagerInterface;
|
||||
use Stemcell\Customer\Api\AvatrRepositoryInterface;
|
||||
use Stemcell\Customer\Helper\Avatr as AvatrHelper;
|
||||
use Stemcell\Customer\Helper\CarSeriesClueFactory;
|
||||
use Stemcell\Customer\Model\AvatrFactory;
|
||||
use Stemcell\Customer\Helper\Avatr\Transformers as TransformersHelper;
|
||||
|
||||
class Post implements HttpPostActionInterface
|
||||
{
|
||||
private \Magento\Framework\App\Request\Http $request;
|
||||
private UploaderFactory $fileUploader;
|
||||
private \Magento\Framework\Filesystem\Directory\WriteInterface $filesystem;
|
||||
private RedirectFactory $redirectFactory;
|
||||
private \Magento\Framework\File\Csv $csv;
|
||||
private AvatrFactory $avatrFactory;
|
||||
private AvatrRepositoryInterface $avatrRepository;
|
||||
private AvatrHelper $avatrHelper;
|
||||
private MessageManagerInterface $messageManager;
|
||||
|
||||
private TransformersHelper $transformersHelper;
|
||||
|
||||
//正式环境,默认测试环境
|
||||
protected array $config = [
|
||||
'media_id' => 6110,
|
||||
'media_name' => 'SHANGHAILIQI',
|
||||
'ak' => 6110,
|
||||
'sk' => 'OvsbfYqDXcqr',
|
||||
'aes_key' => 'oEr4HdIIouvveWL0Jjk74tA8Cf3fkaqQ',
|
||||
'aes_iv' => 'WUPXlZGkfu7yo4gi',
|
||||
'host' => 'https://sl-api-amstp.avatr.com'
|
||||
];
|
||||
private CarSeriesClueFactory $clueHelperFactory;
|
||||
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Framework\App\Request\Http $request,
|
||||
UploaderFactory $fileUploader,
|
||||
Filesystem $filesystem,
|
||||
RedirectFactory $redirectFactory,
|
||||
\Magento\Framework\File\Csv $csv,
|
||||
AvatrFactory $avatrFactory,
|
||||
AvatrRepositoryInterface $avatrRepository,
|
||||
AvatrHelper $avatrHelper,
|
||||
TransformersHelper $transformersHelper,
|
||||
MessageManagerInterface $messageManager,
|
||||
CarSeriesClueFactory $clueHelperFactory
|
||||
) {
|
||||
$this->request = $request;
|
||||
$this->fileUploader = $fileUploader;
|
||||
$this->redirectFactory = $redirectFactory;
|
||||
$this->csv = $csv;
|
||||
$this->avatrFactory = $avatrFactory;
|
||||
$this->avatrRepository = $avatrRepository;
|
||||
$this->avatrHelper = $avatrHelper;
|
||||
$this->transformersHelper = $transformersHelper;
|
||||
$this->messageManager = $messageManager;
|
||||
$this->clueHelperFactory = $clueHelperFactory;
|
||||
$this->filesystem = $filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
|
||||
}
|
||||
|
||||
private function encode(array $data)
|
||||
{
|
||||
foreach ($data as $key=>$val){
|
||||
$data[$key] = mb_convert_encoding($val, 'UTF-8', ['gb2312', 'gbk']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注意:上传的csv第三个列一定要是意向车型
|
||||
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
ini_set('max_execution_time', -1);
|
||||
set_time_limit(0);
|
||||
$file = $this->request->getFiles('avatr');
|
||||
/* @var $logger \Psr\Log\LoggerInterface */
|
||||
$logger = \Magento\Framework\App\ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class);
|
||||
if (file_exists($file['tmp_name'])) {
|
||||
$this->csv->setDelimiter(",");
|
||||
$index = 1;
|
||||
$rawData=[];
|
||||
try {
|
||||
$failRow = [];
|
||||
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
||||
$reader->setReadDataOnly(true);
|
||||
$workSheet = $reader->load($file['tmp_name'])->getSheet(0);
|
||||
|
||||
$count = 0;
|
||||
foreach ($workSheet->toArray() as $row => $item) {
|
||||
|
||||
if ($row > 0 && !empty($item[2])){
|
||||
|
||||
$rawData = $item;
|
||||
$index = $row;
|
||||
// not count the empty row
|
||||
$count++;
|
||||
$env = $this->request->getParam('env');
|
||||
$clueHelper = $this->clueHelperFactory->create($item[2], $env=='dev');
|
||||
|
||||
try {
|
||||
$rowData = $clueHelper->transform($item);
|
||||
|
||||
$item = array_combine(
|
||||
['name', 'telephone', 'favorite_vehicle', 'province_id', 'city_id'],
|
||||
$rowData
|
||||
);
|
||||
|
||||
$avatr = $this->avatrRepository->getByTelephone($item['telephone'], $item['favorite_vehicle']);
|
||||
|
||||
if (!$avatr->getId()) {
|
||||
$avatr = $this->avatrFactory->create();
|
||||
}
|
||||
foreach ($item as $key=>$value) {
|
||||
$avatr->setData($key, $value);
|
||||
}
|
||||
|
||||
$avatr = $this->avatrRepository->save($avatr);
|
||||
$clueHelper->setClue($avatr)->post();
|
||||
$avatr->setIsSent(0);
|
||||
if ($clueHelper->isSuccess()) {
|
||||
$avatr->setIsSent(1);
|
||||
} else {
|
||||
$failRow[] = $row;
|
||||
}
|
||||
$requestLog = [
|
||||
'response' => $clueHelper->getResponse(),
|
||||
'request' => $clueHelper->getRequestData()
|
||||
];
|
||||
|
||||
$avatr->setResponse(json_encode($requestLog, JSON_UNESCAPED_UNICODE));
|
||||
$this->avatrRepository->save($avatr);
|
||||
} catch (LocalizedException $e) {
|
||||
$failRow[] = $row;
|
||||
// echo '第'.$row.'行数据发送异常, 原因:'.$e->getMessage().'<br/>';
|
||||
$this->messageManager->addErrorMessage('第'.$row.'行数据发送异常, 原因:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->messageManager->addSuccessMessage(
|
||||
'总共: '.($count).' 条数据, '
|
||||
.$count-count($failRow).' 条数据发送成功, '.count($failRow).' 条数据发送失败 '
|
||||
);
|
||||
if (count($failRow)) {
|
||||
$this->messageManager->addErrorMessage('第'.implode('、', $failRow).'行数据发送失败');
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// echo '数据发送失败, 原因:'.$e->getMessage().'<br/>';
|
||||
$this->messageManager->addErrorMessage(sprintf('第%d条数据发送失败', $index).', '.$e->getMessage());
|
||||
$logger->alert('详细信息: '.$e->getMessage(), $e->getTrace());
|
||||
$logger->alert(sprintf('第%d条数据发送失败', $index), $rawData);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $this->redirectFactory->create()->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Controller\Avatr;
|
||||
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Stemcell\Customer\Helper\Deepblue\Caller;
|
||||
use Stemcell\Customer\Helper\Deepblue\CluePost;
|
||||
use Magento\Framework\Controller\Result\JsonFactory;
|
||||
|
||||
class Test implements HttpGetActionInterface
|
||||
{
|
||||
private CluePost $cluePostHelper;
|
||||
private array $config = [
|
||||
'host' => 'http://47.108.118.7:5782',
|
||||
'app_key' => '1a7723f050144299822bf2b0223912dd',
|
||||
'app_secret' => '32385b2c5d24263cc08487d659bd273c',
|
||||
'pubKey' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1TizFpjDxJ30ygJRqVMi7tIm7PkiJQWkhv5yf2GI7oqbPZLkvLeKFy8um68EHRAJeSnsj3r6xMaL5aCD6hhu8j8LdMrAIXMOh6/VkNR4TiPYXHwArZ/ykwELPNMSOr9OJspZvXq3Np9imgyhyhAYZw7pcO/C/csnYEm3OqZnRQuayMQOtpukyWWkACvwYX1ZUq3rrXhSgn6qoMOOTg5YkBKKhehYRbyt5Bm4gzok
|
||||
Zi9QhhqtrJpErxxjuryNH1mDeosebsYEN5w6iv5x30lYA7sK3FLxGWeMZ3AVW5DYt59hwZjZx9utlHIYJzv8gCGavr9IhOaQ2rH/Tdjm4N+QjQIDAQAB',
|
||||
];
|
||||
private JsonFactory $jsonFactory;
|
||||
private LoggerInterface $logger;
|
||||
private \Magento\Framework\App\RequestInterface $request;
|
||||
|
||||
public function __construct(
|
||||
CluePost $cluePostHelper,
|
||||
JsonFactory $jsonFactory,
|
||||
LoggerInterface $logger,
|
||||
\Magento\Framework\App\RequestInterface $request
|
||||
) {
|
||||
$this->cluePostHelper = $cluePostHelper;
|
||||
$this->jsonFactory = $jsonFactory;
|
||||
$this->logger = $logger;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
if ($this->request->getParam('env')=='dev') {
|
||||
$this->cluePostHelper->setConfig($this->config);
|
||||
}
|
||||
$result = ['error' => ''];
|
||||
$result['response'] = $this->cluePostHelper->setRequestData([
|
||||
'customerPhoneNo' => '13333333333',
|
||||
'outwardOriginId' => 'bbycm-'.time(),
|
||||
'city' => '420100',
|
||||
'province' => '420000',
|
||||
])->post();
|
||||
|
||||
return $this->jsonFactory->create()->setData(['result' => $result, 'request_data'=>$this->cluePostHelper->getRequestData()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Controller\Lab;
|
||||
|
||||
use Magento\Framework\Controller\Result\RedirectFactory;
|
||||
use Magento\Framework\Message\ManagerInterface as MessageManagerInterface;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Stemcell\Customer\Api\LabRepositoryInterface;
|
||||
use Stemcell\Customer\Helper\LabDownload;
|
||||
|
||||
class Download implements \Magento\Customer\Controller\AccountInterface
|
||||
{
|
||||
private \Magento\Customer\Model\Session $customerSession;
|
||||
private LabRepositoryInterface $labRepository;
|
||||
private RedirectFactory $redirectFactory;
|
||||
private MessageManagerInterface $messageManager;
|
||||
private \Magento\Framework\Controller\Result\RawFactory $resultRawFactory;
|
||||
private \Magento\Framework\App\Response\Http\FileFactory $fileFactory;
|
||||
private LabDownload $labDownloadHelper;
|
||||
private LoggerInterface $logger;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Customer\Model\Session $customerSession,
|
||||
LabRepositoryInterface $labRepository,
|
||||
RedirectFactory $redirectFactory,
|
||||
MessageManagerInterface $messageManager,
|
||||
LabDownload $labDownloadHelper,
|
||||
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
|
||||
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
|
||||
LoggerInterface $logger
|
||||
) {
|
||||
$this->customerSession = $customerSession;
|
||||
$this->labRepository = $labRepository;
|
||||
$this->redirectFactory = $redirectFactory;
|
||||
$this->messageManager = $messageManager;
|
||||
$this->labDownloadHelper = $labDownloadHelper;
|
||||
$this->fileFactory = $fileFactory;
|
||||
$this->resultRawFactory = $resultRawFactory;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$labs = $this->labRepository->getByDealerId($this->customerSession->getCustomerId());
|
||||
if (!$labs->count()) {
|
||||
$this->messageManager->addErrorMessage('您暂无可下载的Lab');
|
||||
return $this->redirectFactory->create()->setPath('customer/account/index/');
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->fileFactory->create('export-'.date('YmdHis').'.xlsx', $this->labDownloadHelper->write($labs), 'media');
|
||||
} catch (\Exception | \PhpOffice\PhpSpreadsheet\Exception $e) {
|
||||
$this->logger->critical('Lab下载失败, 原因:'.$e->getMessage());
|
||||
$this->messageManager->addErrorMessage('Lab下载失败');
|
||||
return $this->redirectFactory->create()->setPath('customer/account/index/');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Controller\Sms;
|
||||
|
||||
use Stemcell\Customer\Api\Data\Http\JsonResponse;
|
||||
use Stemcell\Customer\Observer\CheckRegisterSmsObserver;
|
||||
use Stemcell\Sms\Model\AliyunSmsSender;
|
||||
use Stemcell\Sms\Model\AliyunSmsSenderFactory;
|
||||
use Magento\Backend\Model\View\Result\RedirectFactory;
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
|
||||
use Magento\Framework\App\CsrfAwareActionInterface;
|
||||
use Magento\Framework\App\Request\InvalidRequestException;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\App\Response\RedirectInterface;
|
||||
use Magento\Framework\Controller\Result\JsonFactory as ResultJsonFactory;
|
||||
use Magento\Framework\Controller\Result\Json as ResultJson;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Session\SessionManagerInterface;
|
||||
use Magento\Framework\Stdlib\DateTime\DateTimeFactory;
|
||||
use Magento\Framework\UrlFactory;
|
||||
use Magento\Framework\Data\Form\FormKey;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Send implements CsrfAwareActionInterface, HttpPostActionInterface
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\Controller\Result\RedirectFactory
|
||||
*/
|
||||
protected $resultRedirectFactory;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\UrlInterface
|
||||
*/
|
||||
protected $urlModel;
|
||||
|
||||
protected RedirectInterface $_redirect;
|
||||
|
||||
protected ResultJson $resultJson;
|
||||
|
||||
protected FormKey\Validator $formKeyValidator;
|
||||
|
||||
protected DateTimeFactory $dateTimeFactory;
|
||||
|
||||
protected SessionManagerInterface $session;
|
||||
|
||||
protected FormKey $formKey;
|
||||
|
||||
protected JsonResponse $jsonResponse;
|
||||
|
||||
protected RequestInterface $request;
|
||||
|
||||
protected AliyunSmsSenderFactory $aliyunSmsSenderFactory;
|
||||
|
||||
protected LoggerInterface $logger;
|
||||
|
||||
public function __construct(
|
||||
RedirectFactory $redirectFactory,
|
||||
UrlFactory $urlFactory,
|
||||
RedirectInterface $redirect,
|
||||
ResultJsonFactory $resultJsonFactory,
|
||||
FormKey\Validator $formKeyValidator,
|
||||
FormKey $formKey,
|
||||
SessionManagerInterface $session,
|
||||
DateTimeFactory $dateTimeFactory,
|
||||
JsonResponse $jsonResponse,
|
||||
RequestInterface $request,
|
||||
LoggerInterface $logger,
|
||||
AliyunSmsSenderFactory $aliyunSmsSenderFactory
|
||||
) {
|
||||
$this->resultRedirectFactory = $redirectFactory;
|
||||
$this->urlModel = $urlFactory;
|
||||
$this->_redirect = $redirect;
|
||||
$this->formKeyValidator = $formKeyValidator;
|
||||
$this->resultJson = $resultJsonFactory->create();
|
||||
$this->dateTimeFactory = $dateTimeFactory;
|
||||
$this->session = $session;
|
||||
$this->formKey = $formKey;
|
||||
$this->request = $request;
|
||||
$this->jsonResponse = $jsonResponse;
|
||||
$this->aliyunSmsSenderFactory = $aliyunSmsSenderFactory;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
protected function _beforeExecute(RequestInterface $request) {
|
||||
if (!$this->formKeyValidator->validate($request)) {
|
||||
throw new LocalizedException(__('Please refresh current page'));
|
||||
}
|
||||
|
||||
if ($request->getParam('captcha_fail')) {
|
||||
throw new LocalizedException(__('Incorrect CAPTCHA.'));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getType() {
|
||||
$type = $this->request->getParam('form_id');
|
||||
return $type?:CheckRegisterSmsObserver::FORMID;
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$aliyunSmsSender = $this->aliyunSmsSenderFactory->create([
|
||||
'data' => [
|
||||
'type' => $this->getType(),
|
||||
'mobile' => $this->request->getParam('mobile'),
|
||||
]
|
||||
]);
|
||||
|
||||
try {
|
||||
$this->_beforeExecute($this->request);
|
||||
$response = $aliyunSmsSender->send();
|
||||
$data = [
|
||||
'formKey' => $this->formKey->getFormKey(),
|
||||
'result' => $response->getIsSuccess()
|
||||
];
|
||||
if ($aliyunSmsSender->getAppConfig()->getValue('sms/sms/debug')) {
|
||||
$data['code'] = $aliyunSmsSender->getCode();
|
||||
}
|
||||
$this->jsonResponse->setErrors(!$response->getIsSuccess())->setData($data)->setMessages([$response->getMessage()]);
|
||||
|
||||
} catch (LocalizedException $e) {
|
||||
$this->logger->critical('Sms send fail, '.$e->getMessage());
|
||||
$this->jsonResponse->setErrors(true)
|
||||
->setMessages([__($e->getMessage())->render()]);
|
||||
// ->setMessages([__('Sms send fail')->render()]);
|
||||
}
|
||||
|
||||
return $this->resultJson->setData($this->jsonResponse);
|
||||
}
|
||||
|
||||
public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function validateForCsrf(RequestInterface $request): ?bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Controller\Sms;
|
||||
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\Controller\Result\JsonFactory as ResultJsonFactory;
|
||||
use Magento\SalesSequence\Model\Manager;
|
||||
use Stemcell\Sales\Helper\Data;
|
||||
use Magento\Framework\App\Response;
|
||||
|
||||
class Test implements HttpGetActionInterface
|
||||
{
|
||||
protected Data $data;
|
||||
|
||||
protected ResultJsonFactory $resultJsonFactory;
|
||||
protected Manager $sequenceManager;
|
||||
|
||||
public function __construct(
|
||||
Data $data,
|
||||
ResultJsonFactory $resultJsonFactory,
|
||||
Manager $sequenceManager
|
||||
) {
|
||||
$this->data = $data;
|
||||
$this->resultJsonFactory = $resultJsonFactory;
|
||||
$this->sequenceManager = $sequenceManager;
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$sequence = $this->sequenceManager->getSequence('order', 1);
|
||||
return $this->resultJsonFactory->create()->setData(['data'=>$sequence->getNextValue()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Controller;
|
||||
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface;
|
||||
use Magento\Framework\App\CsrfAwareActionInterface;
|
||||
use Magento\Framework\App\Request\InvalidRequestException;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\Controller\Result\JsonFactory as ResultJsonFactory;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Xiaohongshu implements HttpPostActionInterface, CsrfAwareActionInterface
|
||||
{
|
||||
private LoggerInterface $logger;
|
||||
private \Magento\Framework\App\Request\Http $request;
|
||||
private \Magento\Framework\Controller\Result\Json $resultJson;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Framework\App\Request\Http $request,
|
||||
LoggerInterface $logger,
|
||||
ResultJsonFactory $resultJsonFactory,
|
||||
) {
|
||||
$this->logger = $logger;
|
||||
$this->request = $request;
|
||||
$this->resultJson = $resultJsonFactory->create();
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$this->logger->debug('received data', $this->request->getParams());
|
||||
return $this->resultJson->setHttpResponseCode(200);
|
||||
}
|
||||
|
||||
public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function validateForCsrf(RequestInterface $request): ?bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Controller\Xiaohongshu;
|
||||
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface;
|
||||
use Magento\Framework\App\CsrfAwareActionInterface;
|
||||
use Magento\Framework\App\Request\InvalidRequestException;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\Controller\Result\JsonFactory as ResultJsonFactory;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Post implements HttpPostActionInterface, CsrfAwareActionInterface
|
||||
{
|
||||
private LoggerInterface $logger;
|
||||
private \Magento\Framework\App\Request\Http $request;
|
||||
private \Magento\Framework\Controller\Result\Json $resultJson;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Framework\App\Request\Http $request,
|
||||
LoggerInterface $logger,
|
||||
ResultJsonFactory $resultJsonFactory,
|
||||
) {
|
||||
$this->logger = $logger;
|
||||
$this->request = $request;
|
||||
$this->resultJson = $resultJsonFactory->create();
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$this->logger->debug('received data', $this->request->getParams());
|
||||
return $this->resultJson->setHttpResponseCode(200);
|
||||
}
|
||||
|
||||
public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function validateForCsrf(RequestInterface $request): ?bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\CustomerData;
|
||||
|
||||
use Magento\Customer\Helper\Session\CurrentCustomer;
|
||||
use Magento\Customer\Helper\View;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Customer extends \Magento\Customer\CustomerData\Customer
|
||||
{
|
||||
protected View $customerViewHelper;
|
||||
|
||||
/**
|
||||
* @param CurrentCustomer $currentCustomer
|
||||
* @param View $customerViewHelper
|
||||
*/
|
||||
public function __construct(
|
||||
CurrentCustomer $currentCustomer,
|
||||
View $customerViewHelper
|
||||
) {
|
||||
$this->currentCustomer = $currentCustomer;
|
||||
$this->customerViewHelper = $customerViewHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSectionData()
|
||||
{
|
||||
if (!$this->currentCustomer->getCustomerId()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$customer = $this->currentCustomer->getCustomer();
|
||||
return [
|
||||
'fullname' => $this->customerViewHelper->getCustomerName($customer),
|
||||
'firstname' => $customer->getId(),
|
||||
'websiteId' => $customer->getWebsiteId(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Helper;
|
||||
|
||||
use Magento\Framework\App\Helper\Context;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Stemcell\Customer\Api\Data\AvatrInterface;
|
||||
use Stemcell\Customer\Helper\Avatr\Transformers;
|
||||
|
||||
class Avatr extends \Magento\Framework\App\Helper\AbstractHelper implements CarSeriesClueInterface
|
||||
{
|
||||
protected array $config = [
|
||||
'media_id' => 6110,
|
||||
'media_name' => 'SHANGHAILIQI',
|
||||
'ak' => 6110,
|
||||
'sk' => 'OvsbfYqDXcqr',
|
||||
'aes_key' => 'oEr4HdIIouvveWL0Jjk74tA8Cf3fkaqQ',
|
||||
'aes_iv' => 'WUPXlZGkfu7yo4gi',
|
||||
'host' => 'https://sl-api-amstp.avatr.com'
|
||||
];
|
||||
|
||||
protected int $timestamp = 0;
|
||||
|
||||
protected array $requestData = [];
|
||||
private \Magento\Framework\HTTP\Client\Curl $curl;
|
||||
|
||||
private \Stemcell\Customer\Model\Avatr $avatr;
|
||||
private Transformers $transformers;
|
||||
|
||||
private string $clueCreateEndpoint = '/api/media/data/save/v2';
|
||||
|
||||
private string $response;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
\Magento\Framework\HTTP\Client\Curl $curl,
|
||||
Transformers $transformers
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->curl = $curl;
|
||||
$this->transformers = $transformers;
|
||||
}
|
||||
|
||||
public function setConfig(array $config = []): static
|
||||
{
|
||||
$this->config = array_merge($this->config, $config);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setClue(AvatrInterface $clue):self {
|
||||
$this->avatr = $clue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setRequestData(array $requestData): static
|
||||
{
|
||||
$this->requestData = $requestData;
|
||||
return $this;
|
||||
}
|
||||
public function getRequestData():array
|
||||
{
|
||||
if (!empty($this->requestData)) {
|
||||
return $this->requestData;
|
||||
}
|
||||
$leadsCreateTime = $this->avatr->getCreatedAt();
|
||||
if (!$leadsCreateTime) {
|
||||
$leadsCreateTime = date("Y-m-d H:i:s", $this->getTimestamp());
|
||||
}
|
||||
return $this->requestData = [
|
||||
'mediaId' => $this->config['media_id'],
|
||||
'mediaName' => $this->config['media_name'],
|
||||
'clueId' => 'shlq-'.str_pad($this->avatr->getId(), 12, '0', STR_PAD_LEFT),
|
||||
'name' => $this->avatr->getName(),
|
||||
'leadsCreateTime' => $leadsCreateTime,
|
||||
'phone' => $this->getEncryptedPhone($this->avatr->getTelephone()),
|
||||
'province' => $this->avatr->getProvinceId().'',
|
||||
'city' => $this->avatr->getCityId().'',
|
||||
'carStyle' => $this->avatr->getFavoriteVehicle(),
|
||||
'campaignId' => '202402_CRP_SHANGHAILIQI_S1',
|
||||
'campaignName' => '202402_线索资源池_上海力企_启动期'
|
||||
];
|
||||
}
|
||||
|
||||
protected function getEncryptedPhone(string $content, $cipher = 'AES-256-CBC'):string {
|
||||
return base64_encode(
|
||||
openssl_encrypt(
|
||||
$content,
|
||||
$cipher,
|
||||
$this->config['aes_key'],
|
||||
OPENSSL_RAW_DATA,
|
||||
$this->config['aes_iv']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function getTimestamp(): int
|
||||
{
|
||||
if ($this->timestamp !== 0) {
|
||||
return $this->timestamp;
|
||||
}
|
||||
|
||||
return $this->timestamp = time();
|
||||
}
|
||||
|
||||
protected function sign(
|
||||
string $uri = '/api/media/data/save/v2',
|
||||
string $algo = 'sha1',
|
||||
string $httpMethod = 'POST',
|
||||
string $contentType = 'application/json',
|
||||
): string
|
||||
{
|
||||
$data = $this->getRequestData();
|
||||
ksort($data);
|
||||
|
||||
$signString = sprintf(
|
||||
'%s %s %s %s %s',
|
||||
$httpMethod,
|
||||
$uri,
|
||||
$contentType,
|
||||
$this->getTimestamp(),
|
||||
str_replace('\\/', '/', json_encode($data, JSON_UNESCAPED_UNICODE))
|
||||
);
|
||||
// echo '签名前数据: '.$signString.'<br/><br/>';
|
||||
return base64_encode(hash_hmac($algo, $signString, $this->config['sk'], true));
|
||||
}
|
||||
|
||||
public function post() : self {
|
||||
$body = json_encode($this->getRequestData());
|
||||
|
||||
$this->_logger->debug('config: ', $this->config);
|
||||
$authorization = sprintf('AVATR %s:%s', $this->config['ak'], $this->sign($this->clueCreateEndpoint));
|
||||
|
||||
$this->curl->addHeader("Content-Type", "application/json");
|
||||
$this->curl->addHeader('Timestamp', $this->getTimestamp());
|
||||
$this->curl->addHeader('Authorization', $authorization);
|
||||
$this->curl->post( $this->config['host'].$this->clueCreateEndpoint, $body);
|
||||
|
||||
$this->response = $this->curl->getBody();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function transform(array $from): array
|
||||
{
|
||||
return $this->transformers->transform($from);
|
||||
}
|
||||
|
||||
public function getResponse() : array
|
||||
{
|
||||
$response = json_decode($this->response, true);
|
||||
return is_array($response)? $response:[];
|
||||
}
|
||||
public function isSuccess(): bool
|
||||
{
|
||||
$response = $this->getResponse();
|
||||
return isset($response['success']) && $response['success']==true;
|
||||
}
|
||||
|
||||
public function reset(): self
|
||||
{
|
||||
$this->requestData = [];
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Helper\Avatr;
|
||||
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Module\Dir as ModuleDir;
|
||||
use Stemcell\Customer\Helper\TransformersInterface;
|
||||
|
||||
/**
|
||||
* transform original province and city name to Avatr require id
|
||||
*/
|
||||
class Transformers implements TransformersInterface
|
||||
{
|
||||
private ModuleDir $moduleDir;
|
||||
|
||||
protected array $data = [];
|
||||
|
||||
protected array $regions = [];
|
||||
public function __construct(
|
||||
ModuleDir $moduleDir
|
||||
) {
|
||||
$this->moduleDir = $moduleDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path a relative path to $module, must begin with /
|
||||
* @param string $module
|
||||
* @return array
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function loadDataFromFile(string $path, string $module='Stemcell_Customer') : array
|
||||
{
|
||||
if (isset($this->data[$path]) && !empty($this->data[$path])) {
|
||||
return $this->data[$path];
|
||||
}
|
||||
$file = $this->moduleDir->getDir($module).$path;
|
||||
if (!file_exists($file)) {
|
||||
throw new LocalizedException(__("$file not exist"));
|
||||
}
|
||||
|
||||
$data = json_decode(file_get_contents($file), true);
|
||||
if (!$data) {
|
||||
throw new LocalizedException(__("$file content is not json"));
|
||||
}
|
||||
|
||||
return $this->data[$path] = $data;
|
||||
}
|
||||
|
||||
protected function chineseEncoding(string $str)
|
||||
{
|
||||
// return mb_convert_encoding($str, 'UTF-8', 'gb2312');
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $row original row data
|
||||
* @return array data order by ['name', 'telephone', 'favorite_vehicle', 'province_id', 'city_id']
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function transform(array $row): array
|
||||
{
|
||||
$region = $this->getRegionId($row[4]);
|
||||
return [$this->chineseEncoding($row[0]), $row[1], $this->getCarModelId($row[2]), $region[0], $region[1]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function getRegionId(string $city)
|
||||
{
|
||||
$city = str_replace(' ', '', $city);
|
||||
$city = $this->chineseEncoding($city);
|
||||
if (isset($this->regions[$city])) {
|
||||
return $this->regions[$city];
|
||||
}
|
||||
|
||||
|
||||
if (mb_strlen($city) < 2) {
|
||||
throw new LocalizedException(__("invalid city name: ".$city));
|
||||
}
|
||||
|
||||
$regions = $this->loadDataFromFile('/data/regions.json');
|
||||
if (isset($regions[$city]) && is_array($regions[$city])) {
|
||||
return $this->regions[$city] = [$regions[$city]['province_id'], $regions[$city]['city_id']];
|
||||
}
|
||||
|
||||
foreach ($regions as $cityName => $item) {
|
||||
if (mb_strpos($cityName, $city) === 0 ) {
|
||||
return $this->regions[$city] = [$item['province_id'], $item['city_id']];
|
||||
}
|
||||
}
|
||||
|
||||
return [null, null];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function getCarModelId(string $carModel)
|
||||
{
|
||||
$carModel = str_replace(' ', '', $carModel);
|
||||
$carModel = $this->chineseEncoding($carModel);
|
||||
$carModels = $this->loadDataFromFile('/data/car-models.json');
|
||||
return $carModels[$carModel] ?? null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Helper;
|
||||
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Stemcell\Customer\Helper\Deepblue\CluePost;
|
||||
|
||||
class CarSeriesClueFactory
|
||||
{
|
||||
private \Magento\Framework\ObjectManagerInterface $objectManager;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Framework\ObjectManagerInterface $objectManager
|
||||
) {
|
||||
$this->objectManager = $objectManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function create(string $series, $isDev = true) : CarSeriesClueInterface
|
||||
{
|
||||
switch ($series) {
|
||||
case '阿维塔11':
|
||||
case '阿维塔12':
|
||||
/* @var $clue CarSeriesClueInterface */
|
||||
$clue = $this->objectManager->create(Avatr::class);
|
||||
if ($isDev) {
|
||||
$clue->setConfig([
|
||||
'media_id' => 6110,
|
||||
'media_name' => 'SHANGHAILIQI',
|
||||
'ak' => 6110,
|
||||
'sk' => 'lMe31rTYgo1i',
|
||||
'aes_key' => '87UaSvn4LyCL6KspJECNfvpXeloujQRK',
|
||||
'aes_iv' => '4VSqolaKO1Z6FPiS',
|
||||
'host' => 'https://sl-api-amstp.stg.avatr.com'
|
||||
]);
|
||||
}
|
||||
return $clue;
|
||||
case '启源':
|
||||
case '深蓝':
|
||||
/* @var $clue CarSeriesClueInterface */
|
||||
$clue = $this->objectManager->create(CluePost::class);
|
||||
if ($isDev) {
|
||||
$clue->setConfig([
|
||||
'host' => 'http://47.108.118.7:5782',
|
||||
'app_key' => '1a7723f050144299822bf2b0223912dd',
|
||||
'app_secret' => '32385b2c5d24263cc08487d659bd273c',
|
||||
'pubKey' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1TizFpjDxJ30ygJRqVMi7tIm7PkiJQWkhv5yf2GI7oqbPZLkvLeKFy8um68EHRAJeSnsj3r6xMaL5aCD6hhu8j8LdMrAIXMOh6/VkNR4TiPYXHwArZ/ykwELPNMSOr9OJspZvXq3Np9imgyhyhAYZw7pcO/C/csnYEm3OqZnRQuayMQOtpukyWWkACvwYX1ZUq3rrXhSgn6qoMOOTg5YkBKKhehYRbyt5Bm4gzok
|
||||
Zi9QhhqtrJpErxxjuryNH1mDeosebsYEN5w6iv5x30lYA7sK3FLxGWeMZ3AVW5DYt59hwZjZx9utlHIYJzv8gCGavr9IhOaQ2rH/Tdjm4N+QjQIDAQAB',
|
||||
]);
|
||||
}
|
||||
return $clue;
|
||||
default:
|
||||
if (str_contains($series, '领克')){
|
||||
/* @var $clue CarSeriesClueInterface */
|
||||
$clue = $this->objectManager->create(Lynkco\CluePost::class);
|
||||
return $clue;
|
||||
}
|
||||
throw new LocalizedException(__('invalid param series: %1', $series));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Helper;
|
||||
|
||||
use Stemcell\Customer\Api\Data\AvatrInterface;
|
||||
|
||||
interface CarSeriesClueInterface
|
||||
{
|
||||
public function setConfig() : self;
|
||||
|
||||
public function transform(array $from) : array;
|
||||
|
||||
public function setClue(AvatrInterface $clue) : self;
|
||||
|
||||
public function post() : self;
|
||||
|
||||
public function isSuccess() : bool;
|
||||
|
||||
public function getResponse() : array;
|
||||
|
||||
public function reset() : self;
|
||||
|
||||
public function getRequestData() : array;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Helper\Deepblue;
|
||||
|
||||
interface Caller
|
||||
{
|
||||
function getAppKey():string;
|
||||
|
||||
function getAppSecret():string;
|
||||
|
||||
function getHost():string;
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Helper\Deepblue;
|
||||
|
||||
use Magento\Framework\App\Helper\Context;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Stemcell\Customer\Api\Data\AvatrInterface;
|
||||
use Stemcell\Customer\Helper\CarSeriesClueInterface;
|
||||
use phpseclib3\Crypt\RSA\PublicKey;
|
||||
use phpseclib3\Crypt\PublicKeyLoader;
|
||||
|
||||
class CluePost extends \Magento\Framework\App\Helper\AbstractHelper implements Caller, CarSeriesClueInterface
|
||||
{
|
||||
/**
|
||||
* config must contains follow data:app_key, app_secret, host:请求地址, pubKey:RSA public key
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private array $config = [
|
||||
'host' => 'https://clue.changan.com.cn:5786',
|
||||
'app_key' => '2e0a1703b9784ca89e9368e21a119b4c',
|
||||
'app_secret' => 'a6049e8b647ae0339111b39ffaf1cab0',
|
||||
'pubKey' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArJiVab+4lEatCcpLQHef8+MyjcSKmOLqcGPb+ObtwvLxbyRQ/eM2AO3mDAPFZddYhl/hSeLBsWIt1vY4WKUtkmm5mRRLkFQuLj0FRhRKxHBstKNXd0MX+ekz4Jx2FaulleRfJ7PbGpCZJNDzMmZHuRng0g+1g2Avk1B5NQ9dSn3SzRbHXAiY8aCkyUs3i8Hb/nMq2ivj9AJjgsc3LcltKLG/Lnlvr2b17WLKNjPxdyj112+xR0CA99/hBZo2cxDfjUIhDjBo9pcCRzA3AnFOnRQ44fjjcDwwoMhvpgnbt7D+5ek4wDzgnL4hai3naCIfzlnYQSVlCII/NUURs9WjZwIDAQAB',
|
||||
];
|
||||
private Token $tokenHelper;
|
||||
|
||||
private array $requestData = [];
|
||||
|
||||
/**
|
||||
* RSA public key
|
||||
* @var string
|
||||
*/
|
||||
private string $pubKey = '';
|
||||
private \Magento\Framework\HTTP\Client\Curl $curl;
|
||||
|
||||
private string $response;
|
||||
|
||||
private AvatrInterface $clue;
|
||||
private Transformers $transformers;
|
||||
private string $distributorCode;
|
||||
|
||||
private string $carSeries;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private string $line;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Token $tokenHelper,
|
||||
\Magento\Framework\HTTP\Client\Curl $curl,
|
||||
Transformers $transformers
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->tokenHelper = $tokenHelper;
|
||||
$this->curl = $curl;
|
||||
$this->transformers = $transformers;
|
||||
$this->tokenHelper->setCaller($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function getHost(): string
|
||||
{
|
||||
return $this->_getData('host');
|
||||
}
|
||||
|
||||
public function setConfig(array $config = []): static
|
||||
{
|
||||
$this->config = array_merge($this->config, $config);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
function _getData(string $key): string
|
||||
{
|
||||
if (isset($this->config[$key]) && !empty($this->config[$key])) {
|
||||
return $this->config[$key];
|
||||
}
|
||||
|
||||
throw new LocalizedException(__($key.' is not set'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
function getAppSecret(): string
|
||||
{
|
||||
return $this->_getData('app_secret');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
function getAppKey(): string
|
||||
{
|
||||
return $this->_getData('app_key');
|
||||
}
|
||||
|
||||
/**
|
||||
* get RSA public key
|
||||
* @return string
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function getPubKey(): string
|
||||
{
|
||||
return "-----BEGIN PUBLIC KEY-----\n" .
|
||||
wordwrap(
|
||||
$this->_getData('pubKey'),
|
||||
64,
|
||||
"\n",
|
||||
true
|
||||
) . "\n-----END PUBLIC KEY-----";
|
||||
}
|
||||
|
||||
/**
|
||||
* data must contains follow data:
|
||||
* customerPhoneNo: 客户电话
|
||||
* outwardOriginId: 线索生成系统的原始id
|
||||
* city: 客户城市编码(国标) https://github.com/modood/Administrative-divisions-of-China/tree/master/dist
|
||||
*
|
||||
* @param array $data
|
||||
* @return $this
|
||||
*/
|
||||
public function setRequestData(array $data): static
|
||||
{
|
||||
$info = [
|
||||
'brand' => '80081004',
|
||||
'leaveInfoTime' => date('Y-m-d H:i:s'),
|
||||
'sourceCd' => '0201700260000'
|
||||
];
|
||||
if ($this->line=='启源') {
|
||||
$info['brand'] = '80081005';
|
||||
$info['sourceCd'] = '0200300140010';
|
||||
}
|
||||
$this->requestData = array_merge($info, $data);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRequestData(): array
|
||||
{
|
||||
if (!empty($this->requestData)) {
|
||||
return $this->requestData;
|
||||
}
|
||||
|
||||
$leadsCreateTime = $this->clue->getCreatedAt();
|
||||
if (!$leadsCreateTime) {
|
||||
$leadsCreateTime = date('Y-m-d H:i:s');
|
||||
}
|
||||
$this->requestData = [
|
||||
'brand' => '80081004',
|
||||
'leaveInfoTime' => $leadsCreateTime,
|
||||
'sourceCd' => '0201700260000',
|
||||
'customerName' => $this->clue->getName(),
|
||||
'customerPhoneNo' => $this->clue->getTelephone(),
|
||||
'outwardOriginId' => 'bbycm-'.str_pad($this->clue->getId(), 12, '0', STR_PAD_LEFT),
|
||||
'city' => $this->clue->getCityId(),
|
||||
'province' => $this->clue->getProvinceId(),
|
||||
'intentionCarSeries' => $this->carSeries,
|
||||
];
|
||||
if (is_numeric($this->distributorCode)) {
|
||||
$this->requestData['distributorId'] = $this->distributorCode;
|
||||
} else {
|
||||
$this->requestData['distributorCode'] = $this->distributorCode;
|
||||
}
|
||||
if ($this->line=='启源') {
|
||||
$this->requestData['brand'] = '80081005';
|
||||
$this->requestData['sourceCd'] = '0200300140010';
|
||||
$this->requestData['marketingActivityName'] = '重庆福戈文化传播有限公司';
|
||||
$this->requestData['marketingActivityNo'] = '2024mtjjrcqfg';
|
||||
}
|
||||
return $this->requestData;
|
||||
}
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function sign(): string
|
||||
{
|
||||
return base64_encode($this->publicEncrypt(json_encode($this->requestData)));
|
||||
}
|
||||
|
||||
protected function publicEncrypt(string $data)
|
||||
{
|
||||
if (!is_string($data)) {
|
||||
return null;
|
||||
}
|
||||
$dataLength = mb_strlen($data);
|
||||
$offet = 0;
|
||||
$length = 128;
|
||||
$i = 0;
|
||||
$string = '';
|
||||
while ($dataLength - $offet > 0) {
|
||||
if ($dataLength - $offet > $length) {
|
||||
$str = mb_substr($data, $offet, $length);
|
||||
} else {
|
||||
$str = mb_substr($data, $offet, $dataLength - $offet);
|
||||
}
|
||||
$encrypted = '';
|
||||
openssl_public_encrypt($str,$encrypted, $this->getPubKey());
|
||||
$string .= $encrypted;
|
||||
$i ++;
|
||||
$offet = $i * $length;
|
||||
}
|
||||
return base64_encode($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function getRequestUrl(): string
|
||||
{
|
||||
return rtrim($this->getHost(), "/") . '/api/interface/commonClue/createClue';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Token
|
||||
*/
|
||||
public function getTokenHelper(): Token
|
||||
{
|
||||
return $this->tokenHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function post(): self
|
||||
{
|
||||
$body = json_encode([array_merge($this->getRequestData(), ['data'=>$this->sign()])]);
|
||||
|
||||
$token = $this->tokenHelper->getToken();
|
||||
$this->curl->addHeader("Content-Type", "application/json");
|
||||
$this->curl->addHeader('token', $token);
|
||||
$this->curl->addHeader('isEncipher', false);
|
||||
$this->curl->post( $this->getRequestUrl(), $body);
|
||||
|
||||
$this->response = $this->curl->getBody();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function transform(array $from): array
|
||||
{
|
||||
$this->distributorCode = $from[5];
|
||||
$this->line = $from[2];
|
||||
if(!$carSeries = $this->transformers->getCarSeriesCode(trim($from[6]))){
|
||||
|
||||
$carSeries = $this->transformers->getCarSeriesCode(trim($from[2]).trim($from[6]));
|
||||
|
||||
if(!$carSeries) {
|
||||
|
||||
throw new \Exception('车系:'.$from[6].'不存在');
|
||||
}
|
||||
}
|
||||
|
||||
$this->carSeries = $carSeries;
|
||||
return $this->transformers->transform($from);
|
||||
}
|
||||
|
||||
public function setClue(AvatrInterface $clue): CarSeriesClueInterface
|
||||
{
|
||||
$this->clue = $clue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isSuccess(): bool
|
||||
{
|
||||
$response = $this->getResponse();
|
||||
return isset($response['code']) && $response['code']==200 && $response['total'] > 0;
|
||||
}
|
||||
|
||||
public function getResponse(): array
|
||||
{
|
||||
$response = json_decode($this->response, true);
|
||||
return is_array($response)? $response:[];
|
||||
}
|
||||
|
||||
public function reset(): CarSeriesClueInterface
|
||||
{
|
||||
$this->requestData = [];
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Helper\Deepblue;
|
||||
|
||||
use Magento\Framework\App\Helper\Context;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
|
||||
class Token extends \Magento\Framework\App\Helper\AbstractHelper
|
||||
{
|
||||
const DEEPBLUE_TOKEN_IDENTIFIER = 'DEEPBLUE-TOKEN-IDENTIFIER-';
|
||||
protected \Magento\Framework\HTTP\Client\Curl $curl;
|
||||
|
||||
protected Caller $caller;
|
||||
|
||||
private int $timestamp = 0;
|
||||
private \Magento\Framework\App\CacheInterface $cache;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
\Magento\Framework\HTTP\Client\Curl $curl,
|
||||
\Magento\Framework\App\CacheInterface $cache
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->curl = $curl;
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
public function setCaller(Caller $caller): static
|
||||
{
|
||||
$this->caller = $caller;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function getTimestamp(): int
|
||||
{
|
||||
if (!$this->timestamp) {
|
||||
return $this->timestamp = round(microtime(true) * 1000);
|
||||
}
|
||||
|
||||
return $this->timestamp;
|
||||
}
|
||||
|
||||
protected function sign(): string
|
||||
{
|
||||
return md5(
|
||||
$this->caller->getAppKey() . $this->getTimestamp() . $this->caller->getAppSecret()
|
||||
);
|
||||
}
|
||||
|
||||
protected function getRequestData(): array
|
||||
{
|
||||
return [
|
||||
'sign' => $this->sign(),
|
||||
'appKey' => $this->caller->getAppKey(),
|
||||
'timestamp' => $this->getTimestamp(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getRequestUrl(): string
|
||||
{
|
||||
return rtrim($this->caller->getHost(), "/") . '/api/auth/thirdPartyToken';
|
||||
}
|
||||
|
||||
protected function post(): array
|
||||
{
|
||||
$body = json_encode($this->getRequestData());
|
||||
|
||||
$this->curl->addHeader("Content-Type", "application/json");
|
||||
$this->curl->post( $this->getRequestUrl(), $body);
|
||||
|
||||
$body = json_decode($this->curl->getBody(), true);
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function tokenCache(): string
|
||||
{
|
||||
$lifeTime = 24*3600-60;
|
||||
$token = $this->post();
|
||||
if (isset($token['code']) && $token['code'] == 200) {
|
||||
$cacheData = json_encode([
|
||||
'token' => $token['data'],
|
||||
'created_at' => time()
|
||||
]);
|
||||
|
||||
$this->cache->save($cacheData, self::DEEPBLUE_TOKEN_IDENTIFIER, [], $lifeTime);
|
||||
return $token['data'];
|
||||
}
|
||||
|
||||
throw new LocalizedException(__('从/api/auth/thirdPartyToken获取token失败,原因:'.$token['msg'].', code:'.$token['code']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function getToken(): string
|
||||
{
|
||||
$token = $this->cache->load(self::DEEPBLUE_TOKEN_IDENTIFIER);
|
||||
if (!$token) {
|
||||
return $this->tokenCache();
|
||||
}
|
||||
|
||||
$cacheData = json_decode($token, true);
|
||||
if ((time() - $cacheData['created_at']) > 60) {
|
||||
return $this->tokenCache();
|
||||
}
|
||||
|
||||
return $cacheData['token'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Helper\Deepblue;
|
||||
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Module\Dir as ModuleDir;
|
||||
use Stemcell\Customer\Helper\TransformersInterface;
|
||||
|
||||
/**
|
||||
* transform original province and city name to Avatr require id
|
||||
*/
|
||||
class Transformers implements TransformersInterface
|
||||
{
|
||||
private ModuleDir $moduleDir;
|
||||
|
||||
protected array $data = [];
|
||||
|
||||
protected array $regions = [];
|
||||
public function __construct(
|
||||
ModuleDir $moduleDir
|
||||
) {
|
||||
$this->moduleDir = $moduleDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path a relative path to $module, must begin with /
|
||||
* @param string $module
|
||||
* @return array
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function loadDataFromFile(string $path, string $module='Stemcell_Customer') : array
|
||||
{
|
||||
if (isset($this->data[$path]) && !empty($this->data[$path])) {
|
||||
return $this->data[$path];
|
||||
}
|
||||
$file = $this->moduleDir->getDir($module).$path;
|
||||
if (!file_exists($file)) {
|
||||
throw new LocalizedException(__("$file not exist"));
|
||||
}
|
||||
|
||||
$data = json_decode(file_get_contents($file), true);
|
||||
if (!$data) {
|
||||
throw new LocalizedException(__("$file content is not json"));
|
||||
}
|
||||
|
||||
return $this->data[$path] = $data;
|
||||
}
|
||||
|
||||
protected function chineseEncoding(string $str) : string
|
||||
{
|
||||
// return mb_convert_encoding($str, 'UTF-8', ['gb2312', 'gbk']);
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $row original row data
|
||||
* @return array data order by ['name', 'telephone', 'favorite_vehicle', 'province_id', 'city_id']
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function transform(array $row): array
|
||||
{
|
||||
$region = $this->getRegionId($row[3], $row[4]);
|
||||
// $row[2] = $this->chineseEncoding($row[2]);
|
||||
|
||||
return [$row[0], $row[1], $this->getCarModelId($row[2]), $region[0], $region[1]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function getRegionId(string $province, string $city)
|
||||
{
|
||||
$city = str_replace(' ', '', $city);
|
||||
// $city = $this->chineseEncoding($city);
|
||||
// $province = $this->chineseEncoding($province);
|
||||
if (isset($this->regions[$city])) {
|
||||
return $this->regions[$city];
|
||||
}
|
||||
|
||||
if (mb_strlen($city) < 2) {
|
||||
throw new LocalizedException(__("invalid city name: ".$city));
|
||||
}
|
||||
|
||||
$regions = $this->loadDataFromFile('/data/pc-code.json');
|
||||
foreach ($regions as $item) {
|
||||
if (mb_strpos($item['name'], $province) === 0 ) {
|
||||
foreach ($item['children'] as $child) {
|
||||
if (mb_strpos($child['name'], $city) === 0 ) {
|
||||
return $this->regions[$city] = [
|
||||
str_pad($item['code'], 6, '0'),
|
||||
str_pad($child['code'], 6, '0')
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [null, null];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function getCarModelId(string $carModel)
|
||||
{
|
||||
$carModel = str_replace(' ', '', $carModel);
|
||||
// $carModel = $this->chineseEncoding($carModel);
|
||||
$carModels = $this->loadDataFromFile('/data/car-models.json');
|
||||
return $carModels[$carModel] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $series
|
||||
* @return string | null
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function getCarSeriesCode(string $series): ?string
|
||||
{
|
||||
$series = str_replace(' ', '', $series);
|
||||
// $series = $this->chineseEncoding($series);
|
||||
// var_dump($series);
|
||||
// echo '<br/><br/><br/>';
|
||||
$data = $this->loadDataFromFile('/data/car-series.json');
|
||||
// var_dump($data[$series]);
|
||||
// echo '<br/><br/><br/>';
|
||||
return $data[$series] ?? null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Helper;
|
||||
|
||||
use Magento\Framework\App\Helper\Context;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Stemcell\Customer\Model\ResourceModel\Lab;
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
|
||||
class LabDownload extends \Magento\Framework\App\Helper\AbstractHelper
|
||||
{
|
||||
private Filesystem\Directory\WriteInterface $directory;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Filesystem $filesystem,
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
|
||||
|
||||
}
|
||||
|
||||
protected function getHeaders()
|
||||
{
|
||||
return [
|
||||
'Lab Id',
|
||||
'PI SAP Id',
|
||||
'订货账户',
|
||||
'经销商',
|
||||
'销售',
|
||||
];
|
||||
}
|
||||
|
||||
protected function getRowFields()
|
||||
{
|
||||
return [
|
||||
'lab_code',
|
||||
'pi_sap_id',
|
||||
'booking_account',
|
||||
'customer_name',
|
||||
'salesperson_name'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Lab\Collection $data
|
||||
* @return array
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||||
*/
|
||||
public function write(Lab\Collection $data)
|
||||
{
|
||||
$styles = [
|
||||
'alignment' => [
|
||||
'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
|
||||
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
|
||||
],
|
||||
];
|
||||
$spreadSheet = new Spreadsheet();
|
||||
$writer = IOFactory::createWriter($spreadSheet, 'Xlsx');
|
||||
$worksheet = $spreadSheet->getActiveSheet();
|
||||
$columnIndex = 'A';
|
||||
foreach ($this->getHeaders() as $row) {
|
||||
$cell = $worksheet->getCell($columnIndex.'1');
|
||||
$cell->getAppliedStyle()->applyFromArray($styles);
|
||||
$cell->setValue($row);
|
||||
$columnIndex++;
|
||||
}
|
||||
$worksheet->getRowDimension(1)->setRowHeight(20);
|
||||
$rowIndex = 2;
|
||||
foreach ($data as $lab) {
|
||||
$columnIndex = 'A';
|
||||
/* @var $lab \Stemcell\Customer\Model\Lab */
|
||||
foreach ($this->getRowFields() as $field) {
|
||||
$worksheet->getColumnDimension($columnIndex)->setWidth(15);
|
||||
$worksheet->getRowDimension($rowIndex)->setRowHeight(20);
|
||||
$cell = $worksheet->getCell($columnIndex.$rowIndex);
|
||||
$cell->getAppliedStyle()->applyFromArray($styles);
|
||||
$cell->setValue($lab->getData($field));
|
||||
$columnIndex++;
|
||||
}
|
||||
$rowIndex++;
|
||||
}
|
||||
$this->directory->create('export');
|
||||
$file = $this->directory->getAbsolutePath('export/lab-'.date('YmdHis').'.xlsx');
|
||||
$writer->save($file);
|
||||
return [
|
||||
'type' => 'filename',
|
||||
'value' => $file,
|
||||
'rm' => true // can delete file after use
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Helper\Lynkco;
|
||||
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Magento\Framework\App\Helper\Context;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Stemcell\Customer\Api\Data\AvatrInterface;
|
||||
use Stemcell\Customer\Helper\CarSeriesClueInterface;
|
||||
use Stemcell\Customer\Helper\Deepblue\Caller;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use IonBazan\AliyunSigner\Key;
|
||||
use IonBazan\AliyunSigner\Guzzle\RequestSignerMiddleware;
|
||||
|
||||
class CluePost extends \Magento\Framework\App\Helper\AbstractHelper implements Caller, CarSeriesClueInterface
|
||||
{
|
||||
/**
|
||||
* config must contains follow data:app_key, app_secret, host:请求地址, pubKey:RSA public key
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private array $config = [
|
||||
'host' => 'https://lead-vma.lynkco.com.cn',
|
||||
'app_key' => '204033053',
|
||||
'app_secret' => 'pflQoSYIPSXMnv3hancZtClkP3ftBbqn',
|
||||
'activityCode' => 'GGTF20240726002',
|
||||
'leadSourceCode' => 'GGTF0002'
|
||||
];
|
||||
|
||||
private array $requestData = [];
|
||||
|
||||
/**
|
||||
* RSA public key
|
||||
* @var string
|
||||
*/
|
||||
private string $pubKey = '';
|
||||
private \Magento\Framework\HTTP\Client\Curl $curl;
|
||||
|
||||
private string $response;
|
||||
|
||||
private AvatrInterface $clue;
|
||||
private Transformers $transformers;
|
||||
|
||||
/**
|
||||
* 经销商编码
|
||||
* @var string
|
||||
*/
|
||||
private string $distributorCode;
|
||||
|
||||
/**
|
||||
* 达人
|
||||
* @var string
|
||||
*/
|
||||
private string $remark;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
\Magento\Framework\HTTP\Client\Curl $curl,
|
||||
Transformers $transformers
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->curl = $curl;
|
||||
$this->transformers = $transformers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function getHost(): string
|
||||
{
|
||||
return $this->_getData('host');
|
||||
}
|
||||
|
||||
public function setConfig(array $config = []): static
|
||||
{
|
||||
$this->config = array_merge($this->config, $config);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
function _getData(string $key): string
|
||||
{
|
||||
if (isset($this->config[$key]) && !empty($this->config[$key])) {
|
||||
return $this->config[$key];
|
||||
}
|
||||
|
||||
throw new LocalizedException(__($key.' is not set'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
function getAppSecret(): string
|
||||
{
|
||||
return $this->_getData('app_secret');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
function getAppKey(): string
|
||||
{
|
||||
return $this->_getData('app_key');
|
||||
}
|
||||
|
||||
/**
|
||||
* data must contains follow data:
|
||||
* customerPhoneNo: 客户电话
|
||||
* outwardOriginId: 线索生成系统的原始id
|
||||
* city: 客户城市编码(国标) https://github.com/modood/Administrative-divisions-of-China/tree/master/dist
|
||||
*
|
||||
* @param array $data
|
||||
* @return $this
|
||||
*/
|
||||
public function setRequestData(array $data): static
|
||||
{
|
||||
$this->requestData = array_merge([
|
||||
'activityCode' => 'GGTF20240726002',
|
||||
'leadSourceCode' => 'GGTF0002',
|
||||
], $data);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRequestData(): array
|
||||
{
|
||||
if (!empty($this->requestData)) {
|
||||
return $this->requestData;
|
||||
}
|
||||
|
||||
$this->requestData = [
|
||||
'activityCode' => 'GGTF20240726002',
|
||||
'leadSourceCode' => 'GGTF0002',
|
||||
'mobile' => $this->clue->getTelephone(),
|
||||
'name' => $this->clue->getName(),
|
||||
'seriesCode' => $this->clue->getFavoriteVehicle(),
|
||||
'dealercode' => $this->distributorCode,
|
||||
];
|
||||
if ($this->remark) {
|
||||
$this->requestData['remark'] = $this->remark;
|
||||
}
|
||||
return $this->requestData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function post(): self
|
||||
{
|
||||
$signer = new RequestSigner(new Key($this->getAppKey(), $this->getAppSecret()));
|
||||
$middleware = new RequestSignerMiddleware($signer);
|
||||
$stack = HandlerStack::create();
|
||||
$stack->push($middleware);
|
||||
|
||||
$client = new Client([
|
||||
'handler' => $stack,
|
||||
'base_uri'=> $this->getHost(),
|
||||
'headers' => [
|
||||
'content-Type' => 'application/json' ,
|
||||
'accept' => 'application/json',
|
||||
]
|
||||
]);
|
||||
|
||||
$response = $client->post(
|
||||
'/api/v1/lead/mediaLeadInput',
|
||||
[\GuzzleHttp\RequestOptions::JSON => $this->getRequestData()]
|
||||
);
|
||||
$this->response = $response->getBody()->getContents();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function transform(array $from): array
|
||||
{
|
||||
$this->distributorCode = trim($from[3]);
|
||||
// $this->remark = mb_convert_encoding($from[4], 'UTF-8', 'gb2312');
|
||||
$this->remark = $from[4];
|
||||
return $this->transformers->transform($from);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AvatrInterface $clue
|
||||
* @return CarSeriesClueInterface
|
||||
*/
|
||||
public function setClue(AvatrInterface $clue): CarSeriesClueInterface
|
||||
{
|
||||
$this->clue = $clue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isSuccess(): bool
|
||||
{
|
||||
$response = $this->getResponse();
|
||||
return isset($response['success']) && $response['success']==true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getResponse(): array
|
||||
{
|
||||
$response = json_decode($this->response, true);
|
||||
return is_array($response)? $response:[];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CarSeriesClueInterface
|
||||
*/
|
||||
public function reset(): CarSeriesClueInterface
|
||||
{
|
||||
$this->requestData = [];
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Helper\Lynkco;
|
||||
|
||||
class HmacSHA256Digest extends \IonBazan\AliyunSigner\Digest\HmacSHA256Digest
|
||||
{
|
||||
public static function __set_state($array)
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Helper\Lynkco;
|
||||
|
||||
use IonBazan\AliyunSigner\Digest\DigestInterface;
|
||||
use IonBazan\AliyunSigner\Key;
|
||||
|
||||
class RequestSigner extends \IonBazan\AliyunSigner\RequestSigner
|
||||
{
|
||||
public function __construct(Key $key, DigestInterface $digest = new HmacSHA256Digest())
|
||||
{
|
||||
parent::__construct($key, $digest);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Helper\Lynkco;
|
||||
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Module\Dir as ModuleDir;
|
||||
use Stemcell\Customer\Helper\TransformersInterface;
|
||||
|
||||
/**
|
||||
* transform original province and city name to Avatr require id
|
||||
*/
|
||||
class Transformers implements TransformersInterface
|
||||
{
|
||||
private ModuleDir $moduleDir;
|
||||
|
||||
protected array $data = [];
|
||||
|
||||
protected array $regions = [];
|
||||
public function __construct(
|
||||
ModuleDir $moduleDir
|
||||
) {
|
||||
$this->moduleDir = $moduleDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path a relative path to $module, must begin with /
|
||||
* @param string $module
|
||||
* @return array
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function loadDataFromFile(string $path, string $module='Stemcell_Customer') : array
|
||||
{
|
||||
if (isset($this->data[$path]) && !empty($this->data[$path])) {
|
||||
return $this->data[$path];
|
||||
}
|
||||
$file = $this->moduleDir->getDir($module).$path;
|
||||
if (!file_exists($file)) {
|
||||
throw new LocalizedException(__("$file not exist"));
|
||||
}
|
||||
|
||||
$data = json_decode(file_get_contents($file), true);
|
||||
if (!$data) {
|
||||
throw new LocalizedException(__("$file content is not json"));
|
||||
}
|
||||
|
||||
return $this->data[$path] = $data;
|
||||
}
|
||||
|
||||
protected function chineseEncoding(string $str)
|
||||
{
|
||||
// return mb_convert_encoding($str, 'UTF-8', 'gb2312');
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $row original row data
|
||||
* @return array data order by ['name', 'telephone', 'favorite_vehicle', 'province_id', 'city_id']
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function transform(array $row): array
|
||||
{
|
||||
return [$this->chineseEncoding($row[0]), $row[1], $this->getCarModelId($row[2]), null, null];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
public function getCarModelId(string $carModel)
|
||||
{
|
||||
$carModel = str_replace(' ', '', $carModel);
|
||||
$carModel = $this->chineseEncoding($carModel);
|
||||
$carModels = $this->loadDataFromFile('/data/car-models.json');
|
||||
return $carModels[$carModel] ?? null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Helper;
|
||||
|
||||
interface TransformersInterface
|
||||
{
|
||||
public function transform(array $row): array;
|
||||
}
|
||||
@@ -0,0 +1,619 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Model;
|
||||
|
||||
use Magento\Customer\Api\AddressRepositoryInterface;
|
||||
use Magento\Customer\Api\CustomerMetadataInterface;
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Customer\Api\Data\AddressInterface;
|
||||
use Magento\Customer\Api\Data\CustomerInterface;
|
||||
use Magento\Customer\Api\Data\ValidationResultsInterfaceFactory;
|
||||
use Magento\Customer\Api\SessionCleanerInterface;
|
||||
use Magento\Customer\Helper\View as CustomerViewHelper;
|
||||
use Magento\Customer\Model\AccountConfirmation;
|
||||
use Magento\Customer\Model\AddressRegistry;
|
||||
use Magento\Customer\Model\AuthenticationInterface;
|
||||
use Magento\Customer\Model\Config\Share as ConfigShare;
|
||||
use Magento\Customer\Model\Customer;
|
||||
use Magento\Customer\Model\Customer as CustomerModel;
|
||||
use Magento\Customer\Model\Customer\CredentialsValidator;
|
||||
use Magento\Customer\Model\CustomerFactory;
|
||||
use Magento\Customer\Model\CustomerRegistry;
|
||||
use Magento\Customer\Model\EmailNotificationInterface;
|
||||
use Magento\Customer\Model\ForgotPasswordToken\GetCustomerByToken;
|
||||
use Magento\Customer\Model\Metadata\Validator;
|
||||
use Magento\Customer\Model\ResourceModel\Visitor\CollectionFactory;
|
||||
use Magento\Directory\Model\AllowedCountries;
|
||||
use Magento\Framework\Api\ExtensibleDataObjectConverter;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Framework\AuthorizationInterface;
|
||||
use Magento\Framework\DataObjectFactory as ObjectFactory;
|
||||
use Magento\Framework\Encryption\EncryptorInterface as Encryptor;
|
||||
use Magento\Framework\Encryption\Helper\Security;
|
||||
use Magento\Framework\Event\ManagerInterface;
|
||||
use Magento\Framework\Exception\InputException;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Exception\State\ExpiredException;
|
||||
use Magento\Framework\Exception\State\InputMismatchException;
|
||||
use Magento\Framework\Intl\DateTimeFactory;
|
||||
use Magento\Framework\Mail\Template\TransportBuilder;
|
||||
use Magento\Framework\Math\Random;
|
||||
use Magento\Framework\Reflection\DataObjectProcessor;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\Session\SaveHandlerInterface;
|
||||
use Magento\Framework\Session\SessionManagerInterface;
|
||||
use Magento\Framework\Stdlib\DateTime;
|
||||
use Magento\Framework\Stdlib\StringUtils as StringHelper;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Psr\Log\LoggerInterface as PsrLogger;
|
||||
|
||||
class AccountManagement extends \Magento\Customer\Model\AccountManagement
|
||||
{
|
||||
protected AddressRegistry $addressRegistry;
|
||||
|
||||
protected GetCustomerByToken $getByToken;
|
||||
|
||||
protected CustomerRegistry $customerRegistry;
|
||||
protected CredentialsValidator $credentialsValidator;
|
||||
protected CustomerRepositoryInterface $customerRepository;
|
||||
protected SessionCleanerInterface $sessionCleaner;
|
||||
|
||||
public function __construct(
|
||||
CustomerFactory $customerFactory,
|
||||
ManagerInterface $eventManager,
|
||||
StoreManagerInterface $storeManager,
|
||||
Random $mathRandom,
|
||||
Validator $validator,
|
||||
ValidationResultsInterfaceFactory $validationResultsDataFactory,
|
||||
AddressRepositoryInterface $addressRepository,
|
||||
CustomerMetadataInterface $customerMetadataService,
|
||||
CustomerRegistry $customerRegistry,
|
||||
PsrLogger $logger,
|
||||
Encryptor $encryptor,
|
||||
ConfigShare $configShare,
|
||||
StringHelper $stringHelper,
|
||||
CustomerRepositoryInterface $customerRepository,
|
||||
ScopeConfigInterface $scopeConfig,
|
||||
TransportBuilder $transportBuilder,
|
||||
DataObjectProcessor $dataProcessor,
|
||||
Registry $registry,
|
||||
CustomerViewHelper $customerViewHelper,
|
||||
DateTime $dateTime,
|
||||
Customer $customerModel,
|
||||
ObjectFactory $objectFactory,
|
||||
ExtensibleDataObjectConverter $extensibleDataObjectConverter,
|
||||
CredentialsValidator $credentialsValidator,
|
||||
DateTimeFactory $dateTimeFactory = null,
|
||||
AccountConfirmation $accountConfirmation = null,
|
||||
SessionManagerInterface $sessionManager = null,
|
||||
SaveHandlerInterface $saveHandler = null,
|
||||
CollectionFactory $visitorCollectionFactory = null,
|
||||
SearchCriteriaBuilder $searchCriteriaBuilder = null,
|
||||
AddressRegistry $addressRegistry,
|
||||
GetCustomerByToken $getByToken,
|
||||
AllowedCountries $allowedCountriesReader = null,
|
||||
SessionCleanerInterface $sessionCleaner,
|
||||
AuthorizationInterface $authorization = null
|
||||
) {
|
||||
parent::__construct($customerFactory, $eventManager, $storeManager, $mathRandom, $validator, $validationResultsDataFactory, $addressRepository, $customerMetadataService, $customerRegistry, $logger, $encryptor, $configShare, $stringHelper, $customerRepository, $scopeConfig, $transportBuilder, $dataProcessor, $registry, $customerViewHelper, $dateTime, $customerModel, $objectFactory, $extensibleDataObjectConverter, $credentialsValidator, $dateTimeFactory, $accountConfirmation, $sessionManager, $saveHandler, $visitorCollectionFactory, $searchCriteriaBuilder, $addressRegistry, $getByToken, $allowedCountriesReader, $sessionCleaner, $authorization);
|
||||
$this->addressRegistry = $addressRegistry;
|
||||
$this->getByToken = $getByToken;
|
||||
$this->customerRegistry = $customerRegistry;
|
||||
$this->credentialsValidator = $credentialsValidator;
|
||||
$this->customerRepository = $customerRepository;
|
||||
$this->sessionCleaner = $sessionCleaner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable Customer Address Validation
|
||||
*
|
||||
* @param CustomerInterface $customer
|
||||
* @throws NoSuchEntityException
|
||||
*/
|
||||
protected function disableAddressValidation($customer)
|
||||
{
|
||||
foreach ($customer->getAddresses() as $address) {
|
||||
$addressModel = $this->addressRegistry->retrieve($address->getId());
|
||||
$addressModel->setShouldIgnoreValidation(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set ignore_validation_flag for reset password flow to skip unnecessary address and customer validation
|
||||
*
|
||||
* @param Customer $customer
|
||||
* @return void
|
||||
*/
|
||||
protected function setIgnoreValidationFlag($customer)
|
||||
{
|
||||
$customer->setData('ignore_validation_flag', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the Reset Password Token for a customer.
|
||||
*
|
||||
* @param int $customerId
|
||||
* @param string $resetPasswordLinkToken
|
||||
*
|
||||
* @return bool
|
||||
* @throws ExpiredException If token is expired
|
||||
* @throws InputException If token or customer id is invalid
|
||||
* @throws InputMismatchException If token is mismatched
|
||||
* @throws LocalizedException
|
||||
* @throws NoSuchEntityException If customer doesn't exist
|
||||
* @SuppressWarnings(PHPMD.LongVariable)
|
||||
*/
|
||||
protected function validateResetPasswordToken($customerId, $resetPasswordLinkToken)
|
||||
{
|
||||
if ($customerId !== null && $customerId <= 0) {
|
||||
throw new InputException(
|
||||
__(
|
||||
'Invalid value of "%value" provided for the %fieldName field.',
|
||||
['value' => $customerId, 'fieldName' => 'customerId']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ($customerId === null) {
|
||||
//Looking for the customer.
|
||||
$customerId = $this->getByToken
|
||||
->execute($resetPasswordLinkToken)
|
||||
->getId();
|
||||
}
|
||||
if (!is_string($resetPasswordLinkToken) || empty($resetPasswordLinkToken)) {
|
||||
$params = ['fieldName' => 'resetPasswordLinkToken'];
|
||||
throw new InputException(__('"%fieldName" is required. Enter and try again.', $params));
|
||||
}
|
||||
$customerSecureData = $this->customerRegistry->retrieveSecureData($customerId);
|
||||
$rpToken = $customerSecureData->getRpToken();
|
||||
$rpTokenCreatedAt = $customerSecureData->getRpTokenCreatedAt();
|
||||
if (!Security::compareStrings($rpToken, $resetPasswordLinkToken)) {
|
||||
throw new InputMismatchException(__('The password token is mismatched. Reset and try again.'));
|
||||
} elseif ($this->isResetPasswordLinkTokenExpired($rpToken, $rpTokenCreatedAt)) {
|
||||
throw new ExpiredException(__('The password token is expired. Reset and try again.'));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function resetPassword($email, $resetToken, $newPassword)
|
||||
{
|
||||
if (!$email && $resetToken) {
|
||||
$customer = $this->getByToken->execute($resetToken);
|
||||
$email = $customer->getEmail();
|
||||
} else {
|
||||
$customer = $this->customerRepository->get($email);
|
||||
}
|
||||
|
||||
// No need to validate customer and customer address while saving customer reset password token
|
||||
$this->disableAddressValidation($customer);
|
||||
$this->setIgnoreValidationFlag($customer);
|
||||
|
||||
//Validate Token and new password strength
|
||||
if ($resetToken) {
|
||||
$this->validateResetPasswordToken($customer->getId(), $resetToken);
|
||||
}
|
||||
|
||||
$this->credentialsValidator->checkPasswordDifferentFromEmail(
|
||||
$email,
|
||||
$newPassword
|
||||
);
|
||||
$this->checkPasswordStrength($newPassword);
|
||||
//Update secure data
|
||||
$customerSecure = $this->customerRegistry->retrieveSecureData($customer->getId());
|
||||
$customerSecure->setRpToken(null);
|
||||
$customerSecure->setRpTokenCreatedAt(null);
|
||||
$customerSecure->setPasswordHash($this->createPasswordHash($newPassword));
|
||||
$this->sessionCleaner->clearFor((int)$customer->getId());
|
||||
$this->customerRepository->save($customer);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Model;
|
||||
|
||||
use Stemcell\ChineseDirectory\Model\CollectionFactory;
|
||||
use Magento\Customer\Api\AddressMetadataInterface;
|
||||
use Magento\Customer\Api\Data\AddressInterface;
|
||||
use Magento\Customer\Api\Data\AddressInterfaceFactory;
|
||||
use Magento\Customer\Api\Data\RegionInterfaceFactory;
|
||||
use Magento\Customer\Model\Address\CustomAttributeListInterface;
|
||||
use Magento\Customer\Model\CustomerFactory;
|
||||
use Magento\Directory\Helper\Data;
|
||||
use Magento\Directory\Model\CountryFactory;
|
||||
use Magento\Directory\Model\RegionFactory;
|
||||
use Magento\Eav\Model\Config;
|
||||
use Magento\Framework\Api\AttributeValueFactory;
|
||||
use Magento\Framework\Api\DataObjectHelper;
|
||||
use Magento\Framework\Api\ExtensionAttributesFactory;
|
||||
use Magento\Framework\Data\Collection\AbstractDb;
|
||||
use Magento\Framework\Indexer\IndexerRegistry;
|
||||
use Magento\Framework\Model\Context;
|
||||
use Magento\Framework\Model\ResourceModel\AbstractResource;
|
||||
use Magento\Framework\Reflection\DataObjectProcessor;
|
||||
use Magento\Framework\Registry;
|
||||
|
||||
class Address extends \Magento\Customer\Model\Address
|
||||
{
|
||||
protected CustomAttributeListInterface $attributeList;
|
||||
|
||||
protected CollectionFactory $collectionFactory;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Registry $registry,
|
||||
ExtensionAttributesFactory $extensionFactory,
|
||||
AttributeValueFactory $customAttributeFactory,
|
||||
Data $directoryData,
|
||||
Config $eavConfig,
|
||||
\Magento\Customer\Model\Address\Config $addressConfig,
|
||||
RegionFactory $regionFactory,
|
||||
CountryFactory $countryFactory,
|
||||
AddressMetadataInterface $metadataService,
|
||||
AddressInterfaceFactory $addressDataFactory,
|
||||
RegionInterfaceFactory $regionDataFactory,
|
||||
DataObjectHelper $dataObjectHelper,
|
||||
CustomerFactory $customerFactory,
|
||||
DataObjectProcessor $dataProcessor,
|
||||
IndexerRegistry $indexerRegistry,
|
||||
CollectionFactory $collectionFactory,
|
||||
AbstractResource $resource = null,
|
||||
AbstractDb $resourceCollection = null,
|
||||
array $data = []
|
||||
) {
|
||||
$this->collectionFactory = $collectionFactory;
|
||||
parent::__construct(
|
||||
$context, $registry,
|
||||
$extensionFactory,
|
||||
$customAttributeFactory,
|
||||
$directoryData,
|
||||
$eavConfig,
|
||||
$addressConfig,
|
||||
$regionFactory,
|
||||
$countryFactory,
|
||||
$metadataService,
|
||||
$addressDataFactory,
|
||||
$regionDataFactory,
|
||||
$dataObjectHelper,
|
||||
$customerFactory,
|
||||
$dataProcessor,
|
||||
$indexerRegistry,
|
||||
$resource,
|
||||
$resourceCollection,
|
||||
$data
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $type
|
||||
* @param int $administrativeId
|
||||
* @return \Magento\Framework\DataObject
|
||||
*/
|
||||
public function getAdministrativeName(String $type, $administrativeId) {
|
||||
if ($administrativeId===null){
|
||||
$this->_logger->error('Argument ($administrativeId) is null, Argument ($type):'.$type);
|
||||
return new \Magento\Framework\DataObject();
|
||||
}
|
||||
if (!in_array(strtolower($type), ['city', 'district', 'town', 'region'])) {
|
||||
throw new \InvalidArgumentException(__('Invalid parameter type'));
|
||||
}
|
||||
$collection = $this->collectionFactory->create(strtolower($type))
|
||||
->addFieldToFilter('code', $administrativeId)
|
||||
->addFieldToSelect('*');
|
||||
|
||||
if ($type == 'region') {
|
||||
$collection->addFieldToFilter('country_id', 'CN');
|
||||
}
|
||||
return $collection->getFirstItem();
|
||||
}
|
||||
|
||||
public function updateData(AddressInterface $address)
|
||||
{
|
||||
// Set all attributes
|
||||
$attributes = $this->dataProcessor
|
||||
->buildOutputDataArray($address, AddressInterface::class);
|
||||
|
||||
foreach ($attributes as $attributeCode => $attributeData) {
|
||||
if (AddressInterface::REGION === $attributeCode) {
|
||||
$this->setRegion($address->getRegion()->getRegion());
|
||||
$this->setRegionCode($address->getRegion()->getRegionCode());
|
||||
$this->setRegionId($address->getRegion()->getRegionId());
|
||||
} else {
|
||||
$this->setDataUsingMethod($attributeCode, $attributeData);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->getCity()) {
|
||||
$cityCode = $address->getCustomAttribute('city_code')? $address->getCustomAttribute('city_code')->getValue():null;
|
||||
$city = $this->getAdministrativeName('city', $cityCode);
|
||||
$this->setData('city', $city->getData('name'));
|
||||
}
|
||||
|
||||
$this->setData('postcode', '0000000');
|
||||
$districtCode = $address->getCustomAttribute('district_code')? $address->getCustomAttribute('district_code')->getValue():null;
|
||||
$district = $this->getAdministrativeName('district', $districtCode);
|
||||
$this->setCustomAttribute('district', $district->getData('name'));
|
||||
|
||||
$districtCode = $address->getCustomAttribute('town_code')? $address->getCustomAttribute('town_code')->getValue():null;
|
||||
$district = $this->getAdministrativeName('town', $districtCode);
|
||||
|
||||
$this->setCustomAttribute('town', $district->getData('name'));
|
||||
$districtCode = $address->getCustomAttribute('city_code')? $address->getCustomAttribute('city_code')->getValue():null;
|
||||
$this->setCustomAttribute('city_code', $districtCode);
|
||||
$districtCode = $address->getCustomAttribute('district_code')? $address->getCustomAttribute('district_code')->getValue():null;
|
||||
$this->setCustomAttribute('district_code', $districtCode);
|
||||
$districtCode = $address->getCustomAttribute('town_code')? $address->getCustomAttribute('town_code')->getValue():null;
|
||||
$this->setCustomAttribute('town_code', $districtCode);
|
||||
|
||||
|
||||
// Need to explicitly set this due to discrepancy in the keys between model and data object
|
||||
$this->setIsDefaultBilling($address->isDefaultBilling());
|
||||
$this->setIsDefaultShipping($address->isDefaultShipping());
|
||||
$customAttributes = $address->getCustomAttributes();
|
||||
if ($customAttributes !== null) {
|
||||
foreach ($customAttributes as $attribute) {
|
||||
$this->setData($attribute->getAttributeCode(), $attribute->getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Stemcell\Customer\Model\Address\Validator;
|
||||
|
||||
use Magento\Customer\Model\Address\AbstractAddress;
|
||||
use Magento\Framework\Validator\NotEmpty;
|
||||
use Magento\Framework\Validator\ValidatorChain;
|
||||
use Magento\Directory\Helper\Data;
|
||||
use Magento\Directory\Model\AllowedCountries;
|
||||
use Magento\Framework\Escaper;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
|
||||
/**
|
||||
* Address country and region validator.
|
||||
*/
|
||||
class Country extends \Magento\Customer\Model\Address\Validator\Country
|
||||
{
|
||||
/**
|
||||
* @var Escaper
|
||||
*/
|
||||
protected $escaper;
|
||||
|
||||
/**
|
||||
* @var Data
|
||||
*/
|
||||
protected $directoryData;
|
||||
|
||||
/**
|
||||
* @var AllowedCountries
|
||||
*/
|
||||
protected $allowedCountriesReader;
|
||||
|
||||
/**
|
||||
* @param Data $directoryData
|
||||
* @param AllowedCountries $allowedCountriesReader
|
||||
* @param Escaper|null $escaper
|
||||
*/
|
||||
public function __construct(
|
||||
Data $directoryData,
|
||||
AllowedCountries $allowedCountriesReader,
|
||||
Escaper $escaper = null
|
||||
) {
|
||||
$this->directoryData = $directoryData;
|
||||
$this->allowedCountriesReader = $allowedCountriesReader;
|
||||
$this->escaper = $escaper ?? ObjectManager::getInstance()->get(
|
||||
Escaper::class
|
||||
);
|
||||
parent::__construct($directoryData, $allowedCountriesReader, $escaper);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validate(AbstractAddress $address)
|
||||
{
|
||||
$errors = $this->validateCountry($address);
|
||||
if (empty($errors)) {
|
||||
$errors = $this->validateRegion($address);
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate country existence.
|
||||
*
|
||||
* @param AbstractAddress $address
|
||||
* @return array
|
||||
*/
|
||||
private function validateCountry(AbstractAddress $address)
|
||||
{
|
||||
$countryId = $address->getCountryId();
|
||||
$errors = [];
|
||||
if (!ValidatorChain::is($countryId, NotEmpty::class)) {
|
||||
$errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'countryId']);
|
||||
} elseif (!in_array($countryId, $this->getWebsiteAllowedCountries($address), true)) {
|
||||
//Checking if such country exists.
|
||||
$errors[] = __(
|
||||
'Invalid value of "%value" provided for the %fieldName field.',
|
||||
['fieldName' => 'countryId', 'value' => $this->escaper->escapeHtml($countryId)]
|
||||
);
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractAddress $address
|
||||
* @return array
|
||||
* @throws \Magento\Framework\Validator\ValidateException
|
||||
*/
|
||||
private function validateRegion(AbstractAddress $address)
|
||||
{
|
||||
$errors = [];
|
||||
$countryId = $address->getCountryId();
|
||||
$countryModel = $address->getCountryModel();
|
||||
$regionCollection = $countryModel->getRegionCollection();
|
||||
$region = $address->getRegion();
|
||||
$regionId = (string)$address->getRegionId();
|
||||
$allowedRegions = $regionCollection->getAllIds();
|
||||
$isRegionRequired = $this->directoryData->isRegionRequired($countryId);
|
||||
if ($isRegionRequired && empty($allowedRegions) && !ValidatorChain::is($region, NotEmpty::class)) {
|
||||
//If region is required for country and country doesn't provide regions list
|
||||
//region must be provided.
|
||||
$errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'region']);
|
||||
} elseif ($allowedRegions && !ValidatorChain::is($regionId, NotEmpty::class) && $isRegionRequired) {
|
||||
//If country actually has regions and requires you to
|
||||
//select one then it must be selected.
|
||||
$errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'regionId']);
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return allowed counties per website.
|
||||
*
|
||||
* @param AbstractAddress $address
|
||||
* @return array
|
||||
*/
|
||||
private function getWebsiteAllowedCountries(AbstractAddress $address): array
|
||||
{
|
||||
$storeId = $address->getData('store_id');
|
||||
return $this->allowedCountriesReader->getAllowedCountries(ScopeInterface::SCOPE_STORE, $storeId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Stemcell\Customer\Model\Address\Validator;
|
||||
|
||||
use Magento\Customer\Api\AddressMetadataInterface;
|
||||
use Magento\Customer\Model\Address\AbstractAddress;
|
||||
use Magento\Framework\Validator\NotEmpty;
|
||||
use Magento\Framework\Validator\ValidatorChain;
|
||||
|
||||
/**
|
||||
* Address general fields validator.
|
||||
*/
|
||||
class General extends \Magento\Customer\Model\Address\Validator\General
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Eav\Model\Config
|
||||
*/
|
||||
protected $eavConfig;
|
||||
|
||||
/**
|
||||
* @var \Magento\Directory\Helper\Data
|
||||
*/
|
||||
protected $directoryData;
|
||||
|
||||
/**
|
||||
* @param \Magento\Eav\Model\Config $eavConfig
|
||||
* @param \Magento\Directory\Helper\Data $directoryData
|
||||
*/
|
||||
public function __construct(
|
||||
\Magento\Eav\Model\Config $eavConfig,
|
||||
\Magento\Directory\Helper\Data $directoryData
|
||||
) {
|
||||
$this->eavConfig = $eavConfig;
|
||||
$this->directoryData = $directoryData;
|
||||
parent::__construct($eavConfig, $directoryData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function validate(AbstractAddress $address)
|
||||
{
|
||||
$errors = array_merge(
|
||||
$this->checkRequiredFields($address),
|
||||
$this->checkOptionalFields($address)
|
||||
);
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractAddress $address
|
||||
* @return array
|
||||
* @throws \Magento\Framework\Validator\ValidateException
|
||||
*/
|
||||
private function checkRequiredFields(AbstractAddress $address)
|
||||
{
|
||||
$errors = [];
|
||||
if (!ValidatorChain::is($address->getFirstname(), NotEmpty::class)) {
|
||||
$errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'firstname']);
|
||||
}
|
||||
|
||||
if (!ValidatorChain::is($address->getStreetLine(1), NotEmpty::class)) {
|
||||
$errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'street']);
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AbstractAddress $address
|
||||
* @return array
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
* @throws \Magento\Framework\Validator\ValidateException
|
||||
*/
|
||||
private function checkOptionalFields(AbstractAddress $address)
|
||||
{
|
||||
$this->reloadAddressAttributes($address);
|
||||
$errors = [];
|
||||
if ($this->isTelephoneRequired()
|
||||
&& !ValidatorChain::is($address->getTelephone(), NotEmpty::class)
|
||||
) {
|
||||
$errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'telephone']);
|
||||
}
|
||||
|
||||
if ($this->isFaxRequired()
|
||||
&& !ValidatorChain::is($address->getFax(), NotEmpty::class)
|
||||
) {
|
||||
$errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'fax']);
|
||||
}
|
||||
|
||||
if ($this->isCompanyRequired()
|
||||
&& !ValidatorChain::is($address->getCompany(), NotEmpty::class)
|
||||
) {
|
||||
$errors[] = __('"%fieldName" is required. Enter and try again.', ['fieldName' => 'company']);
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if company field required in configuration.
|
||||
*
|
||||
* @return bool
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
private function isCompanyRequired()
|
||||
{
|
||||
return $this->eavConfig->getAttribute('customer_address', 'company')->getIsRequired();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if telephone field required in configuration.
|
||||
*
|
||||
* @return bool
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
private function isTelephoneRequired()
|
||||
{
|
||||
return $this->eavConfig->getAttribute('customer_address', 'telephone')->getIsRequired();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if fax field required in configuration.
|
||||
*
|
||||
* @return bool
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
private function isFaxRequired()
|
||||
{
|
||||
return $this->eavConfig->getAttribute('customer_address', 'fax')->getIsRequired();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload address attributes for the certain store
|
||||
*
|
||||
* @param AbstractAddress $address
|
||||
* @return void
|
||||
*/
|
||||
private function reloadAddressAttributes(AbstractAddress $address): void
|
||||
{
|
||||
$attributeSetId = $address->getAttributeSetId() ?: AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS;
|
||||
$address->setData('attribute_set_id', $attributeSetId);
|
||||
$this->eavConfig->getEntityAttributes(AddressMetadataInterface::ENTITY_TYPE_ADDRESS, $address);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Model\Attribute\Source;
|
||||
|
||||
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
|
||||
class CustomerType extends AbstractSource
|
||||
{
|
||||
|
||||
public function getAllOptions(): array
|
||||
{
|
||||
return $this->_options = [
|
||||
['label' => __('Distributor'), 'value' => 1],
|
||||
['label' => __('Personal'), 'value' => 2],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Model\Attribute\Source;
|
||||
|
||||
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
|
||||
|
||||
class ResearchFields extends AbstractSource
|
||||
{
|
||||
|
||||
public function getAllOptions()
|
||||
{
|
||||
return $this->_options = [
|
||||
['label' => __('细胞治疗'), 'value' => __('细胞治疗')],
|
||||
['label' => __('免疫研究'), 'value' => __('免疫研究')],
|
||||
['label' => __('抗体筛选'), 'value' => __('抗体筛选')],
|
||||
['label' => __('多能干细胞'), 'value' => __('多能干细胞')],
|
||||
['label' => __('间充质干细胞'), 'value' => __('间充质干细胞')],
|
||||
['label' => __('神经科学'), 'value' => __('神经科学')],
|
||||
['label' => __('造血干细胞'), 'value' => __('造血干细胞')],
|
||||
['label' => __('类器官'), 'value' => __('类器官')],
|
||||
['label' => __('其他'), 'value' => __('其他')],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Model;
|
||||
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
use Stemcell\Customer\Api\Data\AvatrInterface;
|
||||
|
||||
class Avatr extends AbstractModel implements AvatrInterface
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function _construct()
|
||||
{
|
||||
$this->_init(\Stemcell\Customer\Model\ResourceModel\Avatr::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->getData(self::NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
return $this->setData(self::NAME, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTelephone()
|
||||
{
|
||||
return $this->getData(self::TELEPHONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setTelephone($telephone)
|
||||
{
|
||||
return $this->setData(self::TELEPHONE, $telephone);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getFavoriteVehicle()
|
||||
{
|
||||
return $this->getData(self::FAVORITE_VEHICLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setFavoriteVehicle($favoriteVehicle)
|
||||
{
|
||||
return $this->setData(self::FAVORITE_VEHICLE, $favoriteVehicle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getProvinceId()
|
||||
{
|
||||
return $this->getData(self::PROVINCE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setProvinceId($provinceId)
|
||||
{
|
||||
return $this->setData(self::PROVINCE_ID, $provinceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCityId()
|
||||
{
|
||||
return $this->getData(self::CITY_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCityId($cityId)
|
||||
{
|
||||
return $this->setData(self::CITY_ID, $cityId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIsSent()
|
||||
{
|
||||
return $this->getData(self::IS_SENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setIsSent($isSent)
|
||||
{
|
||||
return $this->setData(self::IS_SENT, $isSent);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCreatedAt()
|
||||
{
|
||||
return $this->getData(self::CREATED_AT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->getData(self::RESPONSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setResponse(string $response)
|
||||
{
|
||||
return $this->setData(self::RESPONSE, $response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Model;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
|
||||
use Magento\Framework\Exception\CouldNotDeleteException;
|
||||
use Magento\Framework\Exception\CouldNotSaveException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Stemcell\Customer\Api\AvatrRepositoryInterface;
|
||||
use Stemcell\Customer\Api\Data\AvatrInterface;
|
||||
use Stemcell\Customer\Api\Data\AvatrInterfaceFactory;
|
||||
use Stemcell\Customer\Api\Data\AvatrSearchResultsInterfaceFactory;
|
||||
use Stemcell\Customer\Model\ResourceModel\Avatr as ResourceAvatr;
|
||||
use Stemcell\Customer\Model\ResourceModel\Avatr\CollectionFactory as AvatrCollectionFactory;
|
||||
|
||||
class AvatrRepository implements AvatrRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var CollectionProcessorInterface
|
||||
*/
|
||||
protected $collectionProcessor;
|
||||
|
||||
/**
|
||||
* @var AvatrInterfaceFactory
|
||||
*/
|
||||
protected $avatrFactory;
|
||||
|
||||
/**
|
||||
* @var ResourceAvatr
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var AvatrCollectionFactory
|
||||
*/
|
||||
protected $avatrCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var Avatr
|
||||
*/
|
||||
protected $searchResultsFactory;
|
||||
|
||||
|
||||
/**
|
||||
* @param ResourceAvatr $resource
|
||||
* @param AvatrInterfaceFactory $avatrFactory
|
||||
* @param AvatrCollectionFactory $avatrCollectionFactory
|
||||
* @param AvatrSearchResultsInterfaceFactory $searchResultsFactory
|
||||
* @param CollectionProcessorInterface $collectionProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
ResourceAvatr $resource,
|
||||
AvatrInterfaceFactory $avatrFactory,
|
||||
AvatrCollectionFactory $avatrCollectionFactory,
|
||||
AvatrSearchResultsInterfaceFactory $searchResultsFactory,
|
||||
CollectionProcessorInterface $collectionProcessor
|
||||
) {
|
||||
$this->resource = $resource;
|
||||
$this->avatrFactory = $avatrFactory;
|
||||
$this->avatrCollectionFactory = $avatrCollectionFactory;
|
||||
$this->searchResultsFactory = $searchResultsFactory;
|
||||
$this->collectionProcessor = $collectionProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function save(AvatrInterface $avatr)
|
||||
{
|
||||
try {
|
||||
$this->resource->save($avatr);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotSaveException(__(
|
||||
'Could not save the avatr: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return $avatr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get($avatrId)
|
||||
{
|
||||
$avatr = $this->avatrFactory->create();
|
||||
$this->resource->load($avatr, $avatrId);
|
||||
if (!$avatr->getId()) {
|
||||
throw new NoSuchEntityException(__('Avatr with id "%1" does not exist.', $avatrId));
|
||||
}
|
||||
return $avatr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getList(
|
||||
\Magento\Framework\Api\SearchCriteriaInterface $criteria
|
||||
) {
|
||||
$collection = $this->avatrCollectionFactory->create();
|
||||
|
||||
$this->collectionProcessor->process($criteria, $collection);
|
||||
|
||||
$searchResults = $this->searchResultsFactory->create();
|
||||
$searchResults->setSearchCriteria($criteria);
|
||||
|
||||
$items = [];
|
||||
foreach ($collection as $model) {
|
||||
$items[] = $model;
|
||||
}
|
||||
|
||||
$searchResults->setItems($items);
|
||||
$searchResults->setTotalCount($collection->getSize());
|
||||
return $searchResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(AvatrInterface $avatr)
|
||||
{
|
||||
try {
|
||||
$avatrModel = $this->avatrFactory->create();
|
||||
$this->resource->load($avatrModel, $avatr->getAvatrId());
|
||||
$this->resource->delete($avatrModel);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotDeleteException(__(
|
||||
'Could not delete the Avatr: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function deleteById($avatrId)
|
||||
{
|
||||
return $this->delete($this->get($avatrId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $telephone
|
||||
* @param string $model
|
||||
* @return AvatrInterface
|
||||
*/
|
||||
public function getByTelephone(string $telephone, string $model): AvatrInterface
|
||||
{
|
||||
$collection = $this->avatrCollectionFactory->create();
|
||||
$collection->addFieldToFilter('telephone', $telephone)
|
||||
->addFieldToFilter('favorite_vehicle', $model)
|
||||
->setItemObjectClass(Avatr::class);
|
||||
return $collection->getFirstItem();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Model;
|
||||
|
||||
class Customer
|
||||
{
|
||||
const EMAIL_DOMAIN = '@placeholder.com';
|
||||
const MOBILE_PATTERN = '/^(?:\+?86)?1(?:3\d{3}|5[^4\D]\d{2}|8\d{3}|7(?:[0-35-9]\d{2}|4(?:0\d|1[0-2]|9\d))|9[0-35-9]\d{2}|6[2567]\d{2}|4(?:(?:10|4[01])\d{3}|[68]\d{4}|[579]\d{2}))\d{6}$/';
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Model\Data;
|
||||
|
||||
use Stemcell\Customer\Api\Data\Http;
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\Serialize\Serializer\Json;
|
||||
use Magento\Setup\Module\I18n\Dictionary\Phrase;
|
||||
|
||||
class JsonResponse extends DataObject implements Http\JsonResponse
|
||||
{
|
||||
protected bool $errors = false;
|
||||
|
||||
protected array $message = [];
|
||||
|
||||
protected Json $jsonSerializer;
|
||||
|
||||
public function __construct(
|
||||
Json $jsonSerializer,
|
||||
array $data = []
|
||||
) {
|
||||
$this->jsonSerializer = $jsonSerializer;
|
||||
parent::__construct($data);
|
||||
}
|
||||
|
||||
public function setErrors(bool $status = false): self
|
||||
{
|
||||
$this->errors = $status;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setMessages(array $message): self
|
||||
{
|
||||
$this->message = array_merge($this->message, $message);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setData($key, $value = null): self
|
||||
{
|
||||
if (is_array($key)) {
|
||||
$this->_data = array_merge($this->_data, $key);
|
||||
} else {
|
||||
parent::setData($key, $value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function toArray(array $keys = []): array
|
||||
{
|
||||
return [
|
||||
'error' => $this->errors,
|
||||
'message' =>array_values($this->message),
|
||||
'data' => $this->_data
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function getErrors(): bool
|
||||
{
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
public function getMessages(): array
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Model;
|
||||
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
use Stemcell\Customer\Api\Data\LabInterface;
|
||||
|
||||
class Lab extends AbstractModel implements LabInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function _construct()
|
||||
{
|
||||
$this->_init(\Stemcell\Customer\Model\ResourceModel\Lab::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLabCode()
|
||||
{
|
||||
return $this->getData(self::LAB_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setLabCode($labCode)
|
||||
{
|
||||
return $this->setData(self::LAB_CODE, $labCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getBookingAccount()
|
||||
{
|
||||
return $this->getData(self::BOOKING_ACCOUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setBookingAccount($bookingAccount)
|
||||
{
|
||||
return $this->setData(self::BOOKING_ACCOUNT, $bookingAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getPiSapId()
|
||||
{
|
||||
return $this->getData(self::PI_SAP_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setPiSapId($piSapId)
|
||||
{
|
||||
return $this->setData(self::PI_SAP_ID, $piSapId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getVendorName()
|
||||
{
|
||||
return $this->getData(self::VENDOR_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setVendorName($vendorName)
|
||||
{
|
||||
return $this->setData(self::VENDOR_NAME, $vendorName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIsActive()
|
||||
{
|
||||
return $this->getData(self::IS_ACTIVE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setIsActive($isActive)
|
||||
{
|
||||
return $this->setData(self::IS_ACTIVE, $isActive);
|
||||
}
|
||||
|
||||
public function getLabId()
|
||||
{
|
||||
return $this->getData(self::LAB_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setLabId(int $labId)
|
||||
{
|
||||
return $this->setData(self::LAB_ID, $labId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $salespersonId
|
||||
* @return LabInterface
|
||||
*/
|
||||
public function setSalespersonId(int $salespersonId): LabInterface
|
||||
{
|
||||
return $this->setData(self::SALESPERSON_ID, $salespersonId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getSalespersonId()
|
||||
{
|
||||
return $this->getData(self::SALESPERSON_ID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Model\Lab;
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Ui\Component\MassAction\Filter;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use Stemcell\Customer\Model\ResourceModel\Lab\CollectionFactory as LabCollectionFactory;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Stemcell\Customer\Model\ResourceModel\Salesperson\CollectionFactory as SalespersonCollectionFactory;
|
||||
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
|
||||
use Stemcell\Customer\Model\Salesperson;
|
||||
use Magento\Customer\Model\ResourceModel\Group\CollectionFactory as GroupCollectionFactory;
|
||||
|
||||
class Export
|
||||
{
|
||||
protected Filesystem\Directory\WriteInterface $directory;
|
||||
|
||||
protected array $salesperson = [];
|
||||
|
||||
protected array $dealers = [];
|
||||
|
||||
const VENDOR_CUSTOMER_GROUP_CODE = [
|
||||
'STEMCELL CN 经销商组',
|
||||
'库存查询组',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
protected Filter $filter,
|
||||
protected LabCollectionFactory $labCollectionFactory,
|
||||
protected Filesystem $filesystem,
|
||||
protected Filesystem\DirectoryList $directoryList,
|
||||
protected SalespersonCollectionFactory $salespersonCollectionFactory,
|
||||
protected CustomerCollectionFactory $customerCollectionFactory,
|
||||
protected GroupCollectionFactory $groupCollectionFactory,
|
||||
) {
|
||||
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
|
||||
}
|
||||
|
||||
protected function getSalesperson()
|
||||
{
|
||||
if (!empty($this->salesperson)) {
|
||||
return $this->salesperson;
|
||||
}
|
||||
|
||||
$collection = $this->salespersonCollectionFactory->create()->addFieldToSelect('*');
|
||||
foreach ($collection as $salesperson) {
|
||||
/* @var $salesperson Salesperson */
|
||||
$this->salesperson[$salesperson->getId()] = $salesperson->getName();
|
||||
}
|
||||
return $this->salesperson;
|
||||
}
|
||||
|
||||
protected function getDealers()
|
||||
{
|
||||
if (!empty($this->dealers)) {
|
||||
return $this->dealers;
|
||||
}
|
||||
$groups = $this->groupCollectionFactory->create()
|
||||
->addFieldToFilter('customer_group_code', ['in' => self::VENDOR_CUSTOMER_GROUP_CODE]);
|
||||
|
||||
$collection = $this->customerCollectionFactory->create()->addAttributeToSelect('firstname')
|
||||
->addAttributeToFilter('group_id', ['in' => $groups->getColumnValues('customer_group_id')]);
|
||||
foreach ($collection as $customer) {
|
||||
$this->dealers[$customer->getEntityId()] = $customer->getFirstname();
|
||||
}
|
||||
|
||||
return $this->dealers;
|
||||
}
|
||||
|
||||
public function getExcelFile()
|
||||
{
|
||||
$this->directory->create('export');
|
||||
$file = 'export/Labs-'.date("YmdH:i:s") . '.xlsx';
|
||||
$filePath = $this->directoryList->getPath('var').'/'.$file;
|
||||
|
||||
$this->getSalesperson();
|
||||
$this->getDealers();
|
||||
|
||||
$spreadSheet = new Spreadsheet();
|
||||
$writer = IOFactory::createWriter($spreadSheet, 'Xlsx');
|
||||
$worksheet = $spreadSheet->getActiveSheet();
|
||||
$styles = [
|
||||
'alignment' => [
|
||||
'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
|
||||
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
|
||||
],
|
||||
];
|
||||
$columnIndex = 'A';
|
||||
$headers = $this->getHeaders();
|
||||
foreach ($headers as $row) {
|
||||
$cell = $worksheet->getCell($columnIndex.'1');
|
||||
$cell->getAppliedStyle()->applyFromArray($styles);
|
||||
$cell->setValue($row);
|
||||
$columnIndex++;
|
||||
}
|
||||
|
||||
$rowIndex = 2;
|
||||
$result = $this->getFilterResult();
|
||||
foreach ($result as $row) {
|
||||
/* @var $row \Stemcell\Customer\Model\Lab */
|
||||
$columnIndex = 'A';
|
||||
$worksheet->getColumnDimension($columnIndex)->setWidth(15);
|
||||
$worksheet->getRowDimension($rowIndex)->setRowHeight(20);
|
||||
foreach (array_keys($headers) as $field) {
|
||||
$value = '';
|
||||
if (in_array($field, ['customer_id', 'salesperson_id'])) {
|
||||
if ($row->getData($field)) {
|
||||
if ($field == 'customer_id') {
|
||||
$value = isset($this->dealers[$row->getData($field)])? $this->dealers[$row->getData($field)] : '';
|
||||
} else {
|
||||
$value = isset($this->salesperson[$row->getData($field)])? $this->salesperson[$row->getData($field)] : '';
|
||||
}
|
||||
}
|
||||
} elseif ($field == 'is_active') {
|
||||
$value = $row->getData($field) == 1? '是':'否';
|
||||
} else {
|
||||
$value = $row->getData($field);
|
||||
}
|
||||
$cell = $worksheet->getCell($columnIndex.$rowIndex);
|
||||
|
||||
$cell->setValue($value);
|
||||
$columnIndex++;
|
||||
}
|
||||
$rowIndex++;
|
||||
}
|
||||
|
||||
$writer->save($filePath);
|
||||
return [
|
||||
'type' => 'filename',
|
||||
'value' => $file,
|
||||
'rm' => true // can delete file after use
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Stemcell\Customer\Model\Lab[]
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
protected function getFilterResult()
|
||||
{
|
||||
/* @var $component \Magento\Ui\Component\Listing */
|
||||
$component = $this->filter->getComponent();
|
||||
|
||||
// md5() here is not for cryptographic use.
|
||||
// phpcs:ignore Magento2.Security.InsecureFunction
|
||||
$name = md5(microtime());
|
||||
$file = 'export/'. $component->getName() . '-'.date("YmdH:i:s") . '.xlsx';
|
||||
|
||||
$this->filter->prepareComponent($component);
|
||||
$this->filter->applySelectionOnTargetProvider();
|
||||
|
||||
/* @var $dataProvider \Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider */
|
||||
$dataProvider = $component->getContext()->getDataProvider();
|
||||
|
||||
// $this->directory->create('export');
|
||||
// $filePath = $this->directoryList->getPath('var').'/'.$file;
|
||||
$dataProvider->setLimit(0, 100000);
|
||||
|
||||
$items = $dataProvider->getSearchResult()->getItems();
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
protected function getHeaders()
|
||||
{
|
||||
return [
|
||||
'lab_code' => 'Lab ID',
|
||||
'booking_account' => 'Booking Account',
|
||||
'pi_sap_id' => 'PI SAP ID',
|
||||
'customer_id' => 'Dealer Name',
|
||||
'salesperson_id' => 'Sales Person',
|
||||
'is_active' => 'Is Active',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Model;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\Exception\CouldNotDeleteException;
|
||||
use Magento\Framework\Exception\CouldNotSaveException;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Stemcell\Customer\Api\Data\LabInterface;
|
||||
use Stemcell\Customer\Api\Data\LabInterfaceFactory;
|
||||
use Stemcell\Customer\Api\Data\LabSearchResultsInterfaceFactory;
|
||||
use Stemcell\Customer\Api\LabRepositoryInterface;
|
||||
use Stemcell\Customer\Model\ResourceModel\Lab as ResourceLab;
|
||||
use Stemcell\Customer\Model\ResourceModel\Lab\CollectionFactory as LabCollectionFactory;
|
||||
|
||||
class LabRepository implements LabRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ResourceLab
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var LabInterfaceFactory
|
||||
*/
|
||||
protected $labFactory;
|
||||
|
||||
/**
|
||||
* @var LabCollectionFactory
|
||||
*/
|
||||
protected $labCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var Lab
|
||||
*/
|
||||
protected $searchResultsFactory;
|
||||
|
||||
/**
|
||||
* @var CollectionProcessorInterface
|
||||
*/
|
||||
protected $collectionProcessor;
|
||||
protected \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* @param ResourceLab $resource
|
||||
* @param LabInterfaceFactory $labFactory
|
||||
* @param LabCollectionFactory $labCollectionFactory
|
||||
* @param LabSearchResultsInterfaceFactory $searchResultsFactory
|
||||
* @param CollectionProcessorInterface $collectionProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
ResourceLab $resource,
|
||||
LabInterfaceFactory $labFactory,
|
||||
LabCollectionFactory $labCollectionFactory,
|
||||
LabSearchResultsInterfaceFactory $searchResultsFactory,
|
||||
CollectionProcessorInterface $collectionProcessor,
|
||||
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
|
||||
) {
|
||||
$this->resource = $resource;
|
||||
$this->labFactory = $labFactory;
|
||||
$this->labCollectionFactory = $labCollectionFactory;
|
||||
$this->searchResultsFactory = $searchResultsFactory;
|
||||
$this->collectionProcessor = $collectionProcessor;
|
||||
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function save(LabInterface $lab)
|
||||
{
|
||||
try {
|
||||
$this->resource->save($lab);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotSaveException(__(
|
||||
'Could not save the lab: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return $lab;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get($labId)
|
||||
{
|
||||
$lab = $this->labFactory->create();
|
||||
$this->resource->load($lab, $labId);
|
||||
if (!$lab->getId()) {
|
||||
throw new NoSuchEntityException(__('Lab with id "%1" does not exist.', $labId));
|
||||
}
|
||||
return $lab;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getList(
|
||||
\Magento\Framework\Api\SearchCriteriaInterface $criteria
|
||||
) {
|
||||
$collection = $this->labCollectionFactory->create();
|
||||
|
||||
$this->collectionProcessor->process($criteria, $collection);
|
||||
|
||||
$searchResults = $this->searchResultsFactory->create();
|
||||
$searchResults->setSearchCriteria($criteria);
|
||||
|
||||
$items = [];
|
||||
foreach ($collection as $model) {
|
||||
$items[] = $model;
|
||||
}
|
||||
|
||||
$searchResults->setItems($items);
|
||||
$searchResults->setTotalCount($collection->getSize());
|
||||
return $searchResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(LabInterface $lab)
|
||||
{
|
||||
try {
|
||||
$labModel = $this->labFactory->create();
|
||||
$this->resource->load($labModel, $lab->getId());
|
||||
$this->resource->delete($labModel);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotDeleteException(__(
|
||||
'Could not delete the Lab: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function deleteById($labId)
|
||||
{
|
||||
return $this->delete($this->get($labId));
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheirtDoc
|
||||
*/
|
||||
public function getByDealerId(int $customerId): ResourceLab\Collection
|
||||
{
|
||||
$collection = $this->labCollectionFactory->create();
|
||||
$collection->addFieldToFilter('main_table.customer_id', $customerId)
|
||||
->getSelect()
|
||||
->joinLeft('customer_entity', 'customer_entity.entity_id=main_table.customer_id', ['customer_name'=>'firstname'])
|
||||
->joinLeft('salesperson', 'salesperson.salesperson_id=main_table.salesperson_id', ['salesperson_name'=>'salesperson.name'])
|
||||
->query();
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getByLabCode($labCode)
|
||||
{
|
||||
$lab = $this->labFactory->create();
|
||||
$this->resource->load($lab, $labCode, 'lab_code');
|
||||
if (!$lab->getId()) {
|
||||
throw new NoSuchEntityException(__('Lab with id "%1" does not exist.', $labCode));
|
||||
}
|
||||
return $lab;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Model\ResourceModel;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
|
||||
class Avatr extends AbstractDb
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('avatr', 'entity_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Model\ResourceModel\Avatr;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
|
||||
|
||||
class Collection extends AbstractCollection
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected $_idFieldName = 'entity_id';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(
|
||||
\Stemcell\Customer\Model\Avatr::class,
|
||||
\Stemcell\Customer\Model\ResourceModel\Avatr::class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Model\ResourceModel;
|
||||
|
||||
use Magento\Customer\Api\CustomerMetadataInterface;
|
||||
use Magento\Customer\Api\Data\CustomerInterface;
|
||||
use Magento\Customer\Api\Data\CustomerSearchResultsInterfaceFactory;
|
||||
use Magento\Customer\Api\GroupRepositoryInterface;
|
||||
use Magento\Customer\Model\Customer\NotificationStorage;
|
||||
use Magento\Customer\Model\CustomerFactory;
|
||||
use Magento\Customer\Model\CustomerRegistry;
|
||||
use Magento\Customer\Model\Data\CustomerSecureFactory;
|
||||
use Magento\Customer\Model\Delegation\Storage as DelegatedStorage;
|
||||
use Magento\Customer\Model\ResourceModel;
|
||||
use Magento\Customer\Model\ResourceModel\AddressRepository;
|
||||
use Magento\Customer\Model\ResourceModel\Customer;
|
||||
use Magento\Framework\Api\DataObjectHelper;
|
||||
use Magento\Framework\Api\ExtensibleDataObjectConverter;
|
||||
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
|
||||
use Magento\Framework\Api\ImageProcessorInterface;
|
||||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\Event\ManagerInterface;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class CustomerRepository extends ResourceModel\CustomerRepository
|
||||
{
|
||||
const MOBILE_PATTERN = '/^(1(([3456789][0-9])|(47)|[8][01236789]))\d{8}$/';
|
||||
|
||||
protected CollectionFactory $customerCollectionFactory;
|
||||
|
||||
public function __construct(
|
||||
CustomerFactory $customerFactory,
|
||||
CustomerSecureFactory $customerSecureFactory,
|
||||
CustomerRegistry $customerRegistry,
|
||||
AddressRepository $addressRepository,
|
||||
Customer $customerResourceModel,
|
||||
CustomerMetadataInterface $customerMetadata,
|
||||
CustomerSearchResultsInterfaceFactory $searchResultsFactory,
|
||||
ManagerInterface $eventManager,
|
||||
StoreManagerInterface $storeManager,
|
||||
ExtensibleDataObjectConverter $extensibleDataObjectConverter,
|
||||
DataObjectHelper $dataObjectHelper,
|
||||
ImageProcessorInterface $imageProcessor,
|
||||
JoinProcessorInterface $extensionAttributesJoinProcessor,
|
||||
CollectionProcessorInterface $collectionProcessor,
|
||||
NotificationStorage $notificationStorage,
|
||||
CollectionFactory $customerCollectionFactory,
|
||||
DelegatedStorage $delegatedStorage = null,
|
||||
?GroupRepositoryInterface $groupRepository = null
|
||||
) {
|
||||
$this->customerCollectionFactory = $customerCollectionFactory;
|
||||
parent::__construct($customerFactory, $customerSecureFactory, $customerRegistry, $addressRepository, $customerResourceModel, $customerMetadata, $searchResultsFactory, $eventManager, $storeManager, $extensibleDataObjectConverter, $dataObjectHelper, $imageProcessor, $extensionAttributesJoinProcessor, $collectionProcessor, $notificationStorage, $delegatedStorage, $groupRepository);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $mobile
|
||||
* @param null $websiteId
|
||||
* @return \Magento\Customer\Model\Customer
|
||||
* @throws NoSuchEntityException
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
protected function getCustomerByMobile(String $mobile, $websiteId = null) {
|
||||
$websiteId = $websiteId?: $this->storeManager->getDefaultStoreView()->getWebsiteId();
|
||||
/* @var $customer \Magento\Customer\Model\Customer */
|
||||
$customer = $this->customerCollectionFactory->create()
|
||||
->addAttributeToSelect('*')
|
||||
->addAttributeToFilter('mobile', $mobile)
|
||||
->addAttributeToFilter(CustomerInterface::WEBSITE_ID, $websiteId)
|
||||
->getFirstItem();
|
||||
if (!$customer->getId()) {
|
||||
throw new NoSuchEntityException(
|
||||
__(
|
||||
'No such entity with %fieldName = %fieldValue, %field2Name = %field2Value',
|
||||
[
|
||||
'fieldName' => 'mobile',
|
||||
'fieldValue' => $mobile,
|
||||
'field2Name' => 'websiteId',
|
||||
'field2Value' => $websiteId
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @param null $websiteId
|
||||
* @return \Magento\Customer\Api\Data\CustomerInterface
|
||||
* @throws NoSuchEntityException
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function get($email, $websiteId = null)
|
||||
{
|
||||
if (preg_match(self::MOBILE_PATTERN, $email)) {
|
||||
return $this->getCustomerByMobile($email, $websiteId)->getDataModel();
|
||||
}
|
||||
return parent::get($email, $websiteId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Model\ResourceModel;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
|
||||
class Lab extends AbstractDb
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('lab', 'lab_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Model\ResourceModel\Lab;
|
||||
|
||||
use Magento\Framework\DataObject;
|
||||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
|
||||
|
||||
class Collection extends AbstractCollection
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected $_idFieldName = 'lab_id';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(
|
||||
\Stemcell\Customer\Model\Lab::class,
|
||||
\Stemcell\Customer\Model\ResourceModel\Lab::class
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Model\ResourceModel;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
|
||||
class Salesperson extends AbstractDb
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('salesperson', 'salesperson_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Model\ResourceModel\Salesperson;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
|
||||
|
||||
class Collection extends AbstractCollection
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected $_idFieldName = 'salesperson_id';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(
|
||||
\Stemcell\Customer\Model\Salesperson::class,
|
||||
\Stemcell\Customer\Model\ResourceModel\Salesperson::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $valueField
|
||||
* @param $labelField
|
||||
* @param $additional
|
||||
* @return array
|
||||
*/
|
||||
protected function _toOptionArray($valueField = 'salesperson_id', $labelField = 'name', $additional = [])
|
||||
{
|
||||
return parent::_toOptionArray($valueField, $labelField, $additional);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Model;
|
||||
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
use Stemcell\Customer\Api\Data\SalespersonInterface;
|
||||
|
||||
class Salesperson extends AbstractModel implements SalespersonInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function _construct()
|
||||
{
|
||||
$this->_init(\Stemcell\Customer\Model\ResourceModel\Salesperson::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->getData(self::NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
return $this->setData(self::NAME, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->getData(self::EMAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setEmail($email)
|
||||
{
|
||||
return $this->setData(self::EMAIL, $email);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTelephone()
|
||||
{
|
||||
return $this->getData(self::TELEPHONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setTelephone($telephone)
|
||||
{
|
||||
return $this->setData(self::TELEPHONE, $telephone);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getRsmEmail()
|
||||
{
|
||||
return $this->getData(self::RSM_EMAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setRsmEmail($rsmEmail)
|
||||
{
|
||||
return $this->setData(self::RSM_EMAIL, $rsmEmail);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSisrEmail()
|
||||
{
|
||||
return $this->getData(self::SISR_EMAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setSisrEmail($sisrEmail)
|
||||
{
|
||||
return $this->setData(self::SISR_EMAIL, $sisrEmail);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCsrEmail()
|
||||
{
|
||||
return $this->getData(self::CSR_EMAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCsrEmail($csrEmail)
|
||||
{
|
||||
return $this->setData(self::CSR_EMAIL, $csrEmail);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getIsActive()
|
||||
{
|
||||
return $this->getData(self::IS_ACTIVE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setIsActive($isActive)
|
||||
{
|
||||
return $this->setData(self::IS_ACTIVE, $isActive);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSalespersonId()
|
||||
{
|
||||
return $this->getData(self::SALESPERSON_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setSalespersonId($salespersonId)
|
||||
{
|
||||
return $this->setData(self::SALESPERSON_ID, $salespersonId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Model;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
|
||||
use Magento\Framework\Exception\CouldNotDeleteException;
|
||||
use Magento\Framework\Exception\CouldNotSaveException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Stemcell\Customer\Api\Data\SalespersonInterface;
|
||||
use Stemcell\Customer\Api\Data\SalespersonInterfaceFactory;
|
||||
use Stemcell\Customer\Api\Data\SalespersonSearchResultsInterfaceFactory;
|
||||
use Stemcell\Customer\Api\SalespersonRepositoryInterface;
|
||||
use Stemcell\Customer\Model\ResourceModel\Salesperson as ResourceSalesperson;
|
||||
use Stemcell\Customer\Model\ResourceModel\Salesperson\CollectionFactory as SalespersonCollectionFactory;
|
||||
|
||||
class SalespersonRepository implements SalespersonRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ResourceSalesperson
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var SalespersonInterfaceFactory
|
||||
*/
|
||||
protected $salespersonFactory;
|
||||
|
||||
/**
|
||||
* @var SalespersonCollectionFactory
|
||||
*/
|
||||
protected $salespersonCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var Salesperson
|
||||
*/
|
||||
protected $searchResultsFactory;
|
||||
|
||||
/**
|
||||
* @var CollectionProcessorInterface
|
||||
*/
|
||||
protected $collectionProcessor;
|
||||
|
||||
|
||||
/**
|
||||
* @param ResourceSalesperson $resource
|
||||
* @param SalespersonInterfaceFactory $salespersonFactory
|
||||
* @param SalespersonCollectionFactory $salespersonCollectionFactory
|
||||
* @param SalespersonSearchResultsInterfaceFactory $searchResultsFactory
|
||||
* @param CollectionProcessorInterface $collectionProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
ResourceSalesperson $resource,
|
||||
SalespersonInterfaceFactory $salespersonFactory,
|
||||
SalespersonCollectionFactory $salespersonCollectionFactory,
|
||||
SalespersonSearchResultsInterfaceFactory $searchResultsFactory,
|
||||
CollectionProcessorInterface $collectionProcessor
|
||||
) {
|
||||
$this->resource = $resource;
|
||||
$this->salespersonFactory = $salespersonFactory;
|
||||
$this->salespersonCollectionFactory = $salespersonCollectionFactory;
|
||||
$this->searchResultsFactory = $searchResultsFactory;
|
||||
$this->collectionProcessor = $collectionProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function save(SalespersonInterface $salesperson)
|
||||
{
|
||||
try {
|
||||
$this->resource->save($salesperson);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotSaveException(__(
|
||||
'Could not save the salesperson: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return $salesperson;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get($salespersonId)
|
||||
{
|
||||
$salesperson = $this->salespersonFactory->create();
|
||||
$this->resource->load($salesperson, $salespersonId);
|
||||
if (!$salesperson->getId()) {
|
||||
//throw new NoSuchEntityException(__('Salesperson with id "%1" does not exist.', $salespersonId));
|
||||
}
|
||||
return $salesperson;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getList(
|
||||
\Magento\Framework\Api\SearchCriteriaInterface $criteria
|
||||
) {
|
||||
$collection = $this->salespersonCollectionFactory->create();
|
||||
|
||||
$this->collectionProcessor->process($criteria, $collection);
|
||||
|
||||
$searchResults = $this->searchResultsFactory->create();
|
||||
$searchResults->setSearchCriteria($criteria);
|
||||
|
||||
$items = [];
|
||||
foreach ($collection as $model) {
|
||||
$items[] = $model;
|
||||
}
|
||||
|
||||
$searchResults->setItems($items);
|
||||
$searchResults->setTotalCount($collection->getSize());
|
||||
return $searchResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(SalespersonInterface $salesperson)
|
||||
{
|
||||
try {
|
||||
$salespersonModel = $this->salespersonFactory->create();
|
||||
$this->resource->load($salespersonModel, $salesperson->getId());
|
||||
$this->resource->delete($salespersonModel);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotDeleteException(__(
|
||||
'Could not delete the Salesperson: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function deleteById($salespersonId)
|
||||
{
|
||||
return $this->delete($this->get($salespersonId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Model\Validator;
|
||||
|
||||
use Magento\Customer\Model\Customer;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Name extends \Magento\Customer\Model\Validator\Name
|
||||
{
|
||||
protected const PATTERN_NAME = '/^(?:[\p{L}\p{M}\p{P}\s\d]){1,255}+$/u';
|
||||
|
||||
/**
|
||||
* Validate name fields.
|
||||
*
|
||||
* @param Customer $customer
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid($customer)
|
||||
{
|
||||
if (!$this->isValidName($customer->getFirstname())) {
|
||||
parent::_addMessages([['firstname' => 'First Name is not valid!']]);
|
||||
}
|
||||
|
||||
if (!$this->isValidName($customer->getLastname())) {
|
||||
parent::_addMessages([['lastname' => 'Last Name is not valid!']]);
|
||||
}
|
||||
|
||||
if (!$this->isValidName($customer->getMiddlename())) {
|
||||
parent::_addMessages([['middlename' => 'Middle Name is not valid!']]);
|
||||
}
|
||||
|
||||
return count($this->_messages) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if name field is valid.
|
||||
*
|
||||
* @param string|null $nameValue
|
||||
* @return bool
|
||||
*/
|
||||
protected function isValidName($nameValue)
|
||||
{
|
||||
if ($nameValue != null) {
|
||||
if (preg_match(self::PATTERN_NAME, $nameValue, $matches)) {
|
||||
return $matches[0] == $nameValue;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Observer;
|
||||
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
use Magento\Captcha\Observer\CaptchaStringResolver;
|
||||
|
||||
use \Magento\Captcha\Helper\Data;
|
||||
|
||||
class CheckRegisterSmsObserver implements ObserverInterface
|
||||
{
|
||||
const FORMID = 'user_create_sms_sender';
|
||||
const FORMID_FORGOTPASSWORD = 'user_forgot_password_sms_sender';
|
||||
|
||||
protected CaptchaStringResolver $captchaStringResolver;
|
||||
|
||||
protected Data $helper;
|
||||
|
||||
public function __construct(
|
||||
CaptchaStringResolver $captchaStringResolver,
|
||||
Data $helper
|
||||
) {
|
||||
$this->captchaStringResolver = $captchaStringResolver;
|
||||
$this->helper = $helper;
|
||||
}
|
||||
|
||||
protected function getType(RequestInterface $request) {
|
||||
$type = $request->getParam('form_id');
|
||||
return $type?:CheckRegisterSmsObserver::FORMID;
|
||||
}
|
||||
|
||||
public function execute(Observer $observer)
|
||||
{
|
||||
/** @var RequestInterface $request */
|
||||
$request = $observer->getRequest();
|
||||
$formId = $this->getType($request);
|
||||
$captcha = $this->helper->getCaptcha($formId);
|
||||
if ($captcha->isRequired()) {
|
||||
if (!$captcha->isCorrect($this->captchaStringResolver->resolve($request, $formId))) {
|
||||
$request->setParams(['captcha_fail' => true]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Observer\Customer\Register;
|
||||
|
||||
use Magento\Framework\App\ResponseFactory;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\UrlInterface;
|
||||
use Stemcell\Customer\Model\Customer;
|
||||
use Stemcell\Customer\Observer\CheckRegisterSmsObserver;
|
||||
use Stemcell\Sms\Model\AliyunSmsSenderFactory;
|
||||
use Magento\Framework\App\ActionFlag;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\App\Response\RedirectInterface;
|
||||
use Magento\Framework\App\ResponseInterface;
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
use \Magento\Framework\Message;
|
||||
use Magento\Framework\App\Request\DataPersistorInterface;
|
||||
|
||||
class SmsValidation implements ObserverInterface
|
||||
{
|
||||
protected Message\ManagerInterface $messageManager;
|
||||
|
||||
protected AliyunSmsSenderFactory $aliyunSmsSenderFactory;
|
||||
|
||||
protected ActionFlag $actionFlag;
|
||||
protected RedirectInterface $redirect;
|
||||
protected DataPersistorInterface $dataPersistor;
|
||||
protected ResponseInterface $response;
|
||||
protected ResponseFactory $responseFactory;
|
||||
protected UrlInterface $urlBuilder;
|
||||
|
||||
public function __construct(
|
||||
Message\ManagerInterface $messageManager,
|
||||
AliyunSmsSenderFactory $aliyunSmsSenderFactory,
|
||||
ActionFlag $actionFlag,
|
||||
RedirectInterface $redirect,
|
||||
DataPersistorInterface $dataPersistor,
|
||||
ResponseInterface $response,
|
||||
ResponseFactory $responseFactory,
|
||||
UrlInterface $urlBuilder
|
||||
) {
|
||||
$this->messageManager = $messageManager;
|
||||
$this->aliyunSmsSenderFactory = $aliyunSmsSenderFactory;
|
||||
$this->actionFlag = $actionFlag;
|
||||
$this->redirect = $redirect;
|
||||
$this->dataPersistor = $dataPersistor;
|
||||
$this->response = $response;
|
||||
$this->urlBuilder = $urlBuilder;
|
||||
$this->responseFactory = $responseFactory;
|
||||
}
|
||||
|
||||
protected function getType(RequestInterface $request) {
|
||||
$type = $request->getParam('form_id');
|
||||
return $type?:CheckRegisterSmsObserver::FORMID;
|
||||
}
|
||||
|
||||
public function execute(Observer $observer)
|
||||
{
|
||||
/** @var RequestInterface $request */
|
||||
$request = $observer->getRequest();
|
||||
|
||||
$formId = $this->getType($request);
|
||||
try {
|
||||
// $aliyunSmsSender = $this->aliyunSmsSenderFactory->create([
|
||||
// 'data' => [
|
||||
// 'type' => $formId,
|
||||
// 'mobile' => $request->getParam('mobile'),
|
||||
// ]
|
||||
// ]);
|
||||
// $result = $aliyunSmsSender->validate($request->getParam('validate-code'));
|
||||
// if (!$result) {
|
||||
// $this->messageManager->addErrorMessage(__('Incorrect validation code.'));
|
||||
// }
|
||||
} catch (\Exception $e) {
|
||||
$result = false;
|
||||
$this->messageManager->addErrorMessage(__($e->getMessage()));
|
||||
}
|
||||
|
||||
// if (!$result) {
|
||||
// $this->dataPersistor->set($formId, $request->getPostValue());
|
||||
// $customerBeforeAuthUrl = $this->urlBuilder->getUrl('customer/account/create');
|
||||
// $this->responseFactory->create()->setRedirect($customerBeforeAuthUrl)->sendResponse();
|
||||
// return $this;
|
||||
// }
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Stemcell\Customer\Observer\Quote\Address;
|
||||
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
use Magento\Quote\Model\Quote\Address;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Magento\Framework\DataObject\Copy\Config;
|
||||
|
||||
class AttachExtensionAttributeObserver implements ObserverInterface
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
protected Config $fieldsetConfig;
|
||||
|
||||
public function __construct(
|
||||
Config $config
|
||||
) {
|
||||
$this->fieldsetConfig = $config;
|
||||
}
|
||||
|
||||
public function execute(Observer $observer)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Observer;
|
||||
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Stemcell\Customer\Model\ResourceModel\Salesperson;
|
||||
|
||||
class SalespersonsCustomerSave implements ObserverInterface
|
||||
{
|
||||
public function __construct(
|
||||
protected Salesperson $salespersonResourceModel,
|
||||
){
|
||||
}
|
||||
|
||||
public function execute(Observer $observer)
|
||||
{
|
||||
/* @var $request \Magento\Framework\App\RequestInterface */
|
||||
$request = $observer->getData('request');
|
||||
/* @var $request \Magento\Customer\Api\Data\CustomerInterface */
|
||||
$customer = $observer->getData('customer');
|
||||
$salesperson = $request->getParam('customer');
|
||||
|
||||
$connection = $this->salespersonResourceModel->getConnection();
|
||||
if (isset($salesperson['salespersons']) && is_array($salesperson['salespersons'])) {
|
||||
$data = [];
|
||||
foreach ($salesperson['salespersons'] as $item) {
|
||||
$data[] = ['customer_id' => $customer->getId(), 'salesperson_id' => $item];
|
||||
}
|
||||
$connection->beginTransaction();
|
||||
$connection->delete('customer_salesperson', 'customer_id = '. $customer->getId());
|
||||
$connection->insertMultiple('customer_salesperson', $data);
|
||||
$connection->commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Observer;
|
||||
|
||||
use Magento\Customer\Api\Data\CustomerInterface;
|
||||
use Magento\Framework\App\RequestInterface;
|
||||
use Magento\Framework\Event\Observer;
|
||||
use Magento\Framework\Event\ObserverInterface;
|
||||
|
||||
class SalespersonsIdSave implements ObserverInterface
|
||||
{
|
||||
|
||||
public function execute(Observer $observer)
|
||||
{
|
||||
/* @var $customer CustomerInterface */
|
||||
$customer = $observer->getData('customer');
|
||||
/* @var $customer RequestInterface */
|
||||
$request = $observer->getData('request');
|
||||
|
||||
$data = $request->getParam('customer');
|
||||
if (!empty($data['extension_attributes']['salespersons_id'])) {
|
||||
$customer->getExtensionAttributes()->setSalespersonsId(implode(',', $data['extension_attributes']['salespersons_id']));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Plugin;
|
||||
|
||||
use Magento\Customer\Model\Customer\DataProviderWithDefaultAddresses;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Stemcell\Customer\Model\ResourceModel\Salesperson;
|
||||
|
||||
class DataProviderWithDefaultAddressesPlugin
|
||||
{
|
||||
public function __construct(
|
||||
protected Salesperson $salespersonResourceModel,
|
||||
){
|
||||
}
|
||||
|
||||
public function getSalesPerson(int $customerId)
|
||||
{
|
||||
$connection = $this->salespersonResourceModel->getConnection();
|
||||
$query = $connection->query('select salesperson_id from customer_salesperson where customer_id = '. $customerId);
|
||||
$result = $query->fetchAll();
|
||||
if (!empty($result)) {
|
||||
return array_column($result, 'salesperson_id');
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
public function afterGetData(
|
||||
DataProviderWithDefaultAddresses $subject,
|
||||
array $result
|
||||
): array {
|
||||
|
||||
$logger = ObjectManager::getInstance()->get(LoggerInterface::class);
|
||||
|
||||
foreach ($result as $id => $entityData) {
|
||||
if ($id) {
|
||||
|
||||
$result[$id]['customer']['extension_attributes']['customer_abbr'] = $entityData['customer']['customer_abbr'] ?? null;
|
||||
|
||||
$salesperson = $this->getSalesPerson($id);
|
||||
// $logger->warning('$salesperson', $salesperson);
|
||||
if ($salesperson) {
|
||||
$result[$id]['customer']['salespersons'] = $salesperson;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
# 经销商完导入数据模版.xlsx
|
||||
-可以通过这个模版将经销商账号导入customer中,这个excel转换成csv后,通过System->Import导入. 通过此方法可以导入密码
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Setup\Patch\Data;
|
||||
|
||||
use Magento\Customer\Model\Customer;
|
||||
use Magento\Customer\Setup\CustomerSetup;
|
||||
use Magento\Customer\Setup\CustomerSetupFactory;
|
||||
use Magento\Eav\Model\Entity\Attribute\Set;
|
||||
use Magento\Eav\Model\Entity\Attribute\SetFactory;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
|
||||
|
||||
class AddMobileCustomerAttribute implements DataPatchInterface, PatchRevertableInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ModuleDataSetupInterface
|
||||
*/
|
||||
private $moduleDataSetup;
|
||||
/**
|
||||
* @var CustomerSetup
|
||||
*/
|
||||
private $customerSetupFactory;
|
||||
/**
|
||||
* @var SetFactory
|
||||
*/
|
||||
private $attributeSetFactory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ModuleDataSetupInterface $moduleDataSetup
|
||||
* @param CustomerSetupFactory $customerSetupFactory
|
||||
* @param SetFactory $attributeSetFactory
|
||||
*/
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
CustomerSetupFactory $customerSetupFactory,
|
||||
SetFactory $attributeSetFactory
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->customerSetupFactory = $customerSetupFactory;
|
||||
$this->attributeSetFactory = $attributeSetFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply()
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
/** @var CustomerSetup $customerSetup */
|
||||
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
|
||||
$customerEntity = $customerSetup->getEavConfig()->getEntityType(Customer::ENTITY);
|
||||
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
|
||||
|
||||
/** @var $attributeSet Set */
|
||||
$attributeSet = $this->attributeSetFactory->create();
|
||||
$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
|
||||
|
||||
$customerSetup->addAttribute(
|
||||
Customer::ENTITY,
|
||||
'mobile',
|
||||
[
|
||||
'label' => 'Mobile',
|
||||
'input' => 'text',
|
||||
'type' => 'static',
|
||||
'source' => '',
|
||||
'required' => true,
|
||||
'position' => 333,
|
||||
'visible' => true,
|
||||
'system' => false,
|
||||
'is_used_in_grid' => true,
|
||||
'is_visible_in_grid' => true,
|
||||
'is_filterable_in_grid' => true,
|
||||
'is_searchable_in_grid' => false,
|
||||
'backend' => '',
|
||||
'unique' => true
|
||||
]
|
||||
);
|
||||
|
||||
$attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'mobile');
|
||||
$attribute->addData([
|
||||
'used_in_forms' => [
|
||||
'adminhtml_customer',
|
||||
'customer_account_create',
|
||||
'customer_account_edit'
|
||||
]
|
||||
]);
|
||||
$attribute->addData([
|
||||
'attribute_set_id' => $attributeSetId,
|
||||
'attribute_group_id' => $attributeGroupId
|
||||
|
||||
]);
|
||||
$attribute->save();
|
||||
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
}
|
||||
|
||||
public function revert()
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
/** @var CustomerSetup $customerSetup */
|
||||
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
|
||||
$customerSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'mobile');
|
||||
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAliases()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getDependencies()
|
||||
{
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Customer\Setup\Patch\Data;
|
||||
|
||||
use Magento\Customer\Model\Customer;
|
||||
use Magento\Customer\Setup\CustomerSetup;
|
||||
use Magento\Customer\Setup\CustomerSetupFactory;
|
||||
use Magento\Eav\Model\Entity\Attribute\SetFactory;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\DataPatchInterface;
|
||||
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
|
||||
|
||||
class UpdateCustomerNameToNotRequired implements DataPatchInterface, PatchRevertableInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ModuleDataSetupInterface
|
||||
*/
|
||||
private $moduleDataSetup;
|
||||
/**
|
||||
* @var CustomerSetup
|
||||
*/
|
||||
private $customerSetupFactory;
|
||||
/**
|
||||
* @var SetFactory
|
||||
*/
|
||||
private $attributeSetFactory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ModuleDataSetupInterface $moduleDataSetup
|
||||
* @param CustomerSetupFactory $customerSetupFactory
|
||||
* @param SetFactory $attributeSetFactory
|
||||
*/
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
CustomerSetupFactory $customerSetupFactory,
|
||||
SetFactory $attributeSetFactory
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->customerSetupFactory = $customerSetupFactory;
|
||||
$this->attributeSetFactory = $attributeSetFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply()
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
/** @var CustomerSetup $customerSetup */
|
||||
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
|
||||
|
||||
$customerSetup->updateAttribute(Customer::ENTITY,'firstname','is_required',0);
|
||||
$customerSetup->updateAttribute(Customer::ENTITY,'lastname','is_required',0);
|
||||
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
}
|
||||
|
||||
public function revert()
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
/** @var CustomerSetup $customerSetup */
|
||||
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
|
||||
$customerSetup->updateAttribute(Customer::ENTITY,'firstname','is_required',1);
|
||||
$customerSetup->updateAttribute(Customer::ENTITY,'lastname','is_required',1);
|
||||
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAliases()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getDependencies()
|
||||
{
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Setup\Patch\Schema;
|
||||
|
||||
use Magento\Customer\Model\Customer;
|
||||
use Magento\Customer\Model\Indexer\Address\AttributeProvider;
|
||||
use Magento\Customer\Setup\CustomerSetup;
|
||||
use Magento\Customer\Setup\CustomerSetupFactory;
|
||||
use Magento\Eav\Model\AttributeRepository;
|
||||
use Magento\Eav\Model\Entity\Attribute\Set;
|
||||
use Magento\Eav\Model\Entity\Attribute\SetFactory;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Setup\ModuleContextInterface;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
|
||||
use Magento\Framework\Setup\SchemaSetupInterface;
|
||||
use Magento\Framework\Validator\ValidateException;
|
||||
|
||||
class AddCustomerAbbrAttribute implements SchemaPatchInterface
|
||||
{
|
||||
/**
|
||||
* @var ModuleDataSetupInterface
|
||||
*/
|
||||
private $moduleDataSetup;
|
||||
/**
|
||||
* @var CustomerSetup
|
||||
*/
|
||||
private $customerSetupFactory;
|
||||
/**
|
||||
* @var SetFactory
|
||||
*/
|
||||
private $attributeSetFactory;
|
||||
private AttributeRepository $repository;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ModuleDataSetupInterface $moduleDataSetup
|
||||
* @param CustomerSetupFactory $customerSetupFactory
|
||||
* @param SetFactory $attributeSetFactory
|
||||
*/
|
||||
public function __construct(
|
||||
ModuleDataSetupInterface $moduleDataSetup,
|
||||
CustomerSetupFactory $customerSetupFactory,
|
||||
SetFactory $attributeSetFactory,
|
||||
AttributeRepository $repository
|
||||
) {
|
||||
$this->moduleDataSetup = $moduleDataSetup;
|
||||
$this->customerSetupFactory = $customerSetupFactory;
|
||||
$this->attributeSetFactory = $attributeSetFactory;
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAliases()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getDependencies()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws LocalizedException
|
||||
* @throws ValidateException
|
||||
*/
|
||||
public function apply()
|
||||
{
|
||||
$this->moduleDataSetup->getConnection()->startSetup();
|
||||
/** @var CustomerSetup $customerSetup */
|
||||
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
|
||||
|
||||
$customerSetup->addAttribute(Customer::ENTITY, 'customer_abbr', [
|
||||
'type' => 'varchar',
|
||||
'label' => 'Customer Abbr',
|
||||
'input' => 'text',
|
||||
'source' => '',
|
||||
'required' => true,
|
||||
'visible' => false,
|
||||
'position' => 330,
|
||||
'is_user_defined' => true,
|
||||
'is_used_in_grid' => true,
|
||||
]);
|
||||
|
||||
$this->moduleDataSetup->getConnection()->endSetup();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Setup;
|
||||
|
||||
use Magento\Customer\Model\Customer;
|
||||
use Magento\Framework\Setup\InstallDataInterface;
|
||||
use Magento\Framework\Setup\SchemaSetupInterface;
|
||||
use Magento\Framework\Setup\UpgradeSchemaInterface;
|
||||
use Magento\Framework\Setup\ModuleContextInterface;
|
||||
use Magento\Framework\Setup\ModuleDataSetupInterface;
|
||||
use Stemcell\Customer\Model\Attribute\Source\CustomerType;
|
||||
use Stemcell\Customer\Model\Attribute\Source\ResearchFields;
|
||||
|
||||
class RegistryInstallData implements UpgradeSchemaInterface
|
||||
{
|
||||
protected $eavSetupFactory;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Eav\Setup\EavSetupFactory $eavSetupFactory
|
||||
){
|
||||
$this->eavSetupFactory = $eavSetupFactory;
|
||||
}
|
||||
|
||||
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
|
||||
{
|
||||
$eavSetup = $this->eavSetupFactory->create();
|
||||
$eavSetup->addAttribute(
|
||||
Customer::ENTITY,
|
||||
'customer_type',
|
||||
[
|
||||
'label' => 'Customer Type',
|
||||
'input' => 'select',
|
||||
'type' => 'static',
|
||||
'source' => CustomerType::class,
|
||||
'required' => false,
|
||||
'position' => 333,
|
||||
'visible' => false,
|
||||
'system' => false,
|
||||
'is_used_in_grid' => true,
|
||||
'is_visible_in_grid' => true,
|
||||
'is_filterable_in_grid' => true,
|
||||
'is_searchable_in_grid' => false,
|
||||
]
|
||||
);
|
||||
//公司或单位名称
|
||||
$eavSetup->addAttribute(
|
||||
Customer::ENTITY,
|
||||
'company_name',
|
||||
[
|
||||
'label' => 'Company Name',
|
||||
'input' => 'text',
|
||||
'type' => 'varchar',
|
||||
'required' => false,
|
||||
'position' => 334,
|
||||
'visible' => true,
|
||||
'system' => false,
|
||||
'is_used_in_grid' => true,
|
||||
'is_visible_in_grid' => true,
|
||||
'is_filterable_in_grid' => true,
|
||||
'is_searchable_in_grid' => false
|
||||
]
|
||||
);
|
||||
$eavSetup->addAttribute(
|
||||
Customer::ENTITY,
|
||||
'company_address',
|
||||
[
|
||||
'label' => 'Company Address',
|
||||
'input' => 'text',
|
||||
'type' => 'varchar',
|
||||
'required' => false,
|
||||
'position' => 335,
|
||||
'visible' => true,
|
||||
'system' => false,
|
||||
'is_used_in_grid' => true,
|
||||
'is_visible_in_grid' => true,
|
||||
'is_filterable_in_grid' => true,
|
||||
'is_searchable_in_grid' => false
|
||||
]
|
||||
);
|
||||
//课题组、部门
|
||||
$eavSetup->addAttribute(
|
||||
Customer::ENTITY,
|
||||
'department',
|
||||
[
|
||||
'label' => 'Department',
|
||||
'input' => 'text',
|
||||
'type' => 'varchar',
|
||||
'required' => false,
|
||||
'position' => 335,
|
||||
'visible' => true,
|
||||
'system' => false,
|
||||
'is_used_in_grid' => true,
|
||||
'is_visible_in_grid' => true,
|
||||
'is_filterable_in_grid' => true,
|
||||
'is_searchable_in_grid' => false
|
||||
]
|
||||
);
|
||||
//研究方向
|
||||
$eavSetup->addAttribute(
|
||||
Customer::ENTITY,
|
||||
'research_fields',
|
||||
[
|
||||
'label' => 'Research Fields',
|
||||
'input' => 'multiselect',
|
||||
'type' => 'varchar',
|
||||
'required' => false,
|
||||
'position' => 335,
|
||||
'visible' => true,
|
||||
'system' => false,
|
||||
'is_used_in_grid' => true,
|
||||
'is_visible_in_grid' => true,
|
||||
'is_filterable_in_grid' => true,
|
||||
'is_searchable_in_grid' => false,
|
||||
'source' => ResearchFields::class
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
+256
@@ -0,0 +1,256 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Ui\Component\DataProvider;
|
||||
|
||||
use Magento\Customer\Api\CustomerRepositoryInterface;
|
||||
use Magento\Customer\Model\Address;
|
||||
use Magento\Customer\Model\AttributeMetadataResolver;
|
||||
use Magento\Customer\Model\Customer;
|
||||
use Magento\Customer\Model\CustomerFactory;
|
||||
use Magento\Customer\Model\FileUploaderDataResolver;
|
||||
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
|
||||
use Magento\Directory\Model\CountryFactory;
|
||||
use Magento\Eav\Model\Config;
|
||||
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
|
||||
use Magento\Eav\Model\Entity\Type;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Session\SessionManagerInterface;
|
||||
use Magento\Framework\View\Element\UiComponent\ContextInterface;
|
||||
use Magento\Ui\Component\Form\Element\Multiline;
|
||||
|
||||
class DataProviderWithDefaultAddresses extends Customer\DataProviderWithDefaultAddresses
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $loadedData = [];
|
||||
|
||||
/**
|
||||
* @var SessionManagerInterface
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
/**
|
||||
* Customer fields that must be removed
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $forbiddenCustomerFields = [
|
||||
'password_hash',
|
||||
'rp_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* Allow to manage attributes, even they are hidden on storefront
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $allowToShowHiddenAttributes;
|
||||
|
||||
/**
|
||||
* @var CountryFactory
|
||||
*/
|
||||
protected $countryFactory;
|
||||
|
||||
/**
|
||||
* @var FileUploaderDataResolver
|
||||
*/
|
||||
protected $fileUploaderDataResolver;
|
||||
|
||||
/**
|
||||
* @var AttributeMetadataResolver
|
||||
*/
|
||||
protected $attributeMetadataResolver;
|
||||
|
||||
/**
|
||||
* @var CustomerFactory
|
||||
*/
|
||||
protected $customerFactory;
|
||||
|
||||
/**
|
||||
* @var ContextInterface
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* @var CustomerRepositoryInterface
|
||||
*/
|
||||
protected $customerRepository;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $primaryFieldName
|
||||
* @param string $requestFieldName
|
||||
* @param CustomerCollectionFactory $customerCollectionFactory
|
||||
* @param Config $eavConfig
|
||||
* @param CountryFactory $countryFactory
|
||||
* @param SessionManagerInterface $session
|
||||
* @param FileUploaderDataResolver $fileUploaderDataResolver
|
||||
* @param AttributeMetadataResolver $attributeMetadataResolver
|
||||
* @param bool $allowToShowHiddenAttributes
|
||||
* @param array $meta
|
||||
* @param array $data
|
||||
* @param CustomerFactory|null $customerFactory
|
||||
* @param ContextInterface|null $context
|
||||
* @param CustomerRepositoryInterface|null $customerRepository
|
||||
* @throws LocalizedException
|
||||
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
||||
*/
|
||||
public function __construct(
|
||||
string $name,
|
||||
string $primaryFieldName,
|
||||
string $requestFieldName,
|
||||
CustomerCollectionFactory $customerCollectionFactory,
|
||||
Config $eavConfig,
|
||||
CountryFactory $countryFactory,
|
||||
SessionManagerInterface $session,
|
||||
FileUploaderDataResolver $fileUploaderDataResolver,
|
||||
AttributeMetadataResolver $attributeMetadataResolver,
|
||||
$allowToShowHiddenAttributes = true,
|
||||
array $meta = [],
|
||||
array $data = [],
|
||||
CustomerFactory $customerFactory = null,
|
||||
?ContextInterface $context = null,
|
||||
CustomerRepositoryInterface $customerRepository = null
|
||||
) {
|
||||
parent::__construct($name, $primaryFieldName, $requestFieldName, $customerCollectionFactory, $eavConfig, $countryFactory, $session, $fileUploaderDataResolver, $attributeMetadataResolver, $allowToShowHiddenAttributes, $meta, $data, $customerFactory, $context, $customerRepository);
|
||||
$this->session = $session;
|
||||
$this->allowToShowHiddenAttributes = $allowToShowHiddenAttributes;
|
||||
$this->countryFactory = $countryFactory;
|
||||
$this->fileUploaderDataResolver = $fileUploaderDataResolver;
|
||||
$this->attributeMetadataResolver = $attributeMetadataResolver;
|
||||
$this->context = $context ?? ObjectManager::getInstance()->get(ContextInterface::class);
|
||||
$this->customerFactory = $customerFactory ?: ObjectManager::getInstance()->get(CustomerFactory::class);
|
||||
$this->customerRepository = $customerRepository ??
|
||||
ObjectManager::getInstance()->get(CustomerRepositoryInterface::class);
|
||||
$this->meta['customer']['children'] = $this->getAttributesMeta(
|
||||
$eavConfig->getEntityType('customer')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getData(): array
|
||||
{
|
||||
if (!empty($this->loadedData)) {
|
||||
return $this->loadedData;
|
||||
}
|
||||
$items = $this->collection->getItems();
|
||||
/** @var Customer $customer */
|
||||
foreach ($items as $customer) {
|
||||
if ($customer->getSalespersonsId()) {
|
||||
$customer->setSalespersonsId(explode(',', $customer->getSalespersonsId()));
|
||||
}
|
||||
|
||||
$result['customer'] = $customer->getData();
|
||||
if ($customer->getSalespersonsId()) {
|
||||
$result['customer']['extension_attributes']['salespersons_id'] = $customer->getSalespersonsId();
|
||||
}
|
||||
|
||||
$this->fileUploaderDataResolver->overrideFileUploaderData($customer, $result['customer']);
|
||||
|
||||
$result['customer'] = array_diff_key(
|
||||
$result['customer'],
|
||||
array_flip(self::$forbiddenCustomerFields)
|
||||
);
|
||||
$this->prepareCustomAttributeValue($result['customer']);
|
||||
|
||||
$result['default_billing_address'] = $this->prepareDefaultAddress(
|
||||
$customer->getDefaultBillingAddress()
|
||||
);
|
||||
$result['default_shipping_address'] = $this->prepareDefaultAddress(
|
||||
$customer->getDefaultShippingAddress()
|
||||
);
|
||||
$result['customer_id'] = $customer->getId();
|
||||
|
||||
$this->loadedData[$customer->getId()] = $result;
|
||||
}
|
||||
$data = $this->session->getCustomerFormData();
|
||||
if (!empty($data)) {
|
||||
$customer = $this->customerFactory->create();
|
||||
$this->fileUploaderDataResolver->overrideFileUploaderData($customer, $data['customer']);
|
||||
$customerId = $data['customer']['entity_id'] ?? null;
|
||||
$this->loadedData[$customerId] = $data;
|
||||
$this->session->unsCustomerFormData();
|
||||
}
|
||||
|
||||
return $this->loadedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare default address data.
|
||||
*
|
||||
* @param Address|false $address
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareDefaultAddress($address): array
|
||||
{
|
||||
if (!$address) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$addressData = $address->getData();
|
||||
if (isset($addressData['street']) && !is_array($addressData['street'])) {
|
||||
$addressData['street'] = explode("\n", $addressData['street']);
|
||||
}
|
||||
if (!empty($addressData['country_id'])) {
|
||||
$addressData['country'] = $this->countryFactory->create()
|
||||
->loadByCode($addressData['country_id'])
|
||||
->getName();
|
||||
}
|
||||
$addressData['region'] = $address->getRegion();
|
||||
|
||||
return $addressData;
|
||||
}
|
||||
|
||||
/***
|
||||
* Prepare values for Custom Attributes.
|
||||
*
|
||||
* @param array $data
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareCustomAttributeValue(array &$data): void
|
||||
{
|
||||
foreach ($this->meta['customer']['children'] as $attributeName => $attributeMeta) {
|
||||
if ($attributeMeta['arguments']['data']['config']['dataType'] === Multiline::NAME
|
||||
&& isset($data[$attributeName])
|
||||
&& !is_array($data[$attributeName])
|
||||
) {
|
||||
$data[$attributeName] = explode("\n", $data[$attributeName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attributes meta
|
||||
*
|
||||
* @param Type $entityType
|
||||
* @return array
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
protected function getAttributesMeta(Type $entityType): array
|
||||
{
|
||||
$meta = [];
|
||||
$attributes = $entityType->getAttributeCollection();
|
||||
$customerId = $this->context->getRequestParam('id');
|
||||
if ($customerId) {
|
||||
$customer = $this->customerRepository->getById($customerId);
|
||||
$attributes->setWebsite($customer->getWebsiteId());
|
||||
}
|
||||
/* @var AbstractAttribute $attribute */
|
||||
foreach ($attributes as $attribute) {
|
||||
$meta[$attribute->getAttributeCode()] = $this->attributeMetadataResolver->getAttributesMeta(
|
||||
$attribute,
|
||||
$entityType,
|
||||
$this->allowToShowHiddenAttributes
|
||||
);
|
||||
}
|
||||
$this->attributeMetadataResolver->processWebsiteMeta($meta);
|
||||
|
||||
return $meta;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Ui\Component\DataProvider;
|
||||
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\Session\SessionManagerInterface;
|
||||
use Magento\Ui\DataProvider\AbstractDataProvider;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Stemcell\Customer\Model\ResourceModel\Lab\CollectionFactory;
|
||||
|
||||
class Lab extends AbstractDataProvider
|
||||
{
|
||||
protected SessionManagerInterface $session;
|
||||
|
||||
public function __construct(
|
||||
$name,
|
||||
$primaryFieldName,
|
||||
$requestFieldName,
|
||||
SessionManagerInterface $session,
|
||||
CollectionFactory $collectionFactory,
|
||||
array $meta = [],
|
||||
array $data = []
|
||||
) {
|
||||
$this->collection = $collectionFactory->create();
|
||||
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
public function getData(): array
|
||||
{
|
||||
$data = [];
|
||||
$salesperson = $this->session->getLab();
|
||||
if (!empty($salesperson) && isset($salesperson['lab_id'])) {
|
||||
$data[$salesperson['lab_id']]['lab'] = $salesperson;
|
||||
}
|
||||
$this->session->unsLab();
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Customer\Ui\Component\DataProvider;
|
||||
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\Session\SessionManagerInterface;
|
||||
use Magento\Ui\DataProvider\AbstractDataProvider;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Stemcell\Customer\Model\ResourceModel\Salesperson\CollectionFactory;
|
||||
|
||||
class Salesperson extends AbstractDataProvider
|
||||
{
|
||||
protected SessionManagerInterface $session;
|
||||
|
||||
public function __construct(
|
||||
$name,
|
||||
$primaryFieldName,
|
||||
$requestFieldName,
|
||||
SessionManagerInterface $session,
|
||||
CollectionFactory $collectionFactory,
|
||||
array $meta = [],
|
||||
array $data = []
|
||||
) {
|
||||
$this->collection = $collectionFactory->create();
|
||||
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
public function getData(): array
|
||||
{
|
||||
$data = [];
|
||||
$salesperson = $this->session->getSalesperson();
|
||||
if (!empty($salesperson) && isset($salesperson['salesperson_id'])) {
|
||||
$data[$salesperson['salesperson_id']]['salesperson'] = $salesperson;
|
||||
}
|
||||
$this->session->unsSalesperson();
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user