cubecart / v6

CubeCart Version 6
https://cubecart.com
72 stars 59 forks source link

Storefront Link to Admin to Edit an Item #3480

Open bhsmither opened 6 months ago

bhsmither commented 6 months ago

Now with a hook in GUI->addBreadcrumb(), this can be done, but it would be nice to have this anyway.

Feature Request: This adds an icon after every crumb, which is a link to the edit page of that item.

Find in GUI-addBreadcrumb():
        if (!empty($name)) {
            $this->_breadcrumb[] = array(
                'url' => $GLOBALS['seo']->SEOable($href),
                'title' => ucfirst(strip_tags(str_replace('_', ' ', $name)))

Change to:
        preg_match('@\?_a\=(product|category|document)\&(amp;)?(product_id|prod_id|cat_id|doc_id)\=([\d]+)@',$href,$hrefmatch);
        switch ($hrefmatch[1] ?? false) {
            case 'product': $return = '/'.$GLOBALS['config']->get('config', 'adminFile').'?_g=products&node=index&action=edit&product_id='.$hrefmatch[4]; break;
            case 'category': $return = '/'.$GLOBALS['config']->get('config', 'adminFile').'?_g=categories&node=index&action=edit&cat_id='.$hrefmatch[4]; break;
            case 'document': $return = '/'.$GLOBALS['config']->get('config', 'adminFile').'?_g=documents&node=index&action=edit&doc_id='.$hrefmatch[4]; break;
            case false: $return = false;
        }
        if ($GLOBALS['session']->get('super_user', 'admin_data')) {
            $GLOBALS['smarty']->assign('HOMECRUMB'
            , '/'. $GLOBALS['config']->get('config', 'adminFile')
            . '?_g=documents&node=index&action=edit&doc_id='
            . $GLOBALS['db']->select('CubeCart_documents','doc_id','doc_home=1')[0]['doc_id']);
        }
        if (!empty($name)) {
            $this->_breadcrumb[] = array(
                'admin' => ($return && $GLOBALS['session']->get('super_user', 'admin_data') ? $return : false),
                'url' => $GLOBALS['seo']->SEOable($href),
                'title' => ucfirst(strip_tags(str_replace('_', ' ', $name)))

Find in Catalogue->displayProduct():
                $GLOBALS['gui']->addBreadcrumb($product['name'], currentPage());

Change to:
                $GLOBALS['gui']->addBreadcrumb($product['name'], '?_a=product&product_id='.$product['product_id']); // currentPage());

Find in CubeCart->loadPage():
                        $GLOBALS['gui']->addBreadcrumb($document['doc_name'], currentPage());

Change to:
                        $GLOBALS['gui']->addBreadcrumb($document['doc_name'], '?_a=document&doc_id='.$document['doc_id']); // currentPage());

Find in the Foundation template element.breadcrumb.php:
            <span class="show-for-medium-up" itemprop="name">{$LANG.common.home}</span>
         </a>

Change to:
            <span class="show-for-medium-up" itemprop="name">{$LANG.common.home}</span>
         </a>{if $HOMECRUMB}<a href="{$HOMECRUMB}" target="_blank"><svg class="icon"><use xlink:href="#icon-search"></use></svg></a>{/if}

Also find:
            <span itemprop="name">{$crumb.title}</span>
         </a>

Change to:
            <span itemprop="name">{$crumb.title}</span>
         </a>{if $crumb.admin}<a href="{$crumb.admin}" target="_blank"><svg class="icon"><use xlink:href="#icon-search"></use></svg></a>{/if}

Add these CSS rules somewhere:
a[target] {
  color: red;
  font-weight: bold; }
a[target]:hover {
  text-decoration: none; }

It would be better to use an 'edit' SVG graphic instead of the 'search' SVG graphic. But there isn't one.

abrookbanks commented 6 months ago

I like this but I personally don't like it being inline in the page. Maybe like the (store offline) notification there could be a navigation bar at the top instead to edit the current page. Or maybe three choices.

bhsmither commented 6 months ago

A single link to "edit the current page". I can work with that - having to view the actual category page to get at the link to edit that category.