Why cart library is not working in codeigniter 3 when using MX hmvc? - shopping-cart

Tryint to experiment the cart library, it is working ok without mx hmvc in in CI3. But as soon as i am inserting MX hmvc files (i.e MY_Loader.php and MY_Router.php in application/core folder and MX folder inside third_party folder) it is throwing error saying
Severity: Notice
Message: Undefined property: Welcome::$Session
Filename: MX/Loader.php
Line Number: 171
I am not even inside the modules just trying to use codeigniter's default controller and view.
My modified codeigniter's controller welcome.php is as below
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->helper('form');
$this->load->helper('url');
// Load the cart library to use it.
$this->load->library('cart');
// Assuming this is the products from our database
$data['products'] = array(
array(
'id' => 'sku_888',
'qty' => 1,
'price' => 39.95,
'name' => 'T-Shirt',
'options' => array('Size' => 'xxx', 'Color' => 'White')
),
array(
'id' => 'sku_888',
'qty' => 1,
'price' => 39.95,
'name' => 'T-Shirt',
'options' => array('Size' => 'xx', 'Color' => 'green')
),
array(
'id' => 'sku_777',
'qty' => 1,
'price' => 9.95,
'name' => 'Coffee Mug'
),
array(
'id' => 'sku_666',
'qty' => 1,
'price' => 29.95,
'name' => 'Shot Glass'
)
);
// Insert the product to cart
if ($this->input->get('id') != '' && array_key_exists($this->input->get('id'), $data['products']))
{
$this->cart->insert($data['products'][$this->input->get('id')]);
}
// Lets update our cart
if ($this->input->post('update_cart'))
{
unset($_POST['update_cart']);
$contents = $this->input->post();
foreach ($contents as $content)
{
$info = array(
'rowid' => $content['rowid'],
'qty' => $content['qty']
);
$this->cart->update($info);
}
}
$this->load->view('welcome_message', $data);
}
}
and the default codeigniter view welcome_message.php, i modified as below
<b>Products</b>
<table width="100%" border="1">
<tr>
<td width="37%">ID</td>
<td width="30%">Name</td>
<td width="16%">Price</td>
<td width="16%"> </td>
</tr>
<?php $product_array_index = 0;?>
<?php foreach($products as $product):?>
<tr>
<td><?php echo $product['id'];?></td>
<td>
<?php
echo $product['name'] ;
if (array_key_exists('options', $product)) {
echo '<hr>';
foreach ($product['options'] as $key => $value)
{
echo '<strong>' . $key . '</strong> : '. $value . '<br/>';
}
}
?>
</td>
<td><?php echo $product['price'];?></td>
<td>Add to Cart</td>
</tr>
<?php $product_array_index ++;?>
<?php endforeach;?>
</table>
<hr>
<b>Your Cart</b>
<?php echo form_open(base_url()); ?>
<table cellpadding="6" cellspacing="1" style="width:100%" border="1">
<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" align="right">$<?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>
</table>
<p><?php echo form_submit('update_cart', 'Update your Cart'); ?></p>
How to make it work?

Related

How To Add Attribute to Magento 2.1.x Product Page

I hope this is a really simple question created only by my newb status to PhP and Magento.
Question: Given the details described below, in the catalog_product_view.xml first attribute. What should this be to ensure I get my custom attribute gsc_payment? I can everything to work using a built in attribute like UPC, but not my custom attribute.
I created a new attribute and made it visible on Magento's Products Page.
Attribute Code: gsc_payment
Default Label: ARC 90 Payment
I opened catalog_product_view.xml from
/home/XXXXXXXX/public_html/app/design/frontend/Venustheme/gosmart/Magento_Catalog/layout/catalog_product_view.xml and added the referenceContainer shown below.
<referenceContainer name="product.info.main">
<block class="Magento\Catalog\Block\Product\View\Description"
name="product.info.gsc"
template="Magento_Catalog::product/view/gsc.phtml"
after="product.info.upc">
<arguments>
<argument name="at_call" xsi:type="string">getGSC_Payment</argument>
<argument name="at_code" xsi:type="string">gsc_payment</argument>
<argument name="css_class" xsi:type="string">gsc_payment</argument>
<argument name="at_label" xsi:type="string">Arc 90 Payment:</argument>
<argument name="add_attribute" xsi:type="string">itemprop="gsc_payment"</argument>
</arguments>
</block>
</referenceContainer>
<referenceContainer name="product.info.main">
<block class="Ves\Themesettings\Block\Product\View" name="ves.product.info.main" template="Magento_Catalog::product/view/product_info_main.phtml">
<move element="product.info.sku" as="product_info_sku" destination="ves.product.info.main"/>
<move element="product.info.review" as="product_info_review" destination="ves.product.info.main"/>
<move element="product.price.final" as="product_price_final" destination="ves.product.info.main"/>
<move element="product.price.tier" as="product_price_tier" destination="ves.product.info.main"/>
<move element="alert.urls" as="alert_urls" destination="ves.product.info.main"/>
<move element="product.info" as="product_info" destination="ves.product.info.main"/>
<move element="product.info.overview" as="product_info_overview" destination="ves.product.info.main"/>
<move element="require-cookie" as="require_cookie" destination="ves.product.info.main"/>
<move element="product.info.extrahint" as="product_info_extrahint" destination="ves.product.info.main"/>
<move element="product.info.type" as="product_info_type" destination="ves.product.info.main"/>
</block>
</referenceContainer>
<container name="product.info.extrahint" as="extrahint" label="Product View Extra Hint">
<container name="product.info.social" label="Product social links container" after="product.info.overview">
<block class="Magento\Catalog\Block\Product\View" name="product.info.categories" template="product/view/categories.phtml"/>
</container>
I created a new file here /home/XXXXXXXXX/public_html/vendor/magento/module-catalog/view/frontend/templates/product/view/gsc.phtml with the following block code copied from internet.
<?php
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();
$_code = $block->getAtCode();
$_className = $block->getCssClass();
$_attributeLabel = $block->getAtLabel();
$_attributeType = $block->getAtType();
$_attributeAddAttribute = $block->getAddAttribute();
if ($_attributeLabel && $_attributeLabel == 'default') {
$_attributeLabel = $_product->getResource()->getAttribute($_code)->getFrontendLabel();
}
$_attributeValue =$_product->getResource()->getAttribute($_code)->getFrontend()->getValue($_product);
?>
<?php if ($_attributeValue): ?>
<div class="product attibute <?php echo $_className?>">
<?php if ($_attributeLabel != 'none'): ?><strong class="type"><?php echo $_attributeLabel?></strong><?php endif; ?>
<div class="value" <?php echo $_attributeAddAttribute;?>><?php echo $_attributeValue; ?></div>
</div>
<?php endif; ?>
I then opened /home/XXXXXXXXXXX/public_html/app/design/frontend/Venustheme/gosmart/Magento_Catalog/templates/product/view/product_info_main.phtml and added the following code inside the existing .
<div>
<table style="width: 100%; border-color: #ac1a2f; border-style: solid; border-width: 2px;">
<tbody>
<tr>
<td>
<p style="color: red; font-size: 300%; text-align: center;">Buy Today!</p>
<div style="color: green; font-size: 400%; text-align: center;">$
<?php echo $this->getChildHtml('product_info_gsc_payment') ?>
<?php echo "Hello"?>
<?php $_product = $block->getProduct();
echo $_product->getPrice();
echo $_product->getAttributeText('color');
?>
</div>
<p style="font-size: 150%; text-align: center;">bi-weekly/12 months</p>
<p style="color: red; font-size: 150%; text-align: center;">90 Days Same As Cash</p>
<p style="text-align: center;">20-25% Down Payment Required</p>
<p style="text-align: center;">Estimated Payment</p>
</td>
<td>
<div style="text-align: center;">
<p><img style="width: 25%; height: 25%;" src="https://1792armory.com/public/firearms/arc90_logo_big.png" border="0" /></p>
<p> <img style="align: center;" src="https://mail.globalcheck.com/images/qualify1.jpg" border="0" /> </p>
</div>
</td>
</tr>
</tbody>
</table>
You can create custom attribute using Setup/upgradeData.php
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace Custom\Product\Setup;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
class UpgradeData implements UpgradeDataInterface {
public function __construct(\Magento\Eav\Setup\EavSetupFactory $eavSetupFactory) {
$this->eavSetupFactory = $eavSetupFactory;
}
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) {
$setup->startSetup();
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
if (version_compare($context->getVersion(), '2.1.24') < 0) {
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY, 'product_height', [
'type' => 'varchar',
'label' => 'Product Height in cm',
'input' => 'text',
'required' => false,
'class' => '',
'backend' => '',
'source' => '',
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
'visible' => true,
'user_defined' => false,
'searchable' => false,
'filterable' => false,
'filterable_in_search' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'group' => 'General',
'is_used_in_grid' => false,
'is_visible_in_grid' => false,
'is_filterable_in_grid' => true,
]
);
}
$setup->endSetup();
}
}
?>

Display thumbnail of category in category.tpl module in opencart?

I need to display thumbnail images of category in category.tpl module in opencart?
I want display thumbnail of category in extension/module/category.tpl not product/product.tpl
how i can do this?
opencart 2.3.0.2
Show images for the sub-categories in the opencart version 2.3
Find following code at catalog\controller\product\category.php
$data['categories'][] = array(
'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
);
Replace the code with below code:
$data['categories'][] = array(
'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'image' => $this->model_tool_image->resize($result['image'], 100,100),
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
);
Changed is 'image' => $this->model_tool_image->resize($result['image'], 100,100), if you have to increase the size then change 100 to other values.
Find following code at catalog\view\theme\default\template\product\category.tpl
<?php if ($categories) { ?>
<h3><?php echo $text_refine; ?></h3>
<?php if (count($categories) <= 5) { ?>
<div class="row">
<div class="col-sm-3">
<ul>
<?php foreach ($categories as $category) { ?>
<li><?php echo $category['name']; ?></li>
<?php } ?>
</ul>
</div>
</div>
<?php } else { ?>
<div class="row">
<?php foreach (array_chunk($categories, ceil(count($categories) / 4)) as $categories) { ?>
<div class="col-sm-3">
<ul>
<?php foreach ($categories as $category) { ?>
<li><?php echo $category['name']; ?></li>
<?php } ?>
</ul>
</div>
<?php } ?>
</div>
<?php } ?>
<?php } ?>
Replace with the below code
<?php if ($categories) { ?>
<h3><?php echo $text_refine; ?></h3>
<?php if (count($categories) <= 5) { ?>
<div class="row">
<div class="col-sm-3">
<ul>
<?php foreach ($categories as $category) { ?>
<li> <a href="<?php echo $category['href']; ?>">
<?php if($category['image']){ ?>
<img src="<?php echo $category['image']; ?>" ><br>
<?php } ?>
<?php echo $category['name']; ?></a></li>
<?php } ?>
</ul>
</div>
</div>
<?php } else { ?>
<div class="row">
<?php foreach (array_chunk($categories, ceil(count($categories) / 4)) as $categories) { ?>
<div class="col-sm-3">
<ul>
<?php foreach ($categories as $category) { ?>
<li><a href="<?php echo $category['href']; ?>">
<?php if($category['image']){ ?>
<img src="<?php echo $category['image']; ?>" ><br>
<?php } ?>
<?php echo $category['name']; ?></a></li>
<?php } ?>
</ul>
</div>
<?php } ?>
</div>
<?php } ?>
<?php } ?>
Extra code added is below and there are two places to add the code:
<?php if($category['image']){ ?>
<img src="<?php echo $category['image']; ?>" ><br>
<?php } ?>
You are set for the default theme, but if you are using custom theme then you have to manage as per your theme.
https://webocreation.com/blog/show-images-sub-categories-opencart-version-2-3

How to add column to OpenCart customer list?

I use OpenCart 1.5.6.4 and 2.3
In admin panel and in customer list there is no column for Customer Id
between this place:
For Opencart 2:
You need to edit this file:
admin/view/template/customer/customer_list.tpl
1)
Find:
<td class="text-left"><?php if ($sort == 'name') { ?>
Add before it:
<td class="text-left">Customer ID</td>
2)
Find:
<td class="text-left"><?php echo $customer['name']; ?></td>
Add before it:
<td class="text-left"><?php echo $customer['customer_id']; ?></td>
For Opencart 1:
This file:
admin/view/template/sale/customer_list.tpl
1)
Find:
<td class="left"><?php if ($sort == 'name') { ?>
Add before it:
<td class="left">Customer ID</td>
2)
Find:
<td class="left"><?php echo $customer['name']; ?></td>
Add before it:
<td class="left"><?php echo $customer['customer_id']; ?></td>
For sort customers by their id for Opencart 2 in step 1 add this code:
<td class="text-left">
<?php if ($sort == 'customer_id') { ?>
Customer ID
<?php } else { ?>
Customer ID
<?php } ?>
</td>
instead of:
<td class="text-left">Customer ID</td>
Then open this file:
admin/controller/customer/customer.php
Find:
$data['sort_name'] = $this->url->link('customer/customer', 'token=' . $this->session->data['token'] . '&sort=name' . $url, true);
Add before it:
$data['sort_customer_id'] = $this->url->link('customer/customer', 'token=' . $this->session->data['token'] . '&sort=customer_id' . $url, true);

how to add extra tab without any extension in product page in opencart

how to add extra tab without any extension in product page in opencart
may be this is the code for extra tabs any one help? regards
<div class="tabs-group"> <div id="tabs" class="htabs clearfix">Delivery
<?php if ($attribute_groups) { ?>
<?php echo $tab_attribute; ?>
<?php } ?>
<?php if ($review_status) { ?>
<?php echo $tab_review; ?>
<?php } ?>
<?php if( $productConfig['enable_product_customtab'] && isset($productConfig['product_customtab_name'][$languageID]) ) { ?>
<?php echo $productConfig['product_customtab_name'][$languageID]; ?>
<?php } ?>
</div>
<div id="tab-description" class="tab-content"><?php echo $description; ?></div>
<?php if ($attribute_groups) { ?>
<div id="tab-attribute" class="tab-content">
<table class="attribute">
<?php foreach ($attribute_groups as $attribute_group) { ?>
<thead>
<tr>
<td colspan="2"><?php echo $attribute_group['name']; ?></td>
</tr>
</thead>
<tbody>
<?php foreach ($attribute_group['attribute'] as $attribute) { ?>
<tr>
<td><?php echo $attribute['name']; ?></td>
<td><?php echo $attribute['text']; ?></td>
</tr>
<?php } ?>
</tbody>
<?php } ?>
</table>
</div>
<?php } ?>
may be this is the code for extra tabs any one help? regards
Add a link to div id="tabs" with a href to your custom tab's id
<div class="tabs-group">
<div id="tabs" class="htabs clearfix">
Delivery
My Tab //Your custom tab
....
Then add your tab div after
<div id="tab-description" class="tab-content"><?php echo $description; ?></div>
<div id="tab-my-tab" class="tab-content">Your html content goes here</div>

Displaying product viewd report in dashboard in opencart

I want to display Product Viewed Report in Dashboard itself. Now the report id under Report->Products->Viewed
How to display it? I tried copying the code from admin->controller->report->product_viewed.php TO admin->controller->common->home.php
and copied the code from admin->view->report->product_viewed.tpl to admin->common->home.tpl
i have added code like this in home.tpl
<div class="content">
<table class="list">
<thead>
<tr>
<td class="left"><?php echo $column_name; ?></td>
<td class="left"><?php echo $column_model; ?></td>
<td class="right"><?php echo $column_viewed; ?></td>
<td class="right"><?php echo $column_percent; ?></td>
</tr>
</thead>
<tbody>
<?php if ($products) { ?>
<?php foreach ($products as $product) { ?>
<tr>
<td class="left"><?php echo $product['name']; ?></td>
<td class="left"><?php echo $product['model']; ?></td>
<td class="right"><?php echo $product['viewed']; ?></td>
<td class="right"><?php echo $product['percent']; ?></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td class="center" colspan="4"><?php echo $text_no_results; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
in my admin panel-> dashboard i am getting error like this
Notice: Undefined variable: products in /Applications/MAMP/htdocs/opencart/admin/view/template/common/home.tpl on line 95Notice: Undefined variable: column_name in /Applications/MAMP/htdocs/opencart/admin/view/template/common/home.tpl on line 88 Notice: Undefined variable: column_model in /Applications/MAMP/htdocs/opencart/admin/view/template/common/home.tpl on line 89 Notice: Undefined variable: column_viewed in /Applications/MAMP/htdocs/opencart/admin/view/template/common/home.tpl on line 90 Notice: Undefined variable: column_percent in /Applications/MAMP/htdocs/opencart/admin/view/template/common/home.tpl on line 91
please help me in solving this? where i should declare this 'products' ?
What it looks like to me is that there are no results from the products viewed and you have done this transition almost perfectly.
You can either update the language files with the appropriate fields in admin>language>english>common>home.php or you can change the tpl a little like this
<div class="content">
<table class="list">
<thead>
<tr>
<td class="left">Product Name:</td>
<td class="left">Model:</td>
<td class="right">Viewed:</td>
<td class="right">Percent:</td>