Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
48f8a0b
Fix dropdown select and optimized directory helper
xtremevision Jun 13, 2023
4721696
Add files to module
florinm8 Apr 7, 2025
c36adfa
Update namespace
florinm8 Apr 7, 2025
07e1199
Merge pull request #1 from xtremevision/XVT-3-city-dropdown-on-admin-…
xtremevision Apr 7, 2025
10fb3ea
Fix for missing RegionProvider class
xtremevision Apr 8, 2025
b6f31f3
Update README.md
xtremevision Apr 8, 2025
0cfafdd
move collections definitions in the same argumenets list
florinm8 Apr 8, 2025
bbca601
Merge pull request #2 from xtremevision/fix-regions-grid-production-mode
xtremevision Apr 8, 2025
b08024c
Fix for missing RegionProvider class
xtremevision Apr 8, 2025
b983918
Merge branch 'master' of github.com:xtremevision/Magento2-City-Dropdown
xtremevision Apr 8, 2025
d70188a
Fixed crash in Admin Region grid
xtremevision Apr 9, 2025
31705df
Added region name in City Grid
xtremevision Apr 9, 2025
44b0b75
fix city dropdown on customer addresses
florinm8 Apr 15, 2025
b932019
Merge pull request #3 from xtremevision/feature/XVT-3-city-dropdown-f…
xtremevision Apr 25, 2025
ced4014
add mixin for mageworx order editor; adjust js to work with different…
florinm8 May 6, 2025
f51f0ad
add mageworks dependency
florinm8 May 6, 2025
d1cf8c4
overwrite template
florinm8 May 6, 2025
733730e
add param to js for selectors without mageworks module
florinm8 May 6, 2025
fff2fe4
Merge pull request #4 from xtremevision/feature/XVT-3-city-dropdown-f…
xtremevision May 14, 2025
d82a11c
Fixed typo in admin template
xtremevision May 15, 2025
262ec0e
add check to stop place order if city is not allowed
florinm8 May 22, 2025
c8bba81
replace inputs and other fixes
florinm8 May 24, 2025
c20be37
Merge pull request #6 from xtremevision/feature/XVT-3-replace-inputs-…
xtremevision May 28, 2025
607f631
Merge pull request #5 from xtremevision/feature/XVT-block-users-witho…
xtremevision May 28, 2025
532c617
merge master
florinm8 Jun 8, 2025
1e67ee3
invalidate address without throwing error; increase timeout for admin…
florinm8 Jun 8, 2025
237556f
fix typo
florinm8 Jun 8, 2025
b7b6899
Merge pull request #7 from xtremevision/feature/XVT-block-users-witho…
xtremevision Jun 18, 2025
5899820
fix admin city dropdown on new customer; add mixin for checkout to ma…
florinm8 Jun 20, 2025
8ac439f
remove logs
florinm8 Jun 20, 2025
efd7f80
Merge pull request #8 from xtremevision/feature/XVT-block-users-witho…
xtremevision Jun 23, 2025
2346093
fix admin create order create new customer address city dropdown
florinm8 Jun 28, 2025
cbd5207
Merge pull request #9 from xtremevision/feature/XVT-block-users-witho…
xtremevision Jul 12, 2025
e59d7bf
Empty AllowedBilling cities and shipping causes checkout error
xtremevision Sep 3, 2025
1e14493
Fix for create order city select not populating
xtremevision Sep 24, 2025
671bd88
add check if the region is found in the table before validating that …
florinm8 Sep 24, 2025
2245e4d
Merge pull request #10 from xtremevision/feature/fix-checkout-address…
xtremevision Sep 25, 2025
23b07b5
Possible fix for State field no visible in dom
xtremevision Sep 25, 2025
d02d30f
Fix for Shipping city dropdown getting disabled when not same billing…
xtremevision Sep 25, 2025
fcd0934
Fixed onclick sameasbilling city input/select issue
xtremevision Sep 26, 2025
85860e9
Skipped validation error for shipping address if quote is virtual
xtremevision Nov 3, 2025
c93deea
remove address invalidation
florinm8 Nov 3, 2025
aa10a19
Merge pull request #11 from xtremevision/feature/XVT-checkout-errors
xtremevision Nov 3, 2025
e4510c3
City not selected in dropdown when editing address as logged in user
xtremevision Nov 3, 2025
c80ddce
Removed js console debugging
xtremevision Nov 3, 2025
bdb0b6c
mark invalid addresses in checkout
florinm8 Nov 6, 2025
6a901f7
update with master
florinm8 Nov 6, 2025
9965957
Merge pull request #12 from xtremevision/feature/XVT-checkout-errors
xtremevision Nov 12, 2025
7f27fc3
Missing accessor and conflict with shipping.js
xtremevision Nov 13, 2025
fd2a168
Added City add/edit feature
xtremevision Nov 16, 2025
c1e06b5
Tried to fix go to import button
xtremevision Nov 16, 2025
d1e45dc
Some tidying up
xtremevision Nov 16, 2025
32de8ef
load dropdowns for city from backend directly; various fixes on city-…
florinm8 Nov 18, 2025
f297ce5
Merge pull request #13 from xtremevision/feature/XVT-10-admin-create-…
xtremevision Nov 18, 2025
3fc4552
Fixed minor non-existent index
xtremevision Nov 19, 2025
f288169
fix import link
florinm8 Nov 19, 2025
2ee30ee
Merge pull request #14 from xtremevision/feature/XVT-9-admin-import-link
xtremevision Nov 21, 2025
e7923fc
XVT-8 fix get address as string missing custom address fields
direbrain Nov 25, 2025
1292138
Merge pull request #15 from xtremevision/XVT-8
xtremevision Dec 2, 2025
858b621
Fix for [city] not existing error
xtremevision Jan 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Block/Adminhtml/City/Edit/BackButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Copyright © 2018 EaDesign by Eco Active S.R.L.
* See LICENSE for license details.
*/

namespace Eadesigndev\RomCity\Block\Adminhtml\City\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

class BackButton extends GenericButton implements ButtonProviderInterface
{
/**
* @inheritdoc
*/
public function getButtonData()
{
return [
'label' => __('Back'),
'on_click' => sprintf("location.href = '%s';", $this->getUrl('*/*/')),
'class' => 'back',
'sort_order' => 10
];
}
}
36 changes: 36 additions & 0 deletions Block/Adminhtml/City/Edit/DeleteButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright © 2018 EaDesign by Eco Active S.R.L.
* See LICENSE for license details.
*/

namespace Eadesigndev\RomCity\Block\Adminhtml\City\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

class DeleteButton extends GenericButton implements ButtonProviderInterface
{
/**
* @inheritdoc
*/
public function getButtonData()
{
$data = [];
$cityId = $this->getCityId();

if ($cityId) {
$data = [
'label' => __('Delete'),
'class' => 'delete',
'on_click' => sprintf(
"deleteConfirm('%s', '%s')",
__('Are you sure you want to delete this city?'),
$this->getUrl('*/*/delete', ['entity_id' => $cityId])
),
'sort_order' => 20
];
}

return $data;
}
}
42 changes: 42 additions & 0 deletions Block/Adminhtml/City/Edit/GenericButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Copyright © 2018 EaDesign by Eco Active S.R.L.
* See LICENSE for license details.
*/

namespace Eadesigndev\RomCity\Block\Adminhtml\City\Edit;

use Magento\Backend\Block\Widget\Context;

class GenericButton
{
/**
* @var Context
*/
protected $context;

public function __construct(Context $context)
{
$this->context = $context;
}

/**
* @return int|null
*/
public function getCityId(): ?int
{
$id = $this->context->getRequest()->getParam('entity_id');

return $id ? (int)$id : null;
}

/**
* @param string $route
* @param array $params
* @return string
*/
public function getUrl($route = '', $params = []): string
{
return $this->context->getUrlBuilder()->getUrl($route, $params);
}
}
37 changes: 37 additions & 0 deletions Block/Adminhtml/City/Edit/SaveButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Copyright © 2018 EaDesign by Eco Active S.R.L.
* See LICENSE for license details.
*/

namespace Eadesigndev\RomCity\Block\Adminhtml\City\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

class SaveButton extends GenericButton implements ButtonProviderInterface
{
/**
* @inheritdoc
*/
public function getButtonData()
{
return [
'label' => __('Save City'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => [
'buttonAdapter' => [
'actions' => [
[
'targetName' => 'xtea_romcity_form.xtea_romcity_form',
'actionName' => 'save',
'params' => [true]
]
]
]
]
],
'sort_order' => 90
];
}
}
35 changes: 35 additions & 0 deletions Block/Adminhtml/ConfigButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Copyright © 2018 EaDesign by Eco Active S.R.L.
* See LICENSE for license details.
*/

namespace Eadesigndev\RomCity\Block\Adminhtml;

use Eadesigndev\RomCity\Block\Adminhtml\City\Edit\GenericButton;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

class ConfigButton extends GenericButton implements ButtonProviderInterface
{
protected $_backendUrl;

public function __construct(
\Magento\Backend\Model\UrlInterface $backendUrl
) {

$this->_backendUrl = $backendUrl;
}

/**
* @inheritdoc
*/
public function getButtonData()
{
return [
'label' => __('Go to Import Cities'),
'on_click' => sprintf("location.href = '%s';", $this->_backendUrl->getUrl('admin/system_config/index')),
'class' => 'secondary',
'sort_order' => 10
];
}
}
176 changes: 176 additions & 0 deletions Block/Adminhtml/Order/Create/Billing/Address.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<?php

namespace Eadesigndev\RomCity\Block\Adminhtml\Order\Create\Billing;

use Magento\Framework\Pricing\PriceCurrencyInterface;
use Eadesigndev\RomCity\Api\RomCityRepositoryInterface;

class Address extends \Magento\Sales\Block\Adminhtml\Order\Create\Billing\Address
{
/** @var \Magento\Framework\Api\SearchCriteriaBuilder */
private $criteriaBuilder;

/** @var \Eadesigndev\RomCity\Api\RomCityRepositoryInterface */
private $cityRepository;

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,
RomCityRepositoryInterface $cityRepository,
array $data = []
){
parent::__construct(
$context,
$sessionQuote,
$orderCreate,
$priceCurrency,
$formFactory,
$dataObjectProcessor,
$directoryHelper,
$jsonEncoder,
$customerFormFactory,
$options,
$addressHelper,
$addressService,
$criteriaBuilder,
$filterBuilder,
$addressMapper,
$data
);

$this->cityRepository = $cityRepository;
$this->criteriaBuilder = $criteriaBuilder;

}

/**
* Prepare Form and add elements to form
*
* @return $this
*/
/*protected function _prepareForm()
{
parent::_prepareForm();

$formValues = $this->getFormValues();
$countryElement = $this->_form->getElement('country_id');
$regionIdElement = $this->_form->getElement('region_id');
$regionId = $regionIdElement->getValue();
$countryId = $countryElement->getValue();
$searchCriteria = $this->searchCriteriaBuilder
->addFilter('region_id', $regionId)
->create();

$cityValue = $formValues['city'];
$cityId = null;
$values = [__('Please select city')];
if ($regionId) {
$cities = $this->cityRepository->getList($searchCriteria)->getItems();
foreach($cities as $city) {
if ($city->getCity() === $cityValue) {
$cityId = $city->getCity();
}
$values[$city->getCity()] = $city->getCity();
}
}

$addressForm = $this->_customerFormFactory->create('customer_address', 'adminhtml_customer_address');
$cityAttribute = $addressForm->getAttribute('city');
if ($countryId == 'RO') {
$this->_form = $this->_form->removeField('city');
foreach($this->_form->getElements() as $fieldset){
$fieldset->removeField('city');
$fieldset->addField('city', 'select', [
'name' => 'order[billing_address]' . '[' . $cityAttribute->getAttributeCode() . ']',
'label' => __($cityAttribute->getStoreLabel()),
'class' => $this->getValidationClasses($cityAttribute),
'required' => $cityAttribute->isRequired(),
'values' => $values,
'value' => $cityId
], 'region');
}

}

return $this;
}*/

protected function _prepareForm()
{
parent::_prepareForm();

$formValues = (array)$this->getFormValues();

$countryElement = $this->_form->getElement('country_id');
$regionIdElement = $this->_form->getElement('region_id');

$regionId = $regionIdElement ? (int)$regionIdElement->getValue() : 0;
$countryId = $countryElement ? (string)$countryElement->getValue() : '';

// FIX 1: safe read
$cityValue = (string)($formValues['city'] ?? '');

$cityId = null;
//$values = [__('Please select city')];
$values = [['value' => '', 'label' => __('Please select city')]];

if ($regionId) {
// FIX 2: use the criteria builder that exists on the parent block
$searchCriteria = $this->criteriaBuilder
->addFilter('region_id', $regionId)
->create();

$cities = $this->cityRepository->getList($searchCriteria)->getItems();
foreach ($cities as $city) {
$cityName = (string)$city->getCity();

if ($cityName !== '') {
if ($cityName === $cityValue) {
$cityId = $cityName;
}
$values[$cityName] = $cityName;
}
}
}

$addressForm = $this->_customerFormFactory->create('customer_address', 'adminhtml_customer_address');
$cityAttribute = $addressForm->getAttribute('city');

if ($countryId === 'RO' && $cityAttribute) {
// remove city field from the main form + fieldsets (your existing logic)
$this->_form = $this->_form->removeField('city');
foreach ($this->_form->getElements() as $fieldset) {
$fieldset->removeField('city');
$fieldset->addField(
'city',
'select',
[
'name' => 'order[billing_address][' . $cityAttribute->getAttributeCode() . ']',
'label' => __($cityAttribute->getStoreLabel()),
'class' => $this->getValidationClasses($cityAttribute),
'required' => (bool)$cityAttribute->isRequired(),
'values' => $values,
'value' => $cityId
],
'region'
);
}
}

return $this;
}

}
Loading