Iam developing a codeigniter POS system project.
I have separate sections to product sale and product GRN. both are using codeigniter cart library
in product sale section I created instance called : ocart
$this->load->library('cart','','ocart');
$ocart = $this->ocart->contents();
$this->ocart->destroy();
$this->ocart->insert($data);
product GRN section I created separate instance called : pcart
$this->load->library('cart','','pcart');
$pcart = $this->pcart->contents();
$this->pcart->destroy();
$this->pcart->insert($data);
When Im going to add product to the cart in sale section, same time same product added to the product GRN cart also. and wise versa.
then I checked array contents using print_r($pcart) and print_r($ocart);
both giving same output
Array
(
[6b913a2317d00f7bfa0abdaff1a1f67f] => Array
(
[rowid] => 6b913a2317d00f7bfa0abdaff1a1f67f
[id] => 22020
[pcode] => DS141
[note] => PLATE
[qty] => 20
[price] => 1
[name] => 97280
[subtotal] => 20
)
)
what is wrong with above code, please advice.
There is no built-in method to destroy loaded library object.
You can do simply like that by using unset or setting null.
unset($this->my_library);
OR
$this->my_library = null;
Related
Using opencart 3 and trying to make use of the events but I'm unable to find the identifier.
E.g trying to extend the returns form added an event:
$this->model_setting_event->addEvent('mail_account_return_after', 'catalog/model/account/return/addReturn/after', 'extension/module/return/returnAdd');
Controller:
class ControllerExtensionModuleReturn extends Controller {
public function returnAdd(&$route, &$args, &$output) {
print_r($args);
exit;
$args is missing the main return_id identifier:
Array
(
[0] => Array
(
[firstname] => Foo
[lastname] => Bar
[email] => test#gmail.com
[telephone] => 01234556789
[order_id] => 29
[date_ordered] => 2017-06-29
[product] => Canon EOS 5D
[model] => Product 3
[quantity] => 1
[return_reason_id] => 4
[opened] => 0
[comment] => Test comment
)
)
Tried with $this->db->getLastId() but this returns 0. Tested with other events and appears to be missing the main identifiers.
Where does opencart set what data is passed to the before/after events?
If I'm not mistaken you should be able to access the auto increment return_id in $output, which holds the output of method addReturn(), i.e., $this->db->getLastId();.
As to why calling getLastId() a second time from within your event doesn't work, that's a good question. I would assume there may be some other query happening in between - though by default I don't think there should be. Is it possible there is another trigger running a query before your event gets triggered?
Look in system/engine/loader.php at for the strings before and after. There are methods that do view, controller, configuration and language.
I am currently trying to export a number of products from a custom CMS MYSQL database into a Magento compatible database.
The products include product descriptions which is stored as HTML that was serialised in a "ob_data" array with some other info when they were added through CMS system. Here is an example of one:
Array
(
[id] => 1085
[type] => 9
[url_key] => royal-worcester-mikado-milk-jug
[name] => Royal Worcester Mikado 1/2 Pint Milk Jug
[pattern] => Mikado
[manufacturer] => Royal Worcester
[stock] => 0
[content] => <p>Bone china<br />Holds approx1/2 pint.<br />Excellent condition.</p>
[weight] => 0.75
[price] => 20.00
[image] => /media/dContent/eCommerce/old/165.jpg
)
Using unserialze I can extract this and some other info into an array which can be written to the CSV. However when I write this information to a CSV file with fputcsv I get the following:
1085,9,royal-worcester-mikado-milk-jug,"Royal Worcester Mikado 1/2 Pint Milk Jug",Mikado,"Royal Worcester",0,"<p>Bone china<br />
Holds approx 1/2 pint.<br />
Excellent condition.</p>",0.75,20.00,/media/dContent/eCommerce/old/165.jpg
Essentially the <br/> tags that are in the description are also adding new lines in my CSV breaking its format and making it impossible to import.
Is there anyway that I can stop this happening and format the content so that it can comfortably written into the CSV?
Im using the AvS_FastSimpleImport Modul to import products into Magento. So far it works well with a lot of attibutes/configurations. The problem is that some attributes like min_sale_qty or use_config_min_sale_qty are simply ignored and have no effect at all. I set use_config_min_sale_qty to 0 so I thought it should work.
Update
It does work if I set use_config_min_sale_qty = 0, min_sale_qty = 4 fix for the whole import. But I only have some products with min_sale_qty > 1. It looks like it uses the first value for the whole import.
Example product:
Array
(
[sku] => 5409
[_type] => simple
[_attribute_set] => Default
[_product_websites] => base
[name] => Test
[price] => 3
[qty] => 1
[is_in_stock] => 1
[min_sale_qty] => 4
[use_config_min_sale_qty] => 0
(... some more)
)
Any idea how I could fix this?
It was a bug in the import modul (Magento Core).
\app\code\core\Mage\ImportExport\Model\Import\Entity\Product.php, Line 1609
Mage_ImportExport_Model_Import_Entity_Product::_saveStockItem()
$row was not initialised:
$row = array();
$row['product_id'] = $this->_newSku[$rowData[self::COL_SKU]]['entity_id'];
$row['stock_id'] = 1;
This bug is fixed in Magento2 but not in 1.7.0.2 community version.
I have defined some custom attributes and assigned them to products via the Opencart admin panel. I'm trying to retrieve these attributes upon checkout to adjust some shipping costs.
I'm currently working in the catalog/model/shipping/ups.php file in the getQuote function. I'm getting close with this:
print_r($this->cart->getProducts());
Which gives me the following product data:
Array
(
[59] => Array
(
[key] => 59
[product_id] => 59
[name] => My Product Name
[model] => ABC
[shipping] => 1
[image] => data/myproduct.jpg
[option] => Array
(
)
[download] => Array
(
)
[quantity] => 1
[minimum] => 1
[subtract] => 1
[stock] => 1
[price] => 29.99
[total] => 29.99
[reward] => 0
[points] => 0
[tax_class_id] => 0
[weight] => 3.75
[weight_class_id] => 5
[length] => 0.00
[width] => 0.00
[height] => 0.00
[length_class_id] => 3
)
)
However, no custom attributes are returned. I'm sure there is a nice way to pass the product ID to an attribute-getting function, but I can't find it. The Opencart docs are a little lacking for the development side and no luck on Google.
Usually I'd grep the hell out of the whole directory structure to find what I'm looking for, but shell access is disabled on this particular web host :(.
EDIT
I believe Attributes are a newer feature that is built into Opencart. Its like a custom field.
Anyway, on the admin side I went to Catalog > Attributes and created a custom attribute called "Shipping Box Type". Then, under a specific product I can set the attribute. See screenshot. My goal is to retrieve the value of "Shipping Box Type". Does that answer your question #Cleverbot? I'm sure I can do a custom db query to grab it, but theres got to be a built-in function to grab attributes?
Retrieve attributes for a given product_id
$this->load->model('catalog/product');
$attributes = $this->model_catalog_product->getProductAttributes(59);
print_r($attributes);
Output
Array
(
[0] => Array
(
[attribute_group_id] => 9
[name] => Shipping Fields
[attribute] => Array
(
[0] => Array
(
[attribute_id] => 16
[name] => Shipping Box Type
[text] => SM2
)
)
)
)
Taking it further, here is an example of looping through the products currently in the cart to see what attributes they have:
$this->load->model('catalog/product');
$cart_products = $this->cart->getProducts();
// get attributes for each product in the cart
foreach($cart_products as $product) {
$attributes = $this->model_catalog_product->getProductAttributes($product['product_id']);
print_r($attributes);
}
This is not the most intuitive feature in Opencart. First you have to go catalog>attributes>attribute groups and you have to create a group name that will be a title for your attribute. For this it might be "Shipping Specifications".
Then you need to go to catalog>attributes>attributes> and create a new attribute under "Shipping Specifications" named "Shipping Box Type".
Now you are ready to go to catalog>products and add the attribute to a product.
The catch is that it won't be displayed how you were hoping I think. It will show up under the specifications tab next to description on your products page. You have the easy option of changing "Specifications" to the Heading of your choice in catalog/view/*your_theme*/products/products.tpl or you can edit the same tpl file to change the container/format that the data output goes.
I'm using the Nestoria API to retrieve property results.
Everything is working quite well and one can return up to 50 properties using this method.
I would like to show 10 items at a time and allow for the user to paginate through them, but for some reason I'm having difficulty doing this.
The code snippet around the section that controls this is as follows:
$page = isset($_REQUEST["page"]) ? (int)$_REQUEST["page"] : 1;
$page = $page-1;
$pagination = new pagination;
$propertyResults = $pagination->generate($nestoria->decodedData->response->listings, 10);
foreach($propertyResults as $listing) {
//do stuff
}
A snippet of the data array would be:
Array
(
[0] => stdClass Object
(
[auction_date] =>
[property_type] => house
[summary] => Located in North Kingston a two double bedroom Victorian house presented in...
[title] => York Road, Kingston, KT2 - Reception
[updated_in_days] => 6.5
[updated_in_days_formatted] => this week
)
[1] => stdClass Object
(
[auction_date] =>
[property_type] => house
[summary] => Fine home was built about 50 years ago and enjoys one of the best locations...
[title] => Coombe Hill, KT2 - Conservatory
[updated_in_days] => 2.5
[updated_in_days_formatted] => this week
)
....
(sample cut down due to size of array elements)
Now I have been staring at this for way too long now and I've drawn a blank.
This code works correctly except if I try go to any other page other than 1, then the page doesn't finish loading, it just carries on until Firefox says: "The page isn't redirecting properly".
So basically, pagination is able to cut my data array up correctly, but is failing to "paginate" correctly.
Any help?
Turns out the problem with the redirect was actually an .htaccess issue which was using the $_GET["page"] variable and was therefore getting confused, so I renamed all references to the $_GET["page"] to $_GET["_page"] in this app.