0

I want to rewrite the block: Magento\Sales\Block\Adminhtml\Order\Create\Form\Address

Here is my code: di.xml

    <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Sales\Block\Adminhtml\Order\Create\Form\Address" type="Freedom\Adminorder\Block\Adminhtml\Order\Create\Form\Address" />
</config>

Address.php

    <?php
namespace Freedom\Adminorder\Block\Adminhtml\Order\Create\Form;
use Magento\Framework\Pricing\PriceCurrencyInterface;

class Address extends \Magento\Sales\Block\Adminhtml\Order\Create\Shipping\Address {
    public function __construct(\Magento\Backend\Block\Template\Context $context,
                                \Magento\Backend\Model\Session\Quote $sessionQuote,
                                \Magento\Sales\Model\AdminOrder\Create $orderCreate,
                                PriceCurrencyInterface $priceCurrency,
                                \Magento\Framework\Data\FormFactory $formFactory,
                                \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor,
                                \Magento\Directory\Helper\Data $directoryHelper,
                                \Magento\Framework\Json\EncoderInterface $jsonEncoder,
                                \Magento\Customer\Model\Metadata\FormFactory $customerFormFactory,
                                \Magento\Customer\Model\Options $options,
                                \Magento\Customer\Helper\Address $addressHelper,
                                \Magento\Customer\Api\AddressRepositoryInterface $addressService,
                                \Magento\Framework\Api\SearchCriteriaBuilder $criteriaBuilder,
                                \Magento\Framework\Api\FilterBuilder $filterBuilder,
                                \Magento\Customer\Model\Address\Mapper $addressMapper,
                                array $data = []) {
        parent::__construct($context, $sessionQuote, $orderCreate, $priceCurrency, $formFactory, $dataObjectProcessor, $directoryHelper, $jsonEncoder, $customerFormFactory, $options, $addressHelper, $addressService, $criteriaBuilder, $filterBuilder, $addressMapper, $data);
    }

    public function getAddressCollection()
    {
        if ($this->getCustomerId()) {
//            $filter = $this->filterBuilder
//                ->setField('parent_id')
//                ->setValue($this->getCustomerId())
//                ->setConditionType('eq')
//                ->create();
            $filter = $this->filterBuilder
                ->setField('entity_id')
                ->setValue([1,5])
                ->setConditionType('in')
                ->create();
            $this->searchCriteriaBuilder->addFilters([$filter]);
            $searchCriteria = $this->searchCriteriaBuilder->create();
            $result = $this->addressService->getList($searchCriteria);
            return $result->getItems();
        }
        return [];
    }
}

It is not working. Cananyone help me?

  • Suggestion: remove the constructor from your code as you don't inject extra dependencies – Raphael at Digital Pianism Jun 12 '16 at 13:24
  • Does your extension show under "List of enabled extensions" when you run bin/magento module:status ? Also is it listed after Magento_Sales? – Kristof at Fooman Jun 12 '16 at 16:02
1

same issue
seems like magento 2 can't rewrite not obviously declared classes, like Magento\Sales\Block\Adminhtml\Order\Create\Form\Address

but u can rewrite Magento\Sales\Block\Adminhtml\Order\Create\Billing\Address and Magento\Sales\Block\Adminhtml\Order\Create\Shipping\Address instead

  • extending Magento\Sales\Block\Adminhtml\Order\Create\Billing\Address will cause error whiling using billing address same as shipping address . – Divya Muralidharan Sep 19 '18 at 4:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.