This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -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();
}
}