Oro PriceList business unit ownership - orocommerce

I have a requirement to configure ownership for priceList entities. To approach this I created a migration to add the required fields:
$this->extendExtension->addManyToOneRelation(
$schema,
$table,
'organization',
$organizationTable,
'name',
[
'extend' => [
'is_extend' => true,
'owner' => ExtendScope::OWNER_SYSTEM,
'without_default' => true,
]
]);
$this->extendExtension->addManyToOneRelation(
$schema,
$table,
'owner',
$businessTable,
'name',
[
'extend' => [
'is_extend' => true,
'owner' => ExtendScope::OWNER_SYSTEM,
'without_default' => true,
]
]
);
Then updated entity configuration information with:
$params = [
"owner_type" => "BUSINESS_UNIT",
"owner_field_name" => "owner",
"owner_column_name" => "owner_id",
"organization_field_name" => "organization",
"organization_column_name" => "organization_id"
];
foreach($params as $code => $value) {
$queries->addPostQuery(
new UpdateEntityConfigEntityValueQuery(
PriceList::class,
'ownership',
$code,
$value
)
);
}
Migration processed without issues but for the data grid on the priceList index page error occurred.
An exception occurred while executing 'SELECT count(o0_.id) AS sclr_0 FROM oro_price_list o0_ WHERE o0_. = 1'
It looks like the data grid couldn't reach the organization name to handle the pagination query. Data grid unmodified grid from ORO 4.1 EE

Everything works fine if ownership configuration updated via SetOwnershipTypeQuery intead of UpdateEntityConfigEntityValueQuery
$queries->addQuery(
new SetOwnershipTypeQuery(
PriceList::class,
[
'owner_type' => 'BUSINESS_UNIT',
'owner_field_name' => 'owner',
'owner_column_name' => 'owner_id',
'organization_field_name' => 'organization',
'organization_column_name' => 'organization_id'
]
)
);

Related

How to remove validation lastname from prestashop 1.7.8.3 backoffice

I have a question how to remove validation from LastName inside client address edit. I need to allow numbers inside this field.
I found here thread Prestashop : Remove Lastname Field Rules Validation From B.O, but this solution is not working.
Finally, I have caught the issue. You are editing in admin panel and I was sharing code for front end. Please try below steps for admin:
Step 1 - file classes/Address.php
'lastname' => ['type' => self::TYPE_STRING, 'validate' => 'isAnything', 'required' => true, 'size' => 255],
Change this to isAnything
Step 2 - src\PrestaShopBundle\Form\Admin\Sell\Address/CustomerAddressType.php
Change your code to below code:
line 209: add('last_name', TextType::class, [
'label' => $this->trans('Last name', 'Admin.Global'),
'help' => $genericInvalidCharsMessage,
'required' => true,
'constraints' => [
new NotBlank([
'message' => $this->trans(
'This field cannot be empty.', 'Admin.Notifications.Error'
),
]),
new CleanHtml(),
new TypedRegex([
'type' => TypedRegex::TYPE_GENERIC_NAME,
]),
new Length([
'max' => AddressConstraint::MAX_LAST_NAME_LENGTH,
'maxMessage' => $this->trans(
'This field cannot be longer than %limit% characters',
'Admin.Notifications.Error',
['%limit%' => AddressConstraint::MAX_LAST_NAME_LENGTH]
),
]),
],
])
Now, you are ready to go and check.
Go to the file classes/Address.php file:
'lastname' =>array('type' => self::TYPE_STRING, 'validate' => 'isCustomerName', 'required' => true, 'size' => 32),
to :
'lastname' =>array('type' => self::TYPE_STRING, 'validate' => 'isAnything', 'required' => true, 'size' => 32),
validate to isAnything.
I think you were modifying in customer class. Please try with Address.php.
Thanks for sharing the files.
I have resolved the case. You need to modify the classes/form/CustomerAddressForm.php
line 229
$isValid &= $this->validateField('lastname', 'isName', $this->translator->trans(
'Invalid name',
[],
'Shop.Forms.Errors'
));
Change to:
$isValid &= $this->validateField('lastname', 'isAnything', $this->translator->trans(
'Invalid name',
[],
'Shop.Forms.Errors'
));
I want to do this good with override. I have an issue with override this class. I have created module to override but it is not working. There is a way to override this without editing core files?
services:
_defaults:
public: true
form.type.customer_address:
class: 'Playdev\PrestaShopBundle\Form\Admin\Sell\Address\CustomCustomerAddressType'
public: true
arguments:
- '#prestashop.adapter.form.choice_provider.country_state_by_id'
- '#=service("prestashop.adapter.legacy.context").getContext().country.id'
- '#router'
tags:
- { name: form.type }
https://ibb.co/VVjnJYr
There is a file class override:
\modules\pd_overridemodule\src\PrestaShopBundle\Form\Admin\Sell\Address\CustomCustomerAddressType.php
https://ibb.co/7QPHrqx
And I have an error when I am inside Edit Address Form Backoffice
Type error: Too few arguments to function PrestaShopBundle\Form\Admin\Sell\Address\CustomerAddressType::__construct(), 0 passed in C:\laragon\www\prestabiolab\vendor\symfony\symfony\src\Symfony\Component\Form\FormRegistry.php on line 92 and exactly 5 expected
[Symfony\Component\Debug\Exception\FatalThrowableError 0]
https://ibb.co/YfwhtKq
I have found a solution
Need to create module and call hookactionCustomerAddressFormBuilderModifier.
public function hookactionCustomerAddressFormBuilderModifier(array $params)
{
/** #var $formBuilder \Symfony\Component\Form */
$formBuilder = $params['form_builder'];
// remove lastname field
$formBuilder->remove('last_name');
// get all fields without removed
$allFields = $formBuilder->all();
// remove all fields
foreach ($allFields as $inputField => $input) {
$formBuilder->remove($inputField);
}
foreach ($allFields as $inputField => $input) {
// normally add fields
$formBuilder->add($input);
// add fields after firstname
if ($inputField == 'first_name') {
$formBuilder->add('last_name', TextType::class, [
'label' => $this->trans('Last name', [], 'Admin.Global'),
'help' => $this->trans(
'Invalid characters:',
[],
'Admin.Notifications.Info'
) . ' ' . TypedRegexValidator::GENERIC_NAME_CHARS,
'required' => true,
'constraints' => [
new NotBlank([
'message' => $this->trans(
'This field cannot be empty.', [], 'Admin.Notifications.Error'
),
]),
new CleanHtml(),
new TypedRegex([
'type' => TypedRegex::TYPE_GENERIC_NAME,
]),
new Length([
'max' => AddressConstraint::MAX_LAST_NAME_LENGTH,
'maxMessage' => $this->trans(
'This field cannot be longer than %limit% characters',
['%limit%' => AddressConstraint::MAX_LAST_NAME_LENGTH],
'Admin.Notifications.Error',
),
]),
],
]);
}
}
}
Now I think it works okey with override :)

In Laravel Backpack need to list users with specific role

please check the details below, where I have a Organizations module. Where I can create a organization with a owner with role "organization".
The third input is a dropdown where we need to select the user with role "organization"
protected function addOrganizationFields(){
$this->crud->addFields([
[
'name' => 'name',
'label' => __('Organization Name'),
'type' => 'text',
],
[
'name' => 'billing_information',
'label' => __('Billing Information'),
'type' => 'textarea',
],
[
'name' => 'owner_id',
'label' => __('Organization Owner'),
'type' => 'select2',
'entity' => 'owners_list',
'attribute' => 'name',
'model' => "App\User",
]
]);
}
In the organization module I wrote this code.
public function owners_list(){
return User::whereHas('roles', function($q){
$q->where('name', 'member');
})->get();
}
in the Organization model relationship I wrote this.
But showing the list of all users in the drop-down.
Can anybody please tel me what is to be done.
You can eliminate options from your select2 field using the “options” attribute mentioned in the docs - https://backpackforlaravel.com/docs/4.1/crud-fields
[
'name' => 'owner_id',
'label' => __('Organization Owner'),
'type' => 'select2',
'entity' => 'owners_list',
'attribute' => 'name',
'model' => "App\User",
// add something like this
'options' => (function ($query) {
return $query->whereHas('roles', function($q){
$q->where('name', 'member');
})->get();
}), // force the related options to be a custom query, instead of all(); you can use this to filter the results show in the select
]

Laravel 5.8 LDAP Authentication not working - LdapRecord Package

I'm trying to implements an LDAP authentication in an application for my company. I'm using Laravel 5.8 and the LdapRecord package
I have succeed to connect the application with the LDAP server test see Successfully connected and my to authenticate with openldap to online server its also Successfully. but when i want to do the authentication with active directory to my app it not working , Why who can help me?
Here is my code :
The .env
LDAP_LOGGING=true
LDAP_CONNECTION=default
LDAP_HOST=server
LDAP_PORT=389
LDAP_BASE_DN="dc=mydomain,dc=local"
LDAP_TIMEOUT=5
LDAP_SSL=false
LDAP_TLS=false
The ldap.php
return [
'default' => env('LDAP_CONNECTION', 'default'),
'connections' => [
'default' => [
'hosts' => [env('LDAP_HOST', 'server')],
'username' => env('LDAP_USERNAME', ''),
'password' => env('LDAP_PASSWORD', ''),
'port' => env('LDAP_PORT', 389),
'base_dn' => env('LDAP_BASE_DN', 'dc=mydomain,dc=local'),
'timeout' => env('LDAP_TIMEOUT', 5),
'use_ssl' => env('LDAP_SSL', false),
'use_tls' => env('LDAP_TLS', false),
],
],
'logging' => env('LDAP_LOGGING', true),
'cache' => [
'enabled' => env('LDAP_CACHE', false),
'driver' => env('CACHE_DRIVER', 'file'),
],
];
The auth.php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'ldap',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
],
'providers' => [
'users' => [
'driver' => 'eloquent' ,
'model' => App \ User :: class,
],
'ldap' => [
'driver' => 'ldap',
'model' => LdapRecord\Models\ActiveDirectory\User::class,
// 'model' => LdapRecord\Models\OpenLDAP\User::class,
'database' => [
'model' => App\User::class,
'sync_passwords' => false,
'sync_attributes' => [
'name' => 'cn',
'email' => 'mail',
],
],
]
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
],
'password_timeout' => 10800,
];
The user.php model
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use LdapRecord\Laravel\Auth\LdapAuthenticatable;
use LdapRecord\Laravel\Auth\AuthenticatesWithLdap;
class User extends Authenticatable implements LdapAuthenticatable
{
use Notifiable, AuthenticatesWithLdap, HasLdapUser ;
protected $fillable = [
'name',
'email',
'password',
];
protected $hidden = [
'password', 'remember_token' ,
];
protected $casts = [
'email_verified_at' => 'datetime',
];
}
The LoginController
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
protected function credentials(Request $request)
{
return [
'uid' => $request->get('username'),
'password' => $request->get('password'),
];
}
public function username()
{
return 'username';
}
}
Is there anyone who has already used this package and can help me on my code ? thank you in advance :)

install.php is not being run during installation

My install.php is not being run during installation.I checked everywhere.To be sure,I ran the code in install.php elsewhere and it worked well. But during installation only the install.php is being skipped somehow.My module name is Hotelreservation, hence the code in install.php is as below. Why is there no error display during installation ?
<?php
class Hotelreservation_Installer extends Engine_Package_Installer_Module
{
public function onInstall()
{
$this->_hotelroomsBrowsePage();
parent::onInstall();
}
protected function _hotelroomsBrowsePage()
{
$db = $this->getDb();
// profile page
$page_id = $db->select()
->from('engine4_core_pages', 'page_id')
->where('name = ?', 'hotelreservation_index_browse')
->limit(1)
->query()
->fetchColumn();
if (!$page_id) {
// Insert page
$db->insert('engine4_core_pages', array(
'name' => 'hotelreservation_index_browse',
'displayname' => 'HotelRooms Browse Page',
'title' => 'Browse Rooms',
'description' => 'this page displays rooms',
'custom' => 0,
));
$page_id = $db->lastInsertId();
// Insert main
$db->insert('engine4_core_content', array(
'type' => 'container',
'name' => 'main',
'page_id' => $page_id,
));
$main_id = $db->lastInsertId();
// Insert middle
$db->insert('engine4_core_content', array(
'type' => 'container',
'name' => 'middle',
'page_id' => $page_id,
'parent_content_id' => $main_id,
'order' => 2,
));
$middle_id = $db->lastInsertId();
// Insert hotelreservation.browse-menu
$db->insert('engine4_core_content', array(
'type' => 'widget',
'name' => 'hotelreservation.browse-menu',
'page_id' => $page_id,
'parent_content_id' => $middle_id,
'order' => 1,
));
// Insert core content
$db->insert('engine4_core_content', array(
'type' => 'widget',
'name' => 'core.content',
'page_id' => $page_id,
'parent_content_id' => $middle_id,
'order' => 2,
));
// Insert left
$db->insert('engine4_core_content', array(
'type' => 'container',
'name' => 'left',
'page_id' => $page_id,
'parent_content_id' => $main_id,
'order' => 3,
));
$left_id = $db->lastInsertId();
}
return $this;
}
}// end class
Did you add info to mainfest file like this in packages array
'callback' => array(
'path' => 'Your path to php file',
'class' => 'Hotelreservation_Installer',
),
I agree with Arif. Check the file manifest.php inside of //settings:
(info of module Album)
'callback' => array(
'path' => 'application/modules/Album/settings/install.php',
'class' => 'Album_Installer',
),
I had this same issue and got it to work.
It turns out that the installer looks in application/packages/module-yourmodule-x.x.x.json first. around line 35 you'll find:
"callback": {
"path": null,
"class": "Engine_Package_Installer_Module",
"priority": 100
},
change that to:
"callback": {
"path": "application/modules/Yourmodule/settings/install.php",
"class": "Yourmodule_Installer",
"priority": 100
},
now, when you run the installer, your install.php will be called.

Zend Framework 2 + Doctrine 2 and Authentication Service

It was successfully working before I changed the authentication service name from 'orm_default' to 'admin', and it is necessary since I have more modules which uses more authentication services.
The problem is I'm getting the following error:
Fatal error: Uncaught exception 'Zend\ServiceManager\Exception\ServiceNotFoundException' with message 'Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for doctrine.authenticationservice.admin'
My module.config.php
'doctrine' => array
(
'driver' => array
(
__NAMESPACE__ . '_driver' => array
(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
),
'orm_default' => array
(
'drivers' => array
(
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
),
)
),
'authentication' => array
(
'admin' => array
(
'object_manager' => 'Doctrine\ORM\EntityManager',
'identity_class' => __NAMESPACE__ . '\Entity\User',
'identity_property' => 'email',
'credential_property' => 'password',
'credentialCallable' => __NAMESPACE__ . '\Model\User::hashPassword'
),
),
),
My Module.php
public function getServiceConfig()
{
return array
(
'factories' => array
(
'Admin\Auth' => function($sm)
{
return $sm->get('doctrine.authenticationservice.admin');
},
'Admin\Form\Auth\Login' => function($sm)
{
return new Form\Auth\Login();
},
),
);
}
It was confirmed as a bug: https://github.com/doctrine/DoctrineORMModule/issues/291
According to a comment in a doctrine module source file it plans to be fixed in 1.0. In this meantime you can it in your any module.config.php file of your application like this:
'authentication' =>
[
'application' =>
[
'object_manager' => 'Doctrine\ORM\EntityManager',
'identity_class' => 'Application\Entity\Customer',
'identity_property' => 'email',
'credential_property' => 'password',
'credentialCallable' => 'Application\Entity\Customer::hashPassword'
],
],
'authenticationadapter' =>
[
'application' => true,
],
'authenticationstorage' =>
[
'application' => true,
],
'authenticationservice' =>
[
'application' => true,
]
I had exactly same problem when i was working on my project. After working my *ss out for two nights, i solved the problem by simply re-installing the doctrine-orm-module after reading https://github.com/doctrine/DoctrineORMModule, "Registered Service names" section. This simply means doctrine orm module wasn't properly installed, or wasn't installed.