lat9 / options_stock_support

Products' Options' Stock Manager: Support Thread
0 stars 3 forks source link

Quick access to POSM product #60

Open zenexpert opened 1 month ago

zenexpert commented 1 month ago

Looking at v6.0.0 in ZC 2.1.0alpha If category/product structure is simple, navigating to a product in Catalog->Manage Options' Stock is relatively straight-forward, but will be a nightmare with complex structures. At first, I was thinking of a search field on the products_options_stock page, but perhaps an even simpler solution would be adding a button on category_product_listing. It could go either after the Attributes Controlled link or at the end after Meta Tags, irrelevant.

Seeing that products_options_stock page doesn't allow direct access using $pID unless you previously selected a category to work in. So, I modified line 333 to this:

if (isset($_GET['category_id'])) {
    $current_category_id = (int)$_GET['category_id'];
} elseif (isset($_SESSION['posm_category_id']) && $pID == 0) {
    $current_category_id = (int)$_SESSION['posm_category_id'];
} else {
    // Allow direct access to a product if we have $pID
    if($pID != 0) {
        $sql = "SELECT master_categories_id FROM ".TABLE_PRODUCTS." WHERE products_id = $pID";
        $sql = $db->Execute($sql);
        $current_category_id = $sql->fields['master_categories_id'];
    } else { // no product requested, use default initial page
        $current_category_id = -1;  //-"Please select" used, if not previously set.
    }
}

Do you see any issues with this or maybe foresee any problems caused by such approach?

lat9 commented 1 month ago

I'm not sure which module you've modified, but there's a direct list from the categories/products listing page (the little blue button) for products that are already stock-managed:

image

When viewing a product with existing attributes on the Attributes Controller page, there's an addition to the "Additional Actions" dropdown that also enables the options-stock manager link to that product:

image

I don't know if that helps. If not, a little more information regarding what you're trying to do would help.

zenexpert commented 1 month ago

Yeah, the blue button works great for products that are already stock-managed. I must admit I didn't realize there was a link in the Additional Actions menu, it's kinda hidden and easy to miss. TBH, I really didn't like that menu since it was introduced - I prefer buttons in clear sight instead of actions hidden in menus...

But, you've just answered my question and I realized the stupid oversight... I wasn't thinking of a direct link with both products_id AND category_id. If you navigate to a product, the URL only has products_id (for $_GET parameter) so it got me off track. If we create a button with both pID and category_id, it works like a charm. So... Editing category_product_listing.php on line 1038 gets me what I was asking about:

<?php if (zen_has_product_attributes($product['products_id'], false)) { ?>
    <a href="<?= zen_href_link(FILENAME_CATEGORY_PRODUCT_LISTING, 'cPath=' . $cPath . '&pID=' . $product['products_id'] . '&action=attribute_features' . (isset($_GET['page']) ? '&page=' . $_GET['page'] : '')) ?>" class="btn btn-sm btn-default btn-attributes-on" role="button" title="<?= BOX_CATALOG_CATEGORIES_ATTRIBUTES_CONTROLLER ?>"><strong>A</strong></a>
    <?php // add direct link to POSM
    if(defined('TABLE_PRODUCTS_OPTIONS_STOCK') && $sniffer->table_exists(TABLE_PRODUCTS_OPTIONS_STOCK)) { ?>
        <a href="<?= zen_href_link(FILENAME_PRODUCTS_OPTIONS_STOCK, '&pID=' . $product['products_id'] . '&category_id=' . $current_category_id); ?>" class="btn btn-sm btn-default btn-attributes-posm" role="button" title="<?= BOX_CATALOG_PRODUCTS_OPTIONS_STOCK ?>"><strong>O<sup>SM</sup></strong></a>
     <?php
     }
     // end link to POSM
    ?>
<?php } else { ?>

Probably no need for the sniffer, but... End result: 2024-09-27_170202

lat9 commented 1 month ago

Hmm, looks like category_product_listing.php could use a notifier (for the current zc210 repo) after line 1069:

https://github.com/zencart/zencart/blob/1407a64b9ba86866d6e25a29af2a83aa2e7a636d/admin/category_product_listing.php#L1059-L1072

Perhaps something like

$extra_actions = '';
$zco_notifier->notify('NOTIFY_ADMIN_PROD_LISTING_ADD_ACTION_ICONS', ['product' => $product, 'current_category_id'] => $current_category_id], $extra_actions);
echo $extra_actions;

Granted, that will put the icon(s) after the meta tags' one, but it'll get the job done. Let me know if that works and I'll submit a PR for the base to get that added to zc210.

zenexpert commented 1 month ago

Yeah, I was looking for a notifier, but couldn't find anything suitable. But, given that POSM is now included in the ZC package (and optionally installed), I think I'd keep the modification above to keep things simple, plus the button is exactly where it makes most sense. It's only the new button's CSS that would need to be added in the stylesheet.css as well. But the notifier is absolutely welcome as there might be other buttons to add. Maybe just add cPath as well so you don't have to rebuild it in the notifier when/if needed? :) Up to you, of course.

lat9 commented 1 month ago

Yeah, I was looking for a notifier, but couldn't find anything suitable. But, given that POSM is now included in the ZC package (and optionally installed), I think I'd keep the modification above to keep things simple, plus the button is exactly where it makes most sense. It's only the new button's CSS that would need to be added in the stylesheet.css as well. But the notifier is absolutely welcome as there might be other buttons to add. Maybe just add cPath as well so you don't have to rebuild it in the notifier when/if needed? :) Up to you, of course.

Sounds like a plan. I'll add a 'cPath' element to that notification's array parameter.

lat9 commented 1 month ago

Note that the notification's slightly different than posted here. $product isn't present when displaying a category in the listing and added $category for similar handling for category elements.