oc-shopaholic / oc-shopaholic-plugin

🛍️ No. 1 e-commerce platform for October CMS
https://shopaholic.one
GNU General Public License v3.0
425 stars 52 forks source link

Can not fork any of the components. #300

Open qroft opened 4 years ago

qroft commented 4 years ago

Hi everyone. as soon as i want to fork a Shopaholic component, i get this error: This component does not have a 'default' partial

As i first thought that this was a OctoberCMS problem, i opened this issue on their Github page: https://github.com/octobercms/october/issues/5142

Let me quote 4nik3t from that post: "It happens when the components do not have any template files (i.e without default.htm)"

Can you tell me where to set up said template file so that Shopaholic will recognize it? Thanks and greetings!

kharanenka commented 4 years ago

Hi! Components don't have templates, because each project has its own unique design and html structure. Logic of blocks may be similar, but with few differences. Therefore, so that developers don't have to freeze plugins, fitting logic to project, we provide flexible classes for rendering data in template. See more information here

qroft commented 4 years ago

Absolutley correct and sorry from my side! I have just read that a few minutes ago in the Documentation. One idea though for "scriptkiddies" like me: maybe have a step-by-step tutorial on how to start your own theme.

I found on YouTube a couple of videos but they were all in russian. By what i could "visually understand" they are perfect for newbies.

What i did now: i installed the Bootstrap theme you offer for free and will now copy it and try to figure out how to adapt it to my needs.

Please correct me if i am wrong but maybe this will help noobs like me to understand the whole structure better: Shopaholic can be considered like a "headless" ecommerce. Is this correct?

Thanks for your time and greetings!

LukeTowers commented 4 years ago

@kharanenka If you don't want to have a default.htm file because you're concerned that people would use it without overriding it and then you might break their sites in the future by changing it, I would say that you shouldn't, because once you have one written as the default example, then there really shouldn't be anything about it that would change in a breaking way without also having required a breaking change to the Component class itself. It's always best practice to include the default.htm file as an example of how your component should be rendered.

If you absolutely don't want to do that, then you can still support the "fork component" use case by doing something like this:

\Cms\Controllers\Index::extend(function ($controller) {
    $controller->bindEvent('ajax.beforeRunHandler', function ($handler) {
        if ($handler === 'onExpandMarkupToken') {
             // Replicate code from https://github.com/octobercms/october/blob/develop/modules/cms/controllers/Index.php#L376-L415 here
            // MAKE SURE TO CHECK THE REQUESTED COMPONENT AND VERIFY THAT IT IS ONE OF YOUR COMPONENTS ONLY
            // Replace loading of 'default' partial with loading 'example' partial instead
       }
    });
});