Skip to content

Commit

Permalink
feat: added new fields to recipient (#320)
Browse files Browse the repository at this point in the history
feat: added new fields to recipient
  • Loading branch information
RafaMelazzo authored Mar 26, 2024
2 parents 7d697a9 + cf1125e commit 85fd96e
Show file tree
Hide file tree
Showing 28 changed files with 2,060 additions and 819 deletions.
73 changes: 64 additions & 9 deletions Block/Adminhtml/Marketplace/Recipient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

namespace Pagarme\Pagarme\Block\Adminhtml\Marketplace;

use Exception;
use Magento\Customer\Model\ResourceModel\Customer\Collection;
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
use Magento\Directory\Model\Country;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Pagarme\Pagarme\Concrete\Magento2CoreSetup;
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
use Pagarme\Core\Marketplace\Repositories\RecipientRepository;
use Pagarme\Pagarme\Concrete\Magento2CoreSetup;
use stdClass;

class Recipient extends Template
{

/**
* @var Collection
*/
private $customerCollection;

/**
Expand All @@ -25,7 +30,6 @@ class Recipient extends Template
*/
private $coreRegistry;


/**
* @var array
*/
Expand All @@ -36,19 +40,31 @@ class Recipient extends Template
*/
private $recipient = null;

/**
* @var Country
*/
private $country;


/**
* Link constructor.
* @param Context $context
* @param Registry $registry
* @param CustomerCollectionFactory $customerCollectionFactory
* @param Country $country
* @throws Exception
*/
public function __construct(
Context $context,
Registry $registry,
CustomerCollectionFactory $customerCollectionFactory
) {
Context $context,
Registry $registry,
CustomerCollectionFactory $customerCollectionFactory,
Country $country
)
{
$this->coreRegistry = $registry;
$this->customerCollection = $customerCollectionFactory->create();
$this->recipientRepository = new RecipientRepository();
$this->country = $country;

Magento2CoreSetup::bootstrap();
parent::__construct($context, []);
Expand Down Expand Up @@ -127,4 +143,43 @@ public function getSellers()

return $this->sellers;
}
}

/**
* @param string $countryCode
* @return array
*/
public function getAllRegionsOfCountry($countryCode = 'BR')
{
return $this->country->loadByCode($countryCode)->getRegions()->getData();
}

public function getLabel($key)
{
$labels = [
'no' => 'No',
'yes' => 'Yes',
'document_type' => 'Document type',
'document_number' => 'Document number',
'name' => 'Name',
'mother_name' => 'Mother name',
'email' => 'E-mail',
'birthdate' => 'Date of birth',
'monthly_income' => 'Monthly income',
'profession' => 'Profession',
'contact_type' => 'Contact type',
'contact_number' => 'Contact number',
'mobile_phone' => 'Mobile phone',
'street' => 'Street',
'number' => 'Number',
'complement' => 'Complement',
'neighborhood' => 'Neighborhood',
'reference_point' => 'Reference point',
'state' => 'State/Province',
'city' => 'City',
'zip' => 'Zip/Postal Code',
'select' => 'Select',
];

return __($labels[$key]);
}
}
24 changes: 11 additions & 13 deletions Controller/Adminhtml/Recipients/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

namespace Pagarme\Pagarme\Controller\Adminhtml\Recipients;

use Magento\Framework\Registry;
use Magento\Framework\Controller\ResultInterface;
use Pagarme\Core\Marketplace\Services\RecipientService;
use Webkul\Marketplace\Model\SellerFactory;
use Pagarme\Pagarme\Controller\Adminhtml\Recipients\RecipientAction;

class Create extends RecipientAction
{
Expand All @@ -17,27 +13,29 @@ class Create extends RecipientAction
*/
public function execute()
{

$sellers = $this->sellerFactory->create()->getCollection()->load();
$sellers = $sellers->getItems();

$this->coreRegistry->register('sellers', serialize($sellers));

$recipientId = (int)$this->getRequest()->getParam('id');
if ($recipientId) {

$recipientService = new RecipientService();
$recipient = $recipientService->findById($recipientId);
$externalId = $recipient->getExternalId();
$localId = $recipient->getId();
$recipient = $recipientService->findByPagarmeId($recipient->getPagarmeId());

$this->resourceModelRecipient->load($this->recipient, $recipientId);
$recipient = $this->recipientService->searchRecipient($this->recipient->getPagarmeId());
if (!$recipient || !$recipient->id) {
$this->messageManager->addError(__('Recipient not exist.'));
$this->_redirect('pagarme_pagarme/recipients/index');
return;
}

$this->coreRegistry->register('recipient_data', json_encode(['recipient' => $recipient, 'externalId' => $externalId, 'localId' => $localId]));
$this->coreRegistry->register(
'recipient_data',
json_encode([
'recipient' => $recipient,
'externalId' => $recipient->code,
'localId' => $recipientId
])
);
}

$resultPage = $this->resultPageFactory->create();
Expand Down
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Recipients/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function execute()

$recipientService->delete($recipientId);

$message = $this->messageFactory->create('success', _("Recipient deleted."));
$message = $this->messageFactory->create('success', __("Recipient deleted."));
$this->messageManager->addMessage($message);

$this->_redirect('pagarme_pagarme/recipients/index');
Expand Down
37 changes: 32 additions & 5 deletions Controller/Adminhtml/Recipients/RecipientAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

use Exception;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Registry;
use Pagarme\Pagarme\Model\Recipient;
use Magento\Backend\App\Action\Context;
use Webkul\Marketplace\Model\SellerFactory;
use Magento\Framework\View\Result\PageFactory;
use Pagarme\Pagarme\Concrete\Magento2CoreSetup;
use Webkul\Marketplace\Model\SellerFactory;
use Magento\Framework\Message\Factory as MagentoMessageFactory;
use Magento\Framework\Module\Manager as ModuleManager;

use Pagarme\Pagarme\Service\Marketplace\RecipientService;
use Magento\Framework\Message\Factory as MagentoMessageFactory;
use Pagarme\Pagarme\Model\ResourceModel\Recipients as ResourceModelRecipient;

class RecipientAction extends Action
{
Expand All @@ -36,21 +38,42 @@ class RecipientAction extends Action
* @var ModuleManager
*/
private $moduleManager;
/**
*
* @var \Pagarme\Pagarme\Model\ResourceModel\Recipients
*/
protected $resourceModelRecipient;
/**
*
* @var \Pagarme\Pagarme\Model\Recipient
*/
protected $recipient;
/**
*
* @var \Pagarme\Pagarme\Service\Marketplace\RecipientService
*/
protected $recipientService;

/**
* @param Context $context
* @param Registry $coreRegistry
* @param PageFactory $resultPageFactory
* @param MagentoMessageFactory $messageFactory
* @param ModuleManager $moduleManager
* @param ResourceModelRecipient $resourceModelRecipient
* @param Recipient $recipient
* @param RecipientService $recipientService
* @throws Exception
*/
public function __construct(
Context $context,
Registry $coreRegistry,
PageFactory $resultPageFactory,
MagentoMessageFactory $messageFactory,
ModuleManager $moduleManager
ModuleManager $moduleManager,
ResourceModelRecipient $resourceModelRecipient,
Recipient $recipient,
RecipientService $recipientService
) {

parent::__construct($context);
Expand All @@ -59,7 +82,11 @@ public function __construct(
$this->coreRegistry = $coreRegistry;
$this->messageFactory = $messageFactory;
$this->moduleManager = $moduleManager;
$this->resourceModelRecipient = $resourceModelRecipient;
$this->recipient = $recipient;
$this->recipientService = $recipientService;
$this->__init();

Magento2CoreSetup::bootstrap();
}

Expand Down
Loading

0 comments on commit 85fd96e

Please sign in to comment.