Opencart Modification - php

I am currently using OpenCart 1.5. I need to display the product purchased in the orders page inside the admin: sales/order. along with the Order_id, customer, status, total, etc...
Should I be able to do this with a module? or can I modify the model (order.php) with another database query. Currently it is called getOrders($data = array()) but it only queries the .order_status database so therefore I can't return the product's name as part of the foreach results in the controller nor the view. Although line 562 in the same model looks pretty familiar to what I want but it is only used after an action is clicked on by the user.
Any help?

You have two choices:
either You make Your edits using the vQmod XML file, while the original code stays intouched
or You make Your edits in the code directly (which may cause problems if You'd decide to upgrade in the future)
Anyway, a module won't do that (unless You think of vQmod edits as a module). You would need to edit the controller - getList() method and the model - getOrders() method. Think wisely how much information You want to display, as products may have other options and You may end up in a juggernaut query and only the list of 20 orders may take few seconds to complete...
Good luck.

Related

Magento not displaing stored articles

I created a script to store articles in magento from external sources.
This is what I'm currently doing
$this->product = Mage::getModel('catalog/product')->loadByAttribute('sku',$this->artnr);
Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
if($this->product===false || $this->product->getId()<1){
$this->product = Mage::getModel('catalog/product');
$this->product->setSku($this->actindo['art_nr']);
$this->newProduct = true;
$this->product->setAttributeSetId($this->getDefaultAttributeSetId());
$this->product->setStoreId(Mage::app()->getStore()->getWebsiteId());
$this->product->setCreatedAt(strtotime('now'));
}
Then I set all the required fields like description etc
and then I'm doing a store
$this->product->save();
The Products appear correctly in the Admin Backend, but they aren't visible in the shop frontend.
I checked the database and saw that several indexes are not written.
Also the flat tables aren't saved.
If I store it afterwards again in the admin backend, everything is saved.
I have the flat tables currently disabled.
But their content is still written.
I'm using Magento 1.7.0.1 with PHP5.3 runing as fpm and web server nginx.
I also already tried to rebuild the indexes and everything, but it still is not visible in the frontend.
What am I doing wrong?
All fields that I push to the script get written and are visible in the admin section.
????
you have probably tried all these but I know figuring out 'why is the product not showing' is a frustrating process.
My advice is try making a similar product manually in the Magento admin area and then check all the fields in the admin area for each product. You might look at setting 'website_ids' closely and I think store_id and website_id are different things, no? $store_id = Mage::app()->getStore()->getStoreId(); vs $store_website_id = Mage::app()->getStore()->getWebsiteId();
You could also use the system->import/export export tool to compare what Magento has set vs what your algorithm is setting.
Are you reading the Magento AdminHTML functions for product saving?
/* path: app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php */
Mage_Adminhtml_Catalog_ProductController::saveAction()
// (and then obviously)
Mage_Adminhtml_Catalog_ProductController::_initProductSave()
Mage_Adminhtml_Catalog_ProductController::_initProduct()
So looking at that code, if you can capture the POST from the Magento Admin when you click the save button when you manually make your test product then you will be able to see what is being 'passed in' to the saveAction() function and compare that with your code.
Where do you run your code from? If you are instantiating your own Mage::app() I think you need to set it up as an admin session and set store ids and such. I can't find a reference to that but search around if you think that might be something to do with it. Maybe you can use a call to saveAction() or re-purpose that code rather than using $this->product->save().
If you have a test module for running arbitrary code, try some debug calls and echos from building different product collections to see what is the difference between your generated product and your manually entered test product.
Plan B : If you have an external product data source, you might find the most excellent 'MAGMI Datapump API' the simplest and quickest way to achieve what you want.
Was that too much information?
There are some settings that are required in order to have a product on the frontend.
It must be enabled:
->setStatus(1);
It must be visible
->setVisibility(4); //or 2
It must be in stock or you must have the setting to display out of stock products on frontend.
$stockItem = array();
$stockItem['qty'] = 100; //something bbigger than 0
$stockItem['is_in_stock'] = 1;
$product->setData('stock_item', $stockItem);

Adding a search field to the Magento admin

Is there a way to add a new search field in the Magento admin under "Orders"? I want to be able to search by coupon code usage (ex: search by coupon code: "sale2013", come up with all the orders that applied that coupon code during checkout).
I'm able to pull this data out of the Magento DB, but I'd really like to add this functionality to the Magento admin to make it easier for co-workers and my boss. Can it be done and, if so, ideas as to where I can start? Thanks guys.
The coupon code used during checkout is stored on the primary order table (sales_flat_order) when the customer checks out. If there is no value, then no coupon code was used. However, the data for the grid in the admin comes from the sales_flat_order_grid table; it comes from there instead of the primary order table for performance reasons which become particularly evident on very high traffic sites.
Now that we know where the data is that you need to filter on, and where the data for the grid comes from, we can move on to build it!
The first thing that you will need to do is add a coupon_code column to the sales_flat_order_grid table matching the definition of the column on the sales_flat_order table. The values in the coupon_code column of sales_flat_order should automatically populate into sales_flat_order_grid once the matching column is there and your cache storage has been flushed.
The data is updated on the order save, so to be specific, new orders and orders updated via the admin (even a comment on the order) will have the data populated. For existing orders, run a data upgrade script to copy the values over.
After the data/schemas are in place, you'll want to have the grid show a filterable column for it. For this you will want to rewrite the Mage_Adminhtml_Block_Sales_Order_Grid class from your custom module (please don't edit the core files directly, it will haunt you later) and override the _prepareColumns method with one that includes your column definition:
$this->addColumn('coupon_code', array(
'header' => Mage::helper('sales')->__('Coupon Code'),
'index' => 'coupon_code',
));
If you're very fresh on Magento development, I'd venture to say that I've only begun to help you. But you'll have plenty of reference points from which to dig in and build the functionality you need. HTH! :)
Adding new columns to a grid is easy with this extension:
https://github.com/magento-hackathon/GridControl
Add this extension, write your own with a gridcontrol.xml inside your etc directory
And then something like this should work:
<?xml version="1.0"?>
<gridcontrol>
<grids>
<order.grid>
<coupon_code>
<after>columnname</after>
<add>
<header>Coupon code</header>
<type>text</type>
<index>coupon_code</index>
<joinField>coupon_code|sales/order|coupon_code|entity_id=entity_id||left</joinField>
</add>
</coupon_code>
</order.grid>
</grids>
</gridcontrol>

cart issue in opencart

I have problem in understanding one concept.
Suppose you have logged in and added some items to your cart but without checking out you have logged out. Next time you logged in you will find the cart with the items you have added previously.
I want to know how this concept works? After some study I have come to know it is using cache files. But how this cache files works? How this cache files are related to the backend database?
OpenCart uses a field in the customer table to store the cart items as a serialized array of data. The field is called cart. Similarly, the wishlist uses the same technique and is called wishlist, again in the customer table. To actually load the cached content, the values are loaded in the login() method in /system/library/customer.php, using this code
if ($customer_query->row['cart'] && is_string($customer_query->row['cart'])) {
$cart = unserialize($customer_query->row['cart']);
foreach ($cart as $key => $value) {
if (!array_key_exists($key, $this->session->data['cart'])) {
$this->session->data['cart'][$key] = $value;
} else {
$this->session->data['cart'][$key] += $value;
}
}
}
This code actually adds items to the current cart, so if you already have items in the basket, it merges them
As You asked more questions - one related to the cart and items storing and one or two cache related, and as Jay Gilford answered that cart related part, here is an answer for the cache:
Opencart caches the data You use most the time and at every page load: currencies, languages, categories, products, category product counts, weight classes, tax classes, etc. In models (lets talk about frontend/catalog for now) when fetching the data OpenCart looks for the cached data prior to querying the database. If there are cached data found they are fetched and unserialized (they are stored in plain text files using PHP's function serialize()) and returned to the controller without querying the database - thus the fetching should be much quicker1. If there are no cached data the database is queried and the database data fetched are then serialized (using PHP's function serilizae()) and saved to the corresponding cache file.
Here is one small problem that may occur - after You have edit the data directly in the database (using phpMyAdmin, may the reason be whatever for this) the change is not present at frontend. This is because there are older data cached that are fetched when asked for them. If You have to do such editing then do not forget to manualy delete corresponding cache file(s).
Which lead us to the administration (backend) part of models - here when editing or adding data (category, product, currencies, weight classes, etc) after the data is successfully stored to the database the corresponding cache file is immediately deleted so it could be re-created at frontend containing up-to-date data.
The cache files could be find at /system/cache/ folder.
EDIT: The cache is instanciated and registered within index.php and is then accessible in both controllers and models as $this->cache while methods set(), get() and delete() are callable. The cache class itself could be found at system/library/cache.php and is quite simple and straightforward.
Is such an answer sufficient?
1 I have seen a server with very fast PHP-MySQL communication while slow filesystem access...

Change Product type in magento

I have two products and their type is "Grouped Product" now I want to change this products in to simple product. Is there any way to do so?
Some links says I have to change directly from database. I tried this but nothing changes. Is there any way to do it?
If it's only 2 maybe you should just create 2 new products with same url and change the url of the old ones.
Alternatively you could do some programming.
Maybe start with this class Mage_Catalog_Model_Product_Type_Grouped.
the public function getAssociatedProducts returns an array of associated products which you can simply sort through applying whatever logic before creating your new products.
You have to deal with store scope etc during this process but there's lots of tutorials.
product type cannot be changed in admin!
may be you could go "catalog_product_entity" table and change the type_id from grouped to simple, but i dunno whether it induced new error, but one thing i only know is you must lost the grouped item linkage.
Have you rebuilt the indices (Admin / System / Index Management) and refreshed the cache (Admin / System / Cache Management)?

Symfony 1.3: Need to override backend filter field's set of data

My project is using Symfony 1.3.11, PHP version is 5.3.3.
Let me explain my case and my problem:
We wanted to add another kind of user, not just "user" and "admin" (using sfGuardPlugin). I did add "business" and I did give him permissions to only ONE admin module -- "purchases" (accessing own and under some conditions -- other people's purchases made on the site).
The "business" user can be associated to one or more Partners (firms) registered in the site, effectively allowing us to handle business owners or representatives a wee bit differently.
When the "business" user accesses the admin section, the list of purchases he sees must be this: All Purchases for all Products of all Partners he has associated with him. (Not exactly a trivial query).
I did that, in my opinion, in a stupid manner, but it does work -- namely overriding the "apps/backend/modules/purchase/actions/actions.class.php#executeIndex". I had to first copy-paste some code from the version of that method in the cache.
In short, I did hook myself to the "executeIndex" and added a code to do the proper Criteria, and the code works.
The problem now is this:
The filter field above the list (the one containing the Product list) does contain all possible Products. We want it to only contain all Products for all Partners the current user is associated with.
Thing is, it's my first time having to override the admin's filters and I am lost as to where should I plug my code.
Any help is appreciated. Thanks for your time.
UPDATE: Strangely very unpopular question. Nobody ever had to do this? Wow.
You have to unset the product_list and set another widget with the filtered choices.
Check this post where I explain something like that but using doctrine. In your case the sfGuardUserForm is your somthingFilterForm.
You could also filter data using this method. This is a little more elegant but both would work.

Categories