Sonata ecommerce custom product admin - symfony

I am using sonata e commerce bundle and I have added a couple of products. I can get them list and displayed in the admin section but when I try to create a new product I only see the basic field that all the products have.
Is there any way to create an Admin class that will allow me to see the extra fields for each kind of product class?

I finally figured out how to do this looking into the sonata sandbox example.
To add the custom fields to the product in the admin I have to override the WineProductProvider class and add the following method just like an admin class.
/**
* {#inheritDoc}
*/
public function buildEditForm(FormMapper $formMapper, $isVariation = false)
{
parent::buildEditForm($formMapper, $isVariation);
$formMapper
->with('Bottle details')
->add('origin','text')
->add('year','integer')
->add('grapes','text')
->add('closure','text')
->add('food','text')
->add('style','text')
->add('size','integer');
$formMapper->end();
}
And thats it. Hope it helps someone else.

Related

disable field from editing but not from creating view sonata bundle

I have an application using Sonata Admin for the back-office.
If I use disabled => true it will remove the field from being editable in edit and create view.
Is there a way to disable it only on the edit screen?
I think you should try the following code to get the subject of the Admin and check if subject exist then disable the field. Update your configureFormFields method inside admin.
/** #var YourClass $subject */
$subject = $this->getSubject();
if($subject) {
// DISABLE THE FIELD
} else {
// ENABLE THE FIELD
}

Show how many pages in Knp pagination

I install and override template in knp pagination. But I need show how many pages are. For example: 1 page of 10, 5 page of 10 e.t.c?I read offical documentation but I dosen't find ansver.
You can override this template : https://github.com/KnpLabs/KnpPaginatorBundle/blob/master/Resources/views/Pagination/sliding.html.twig
Just use the variable pageCount to display the amount of pages where you want.
To do so, create a sliding.html.twig file in your app/Resources/KnpPaginatorBundle/views/Pagination folder.
I can see at the doc this abstract pagination class : https://github.com/KnpLabs/knp-components/blob/master/src/Knp/Component/Pager/Pagination/AbstractPagination.php
This class has a method on line 113:
/**
* Get total item number available
*
* #return integer
*/
public function getTotalItemCount()
{
return $this->totalCount;
}

How to add PunkAveFileUploaderBundle to sonata admin bundle

Well...Everything is in the title and here I am because the documentation about this topic doesn't exist really..So I hope some ninja developers will be able to give me some tips...
I'm working on my personal portfolio (Symfony 2.3) and I have a problem since a couple of week. I used sonata admin bundle to create my admin panel and have a lot of troubles to fix the different file upload in my admin. For that I was wondering to use the PunkAveFileUploaderBundle. But honestly I have no idea of how to implement it properly. I think I have to edit some sonata admin files but here again...which ones? I'm reading the files and have already a good idea of which ones to tweak but not sure at all.. By reading and following the documentation of sonata admin (sonata doc) I never had success.. Don't know why I'm actually following it step by step..
Well if anyone of you has an idea of how to implement the PunkAveFileUpload bundle with sonata admin bundle, let me know your tips or even better, a small example...
PS: links to the documentation are not needed, thank you.
May be you can read this post about getting Gedmo Uploadable working with Sonata Admin
I think you'll have to pass the punk_ave.file_uploader service in your admin class:
acme.admin.demo:
class: Acme\DemoBundle\Admin\DemoAdmin
arguments: [~, Acme\DemoBundle\Entity\Demo, SonataAdminBundle:CRUD, #punk_ave.file_uploader]
tags:
- {name: sonata.admin, manager_type: orm, group: demo, label: demo}
calls:
- [ setTranslationDomain, [SonataAdminBundle]]
ANd change your DemoAdmin class to manage uploads:
class DemoAdmin extends Admin
{
/**
* File uploader
*/
private $fileUploader = null;
/**
* Constructor
*/
public function __construct($code, $class, $baseControllerName, $fileUploader = null)
{
parent::__construct($code, $class, $baseControllerName);
$this->fileUploader = $fileUploader;
}
// ...
public function prePersist($object)
{
$this->manageUploads($object);
}
public function preUpdate($object)
{
$this->manageUploads($object);
}
/**
* Mannger uploads
* #param Demo $object
*/
private function manageUploads($object)
{
if ($object->getId()->getFile()) {
$this->fileUploader->syncFiles(...);
}
}
}
I really don't know if this will work, but that's the way I'll try to make it works...

disable action in sonata admin bundle CRUD

IS there a simple way to disable some CRUD actions for given admin class? E.g. I just want a list of users added via front-end without the option to manually add them.
In your admin class :
protected function configureRoutes(RouteCollection $collection)
{
// to remove a single route
$collection->remove('delete');
// OR remove all route except named ones
$collection->clearExcept(array('list', 'show'));
}
Also use routeCollection at top of admin class
use Sonata\AdminBundle\Route\RouteCollection;
Docs : http://sonata-project.org/bundles/admin/master/doc/reference/routing.html#removing-a-single-route

remove "profile" admin-menu from administrative panel

I am using WordPress, and I want to remove "profile" menu-option completely
Any one is having idea how can I achieve this?
Thanks
For the sake of completeness, here's how to do it programmatically...
// Run the function on admin_init
add_action('admin_init', 'remove_profile_menu');
// Removal function
function remove_profile_menu() {
global $wp_roles;
// Remove the menu. Syntax is `remove_submenu_page($menu_slug, $submenu_slug)`
remove_submenu_page('users.php', 'profile.php');
/* Remove the capability altogether. Syntax is `remove_cap($role, $capability)`
* 'Read' is the only capability subscriber has by default, and allows access
* to the Dashboard and Profile page. You can also remove from a specific user
* like this:
* $user = new WP_User(null, $username);
* $user->remove_cap($capability);
*/
$wp_roles->remove_cap('subscriber', 'read');
}
I know this is late but I just stumbled on this and thought I would add to it. That does remove the sub-menu profile menu item but does not remove the menu profile item. For someone like me who has created a completely custom profile page, I don't want my users to access the profile.php page at all. So this code will work for that:
function remove_profile_menu() {
remove_submenu_page('users.php', 'profile.php');
remove_menu_page('profile.php');
}
add_action('admin_menu', 'remove_profile_menu');
And if you only want to do this for certain capabilities....use this code:
function remove_profile_menu() {
// Only the Admin can see the profile menu
if(!current_user_can('update_core')) {
remove_submenu_page('users.php', 'profile.php');
remove_menu_page('profile.php');
}
}
add_action('admin_menu', 'remove_profile_menu');
You can use the current_user_can() function to determine who you want to see the menu items.
Profiless plugin does that on the subscriber-level.
If you wish to do that for other groups, you should probably use it in combination with Capability manager plugin.

Resources