Post by prototype0104 » Thu Jan 30, 2020 8:09 pm

Hello! Sorry for this stupid post but I'm newbie in OpenCart and I want to know your advices. I want to create category chain by select options.
I did it on php but after that I discovered that I need to create a new cart and order system.. Now I created template and controller files using category model..
Now just thinking about what's next? Some advices?
Thank you.

Attachments

opencart.png

opencart.png (1.67 KiB) Viewed 211 times


New member
Online

Posts

Joined
Sun Mar 24, 2019 6:08 pm

Post by paulfeakins » Thu Jan 30, 2020 8:50 pm

prototype0104 wrote:
Thu Jan 30, 2020 8:09 pm
I want to create category chain by select options.
I think I can imagine what you're trying to create but it's quite involved, what level of PHP do you have?

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Expert Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by prototype0104 » Thu Jan 30, 2020 9:11 pm

I did it in php but on external page.. I want to implement it in OpenCart to use Opencart functions.

New member
Online

Posts

Joined
Sun Mar 24, 2019 6:08 pm

Post by straightlight » Thu Jan 30, 2020 9:12 pm

Using a category search filtering extension from the Marketplace may also be more ideal than looping the dropdown on the custom theme you might be using. This way, you maintain the dimensional size of your layout.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member
Online

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Thu Jan 30, 2020 9:12 pm

prototype0104 wrote:
Thu Jan 30, 2020 9:11 pm
I did it in php but on external page.. I want to implement it in OpenCart to use Opencart functions.
Any codes / attached files you could provide?

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member
Online

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by prototype0104 » Thu Jan 30, 2020 9:37 pm

Code: Select all

<html>
<head>
<script src="js/jquery.min.js"></script>

<script>
$(document).ready(function(){
    $('#category').on('change', function(){
        var categoryID = $(this).val();
        if(categoryID){
            $.ajax({
                type:'POST',
                url:'ajaxData.php',
                data:'category_id='+categoryID,
                success:function(html){
                    $('#child').html(html);
                    $('#child2').html('<option value="">Alege vehiculul</option>');
				
					
                }
            }); 
        }else{
            $('#child').html('<option value="">Alege vehiculul inainte</option>');
            $('#child2').html('<option value="">Alege modelul inainte</option>'); 
        }
    });
    
    $('#child').on('change', function(){
        var childID = $(this).val();
        if(childID){
            $.ajax({
                type:'POST',
                url:'ajaxData.php',
                data:'category_id1='+childID,
                success:function(html){
                    $('#child2').html(html);
                }
            }); 
        }else{
            $('#child2').html('<option value="">Alege modelul inainte</option>'); 
        }
    });
});
</script>

</head>
<body>
<?php 
    // Include the database config file 
    include_once 'dbConfig.php'; 
     
    // Fetch all the category data 
    $query = "SELECT * FROM oc_category_description WHERE category_id IN (SELECT category_id from oc_category WHERE parent_id = 77) AND language_id=1"; 
    $result = $db->query($query); 
?>

<!-- category dropdown -->
<select id="category">
    <option value="">Alege vehiculul</option>
    <?php 
    if($result->num_rows > 0){ 
        while($row = $result->fetch_assoc()){  
            echo '<option value="'.$row['category_id'].'">'.$row['name'].'</option>'; 
        } 
    }else{ 
        echo '<option value="">category not available</option>'; 
    } 
    ?>
</select>
<!-- child dropdown -->
<select id="child">
    <option value="">Alege vehiculul inainte</option>
</select>

<!-- child2 dropdown -->
<select id="child2">
    <option value="">Alege modelul inainte</option>
</select>
</body>
</html>

Code: Select all

<?php 
// Include the database config file 
include_once 'dbConfig.php'; 
 
if(!empty($_POST["category_id"])){ 
    // Fetch state data based on the specific country =
    $query = "SELECT * FROM oc_category_description WHERE category_id IN (SELECT category_id from oc_category WHERE parent_id = ".$_POST['category_id'].") AND language_id=1"; 
    $result = $db->query($query); 
     
    // Generate HTML of state options list 
    if($result->num_rows > 0){ 
        echo '<option value="">Alege modelul</option>'; 
        while($row = $result->fetch_assoc()){  
            echo '<option value="'.$row['category_id'].'">'.$row['name'].'</option>'; 
        } 
    }else{ 
        echo '<option value="">State not available</option>';
    } 
}elseif(!empty($_POST["category_id1"])){ 
    // Fetch city data based on the specific state 
    $query = "SELECT * FROM oc_category_description WHERE category_id IN (SELECT category_id from oc_category WHERE parent_id = ".$_POST['category_id1'].") AND language_id=1 ORDER BY name ASC"; 
    $result = $db->query($query); 
     
    // Generate HTML of city options list 
    if($result->num_rows > 0){ 
        echo '<option value="">Alege diagrama</option>'; 
        while($row = $result->fetch_assoc()){  
            echo '<option value="'.$row['category_id'].'">'.$row['name'].'</option>'; 
        } 
    }else{ 
        echo '<option value="">City not available</option>'; 
    } 
} 
?>

New member
Online

Posts

Joined
Sun Mar 24, 2019 6:08 pm

Post by straightlight » Thu Jan 30, 2020 10:38 pm

It rather looks like you're trying to pull the category IDs rather than the product IDs. The cart.add method from common.js file only pulls the product IDs with their quantities. However, you could rely on the country and zone feature from OC in order to accomplish the task via JSON and HTML outputs. This should be quite easy to do. As an alternative, you could create a new service request in the Commercial Support section of the forum or send me a PM to get this done as a custom job.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member
Online

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 39 guests