Welcome Guest, Not a member yet? Register   Sign In
Shopping Cart
#1

http://localhost/ShoppingCart/

Shopping Cart


Fatal error: Call to undefined function form_open() in C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\ShoppingCart\application\views\welcome_message.php on line 70
A PHP Error was encountered
Severity: Error
Message: Call to undefined function form_open()
Filename: views/welcome_message.php
Line Number: 70
Backtrace:


I already input shopping cart codes into the following messages:

views/welcome_message.php

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Welcome to CodeIgniter</title>

    <style type="text/css">

    ::selection { background-color: #E13300; color: white; }
    ::-moz-selection { background-color: #E13300; color: white; }

    body {
        background-color: #fff;
        margin: 40px;
        font: 13px/20px normal Helvetica, Arial, sans-serif;
        color: #4F5155;
    }

    a {
        color: #003399;
        background-color: transparent;
        font-weight: normal;
    }

    h1 {
        color: #444;
        background-color: transparent;
        border-bottom: 1px solid #D0D0D0;
        font-size: 19px;
        font-weight: normal;
        margin: 0 0 14px 0;
        padding: 14px 15px 10px 15px;
    }

    code {
        font-family: Consolas, Monaco, Courier New, Courier, monospace;
        font-size: 12px;
        background-color: #f9f9f9;
        border: 1px solid #D0D0D0;
        color: #002166;
        display: block;
        margin: 14px 0 14px 0;
        padding: 12px 10px 12px 10px;
    }

    #body {
        margin: 0 15px 0 15px;
    }

    p.footer {
        text-align: right;
        font-size: 11px;
        border-top: 1px solid #D0D0D0;
        line-height: 32px;
        padding: 0 10px 0 10px;
        margin: 20px 0 0 0;
    }

    #container {
        margin: 10px;
        border: 1px solid #D0D0D0;
        box-shadow: 0 0 8px #D0D0D0;
    }
    </style>
</head>
<body>

<?php echo form_open('path/to/controller/update/method'); ?>

<table cellpadding="6" cellspacing="1" style="width:100%" border="0">

<tr>
        <th>QTY</th>
        <th>Item Description</th>
        <th style="text-align:right">Item Price</th>
        <th style="text-align:right">Sub-Total</th>
</tr>

<?php $i 1?>

<?php foreach ($this->cart->contents() as $items): ?>

        <?php echo form_hidden($i.'[rowid]'$items['rowid']); ?>

        <tr>
                <td><?php echo form_input(array('name' => $i.'[qty]''value' => $items['qty'], 'maxlength' => '3''size' => '5')); ?></td>
                <td>
                        <?php echo $items['name']; ?>

                        <?php if ($this->cart->has_options($items['rowid']) == TRUE): ?>

                                <p>
                                        <?php foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value): ?>

                                                <strong><?php echo $option_name?>:</strong> <?php echo $option_value?><br />

                                        <?php endforeach; ?>
                                </p>

                        <?php endif; ?>

                </td>
                <td style="text-align:right"><?php echo $this->cart->format_number($items['price']); ?></td>
                <td style="text-align:right">$<?php echo $this->cart->format_number($items['subtotal']); ?></td>
        </tr>

<?php $i++; ?>

<?php endforeach; ?>

<tr>
        <td colspan="2"> </td>
        <td class="right"><strong>Total</strong></td>
        <td class="right">$<?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>

</table>

<p><?php echo form_submit('''Update your Cart'); ?></p>

</body>
</html> 


controllers/Welcome.php

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Welcome extends CI_Controller {

    
/**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *         http://example.com/index.php/welcome
     *    - or -
     *         http://example.com/index.php/welcome/index
     *    - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see https://codeigniter.com/user_guide/general/urls.html
     */
    
public function index()
    {
        
$this->load->view('welcome_message');
        
        
$data = array(
 
       array(
 
               'id'      => 'sku_123ABC',
 
               'qty'     => 1,
 
               'price'   => 39.95,
 
               'name'    => 'T-Shirt',
 
               'options' => array('Size' => 'L''Color' => 'Red')
 
       ),
 
       array(
 
               'id'      => 'sku_567ZYX',
 
               'qty'     => 1,
 
               'price'   => 9.95,
 
               'name'    => 'Coffee Mug'
 
       ),
 
       array(
 
               'id'      => 'sku_965QRS',
 
               'qty'     => 1,
 
               'price'   => 29.95,
 
               'name'    => 'Shot Glass'
 
       )
        );

    
$this->cart->insert($data);
    }



Can anyone help me detect the errors?
" If I looks more intelligence please increase my reputation."
Reply
#2

Hello Davy_yg. Make sure your form_helper has been loaded.

Also, make sure you read through the docs thoroughly. Most of the questions you've posted here can be answered by reading the documentation.
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#3

Oh, and just to add. I'm pretty sure the shopping cart class is deprecated and scheduled for removal. I would suggest finding an alternative library with active development via composer
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#4

also you have another error in your view file - close the form after the submit button.
Reply
#5

(This post was last modified: 05-12-2016, 08:16 PM by davy_yg.)

Thanks for advice.  What is alternative library with active development via composer?
" If I looks more intelligence please increase my reputation."
Reply
#6

There is none, make your own. A good cart is only responsible for two things - the product id and the quantity.
It also holds some other information, like the product name and the product price - but its not 'responsible' for that info especially the price.

Put this another way - someone puts a product in the cart. They come back a week later to check out. Meanwhile that products price has gone up,
or the product has gone out of stock and is not available at all. Either of those conditions will be very bad for your merchant. So the cart is not in charge of those things, which means it needs to ask the Product table - is this still in stock? is this still the price? etc.

The cart is also not in charge of shipping, tax, discounts, or any order totals. Use a separate shopping session table for that. And when the order is paid for the carts job is done. Make separate tables for the Order and Order Items. Then your cart never has historical data that must be kept, and your Orders and Order Items tables are private and everything in them is historical data.
Reply
#7

(05-13-2016, 11:03 AM)cartalot Wrote: There is none, make your own. A good cart is only responsible for two things - the product id and the quantity.
It also holds some other information, like the product name and the product price - but its not 'responsible' for that info especially the price.

Put this another way - someone puts a product in the cart. They come back a week later to check out. Meanwhile that products price has gone up,
or the product has gone out of stock and is not available at all. Either of those conditions will be very bad for your merchant. So the cart is not in charge of those things, which means it needs to ask the Product table - is this still in stock? is this still the price? etc.

The cart is also not in charge of shipping, tax, discounts, or any order totals. Use a separate shopping session table for that. And when the order is paid for the carts job is done. Make separate tables for the Order and Order Items. Then your cart never has historical data that must be kept, and your Orders and Order Items tables are private and everything in them is historical data.

There is none?

A quick search found a few with active development or a ton of users using it.

The Search:
https://packagist.org/search/?q=cart

Packages with active development:
https://packagist.org/packages/sylius/cart
https://packagist.org/packages/darryldecode/cart (Made for laravel, but I'm sure it can be used in CI)


https://packagist.org/packages/moltin/cart (Has a ton of users using it)
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#8

(05-13-2016, 12:01 PM)albertleao Wrote: There is none?

A quick search found a few with active development or a ton of users using it.

hey i apologize i was not being entirely serious and i was responding to the OP not your suggestion. i almost wrote - if you find a good codeigniter cart please let us know. that said i looked at everything you posted and unless i'm missing something none of them are codeigniter. so if you are going to jump to another framework i would suggest you jump all the way to Ruby and use Spree. its probably the best open source e-commerce system right now. but if you want to do e-commerce with codeigniter, and you are wondering about the cart library - make your own and here is why. thats what my reply was directed to.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB