Magento Import: min_sale_qty is ignored - php

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.

Related

Codeingiter library multiple instances, not working

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;

Running thousands of MySQL queries, crashing server

I'm running a stock update on our company website, and the query is as follows;
$count = count($stock);
for($i = 0; $i < $count; $i++)
{
if(strtolower($stock[$i]['stockloc']) == 'retail')
{
if($stock[$i]['avail'] < 0)
{
$stock[$i]['avail'] = 0;
}
mysql_query("UPDATE `xcart_products`
SET `avail` = ".$stock[$i]['avail']."
WHERE `productid` IN
(SELECT `productid`
FROM `xcart_extra_field_values`
WHERE `productid` = ".$stock[$i]['productid']."
AND `fieldid` = 5
AND LOWER(value) = 'retail')");
}
}
Eessentially it runs in a for loop and iterates through thousands of products, updating stock levels. It runs fine for about 4 minutes, then things start to lag on our website, mysql seems to become backlogged with other website db queries that it can't run (they all appear locked), which then leads to the inevitable;
Internal Server Error The server encountered an internal error or
misconfiguration and was unable to complete your request.
Please contact the server administrator to inform of the time the
error occurred and of anything you might have done that may have
caused the error.
More information about this error may be available in the server error
log.
It doesn't seem to be a timeout I've upped the limit in PHP.ini to no avail. The query isn't particularly complex, however it does run several thousand times. Maybe as many as 5000+. I'm not sure what the problem is, as we ran a similar update system on our old website, and although it wasn't one I designed, it didn't have trouble uploading this many stock quantity changes.
I'll be happy to expand my question if further information is needed, but honestly, I'm at a bit of a loss even how to trace the problem.
The $stock array is an associative array which has the following format;
Array
(
[0] => Array
(
[avail] => 55
[productid] => 17761
[sku] => AER-TOUCH-2100
[stockloc] => retail
)
[1] => Array
(
[avail] => 166
[productid] => 22653
[sku] => CAS-AER-112
[stockloc] => retail
)
[2] => Array
(
[avail] => 272
[productid] => 22952
[sku] => CAS-ANT-001
[stockloc] => retail
)
[3] => Array
(
[avail] => 5
[productid] => 22956
[sku] => CAS-ANT-005
[stockloc] => retail
)
[4] => Array
(
[avail] => 12
[productid] => 22958
[sku] => CAS-ANT-007
[stockloc] => retail
I have tried running a delay every x iterations of the loop, but I'm still getting the 500 internal server error message. Clearly I need a better solution to updating my table.

How to retrieve custom attributes in Opencart?

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.

Paginate Nestoria Results using PHP

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.

PHP Zend Lucene Search Query with multiple criteria fail

Zend Lucene Search Document
Lucene Document
pk:Keyword
category_id:Keyword
title:UnStored
description:UnStored
This is my string query "java lucene AND +category_id:7".
Result here:
Array
(
[0] => Array
(
[pk] => 209
[category_id] => 7
[id] => 0
[score] => 0.40750848701418
)
[1] => Array
(
[pk] => 225
[category_id] => 7
[id] => 3
[score] => 0.30750848701619
)
[2] => Array
(
[pk] => 211
[category_id] => 8 ====>>> WRONG!!!
[id] => 2
[score] => 0.37152213415004
)
)
Can you do a Query search on the category_id = 7 only??
Thanks in advance.
I had solved this problem by using Zend Query Parsing
$strQuery = Zend_Search_Lucene_Search_QueryParser::parse('java lucene');
$cateTerm = new Zend_Search_Lucene_Index_Term(7 , 'category_id');
$cateQuery = new Zend_Search_Lucene_Search_Query_Term($cateTerm);
$query = new Zend_Search_Lucene_Search_Query_Boolean();
$query->addSubquery($strQuery, true /* required */);
$query->addSubquery($cateQuery, true /* required */);
Results will be only in category_id = 7 :)
You can remove the AND +category_id:7 from you query, what you want is a filter since +category_id:7 is not needed as a ranked value.
I don't know how to implement it with Zend_Lucene but in solr I used to pass fq parameter, this may give you a hint :)
Filtering is a process that constrains the search space and allows only a subset of documents to be considered for search hits. You can use this feature to implement search-within-search results. Lucene comes with various built-in filters such as BooleanFilter, CachingWrapperFilter, ChainedFilter, DuplicateFilter, PrefixFilter, QueryWrapperFilter, RangeFilter, RemoteCachingWrapperFilter, SpanFilter, etc.(THE NATIVE JAVA VERSION) Filter can be passed to IndexSearcher's search method to filter documents that match the filter criteria.

Categories