Update Product Name, Description, Short Description in Magento - sql

The solution for this was almost provided in this answer https://stackoverflow.com/a/14249171
It does indeed replace the product name properly.
But I needed to take it a step further and check the productname, description and short description to replace 'example' with 'test' in all three areas. I wasn't sure if it was possible to modify the current script provided to include these other attributes.

this do the trick :
$newName = str_replace('example','test',$product->getName());
$product->setName($newName);
Find it and add the other attributes :
$newDescription = str_replace('example','test',$product->getDescription());
$product->setDescription($newDescription);
$newShortDescription = str_replace('example','test',$product->getShortDescription());
$product->setShortDescription($newShortDescription);
Then save each attribute like this :
$product->getResource()->saveAttribute($product,'description');
$product->getResource()->saveAttribute($product,'short_description');
Or just save the product (time and resource consuming)
$product->save();
To select only product having example in name OR description OR short_desc use this
-addAttributeToFilter(array(array('attribute'=>'name','like'=>'%example%'), array('attribute'=>'description','like'=>'%example%'),array('attribute'=>'short_description','like'=>'%example%')))
Instead of
->addAttributeToFilter('name',array('like','%example%'))

Related

How can I link RSEG table into BSEG or RBKP to BSEG?

I already browse the web but i find no answer that can solve my problem.
I tried the concatenation of RBKP-BELNR and RBKP-GJAHR into BKPF-AWKEY to get the BKPF-BELNR then BKPF-BELNR to BSEG-BELNR, but always show no records.
I need to link to the RSEG to BSEG or RBKP to BSEG .
Need some help! thanks!
Edit: I made the parked document in Tcode MIR7
I found this, but can't enter to VBSEGS table.
UPDATE: these are the details I want to get. but can't find the other details
Concatenate BELNR & GJAHR from RSEG and pass it to the AWKEY field of BKPF table and you will get Accounting document number "BELNR", year "GJAHR" & Company Code "BUKRS". Pass these fields to BSEG and you will get the other details. Did you try it exactly this way? You should check your belnr has left padding '0' you can check it with double click on the record in SE16n tcode.
Actually, you can directly link these table.
Last option, If these are still not working for you, then you can link: However, it will kill the performance, I believe.
RSEG-EBELN = BSEG-EBELN
RSEG-EBELP = BSEG-EBELP
RSEG-MATNR = BSEG-MATNR
I think is this:
RSEG-LFBNR = BSEG-BELNR
RSEG-LFGJA = BSEG-GJAHR
RSEG-LFPOS = BSEG-BUZEI

Odoo: get type of field by name

in odoo you can get value of field by it's str name:
exm:
name = getattr(self, 'name')
what i want now is to know the type of field name is it :
fields.Char, fields.Many2one, fields.Many2many .....
so what i need is something like this
gettype(self, 'user_id')
is there a way to now what is the type of field in odoo?
You can search from ir.model.fields model.
ir_model_obj=self.env['ir.model.fields']
ir_model_field=ir_model_obj.search([('model','=',model),('name','=',field)])
field_type=ir_model_field.ttype
if field_type=='many2one':
print "do operation"
This may help you.
Odoo provides this information in the _fields attribute, I think It's better because every thing happens In the Python side no need for contacting the database, especially In my case my model have more than 30 fields :
for name, field in self._fields.iteritems():
if not isinstance(field, (fields.Many2one, fields.Many2many, fields.One2many)):
# logic go here
If you you want to verify just one fields:
if not isinstance(self._fields[field_name], (fields.Many2one, ...)): # do something

eBay API aspectFilter with MaxPrice parameter returns 0 results

I am using the following URL to fetch car listing. But when I add the MaxPrice parameter It shows 0 items. But on the site there are 12 items that have price below my value.
http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsAdvanced&SERVICE-VERSION=1.12.0&SERVICE-NAME=FindingService&SECURITY-APPNAME=prosoftda-d112-4c99-9bec-8a09c902a7a&RESPONSE-DATA-FORMAT=JSON&paginationInput.entriesPerPage=50&categoryId=6001&outputSelector=PictureURLSuperSize&REST-PAYLOAD=true
&aspectFilter(0).aspectName=Make&aspectFilter(0).aspectValueName=Audi
&aspectFilter(1).aspectName=Model&aspectFilter(1).aspectValueName=Q7
&aspectFilter(2).aspectName=Model+Year&aspectFilter(2).aspectValueName=2013
&aspectFilter(3).aspectName=MaxPrice&aspectFilter(3).aspectValueName=50000.00
When I remove MaxPrice parameter the URL works perfectly.
Btw, I got the solution for this question:
To pass the price value need to pass as ItemFilter. not with the AspectFilter.
I replace the string :
&aspectFilter(3).aspectName=MaxPrice&aspectFilter(3).aspectValueName=50000.00
By the string :
&itemFilter(0).name=MaxPrice&itemFilter(0).value=500000.00
So It works now. As Price parameter is related to attribute so need to pass with the ItemFilter.
So final URL Is:
http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsAdvanced&SERVICE-VERSION=1.12.0&SERVICE-NAME=FindingService&SECURITY-APPNAME=prosoftda-d112-4c99-9bec-8a09c902a7a&RESPONSE-DATA-FORMAT=JSON&paginationInput.entriesPerPage=50&categoryId=6001&outputSelector=PictureURLSuperSize&REST-PAYLOAD=true
&aspectFilter(0).aspectName=Make&aspectFilter(0).aspectValueName=Audi
&aspectFilter(1).aspectName=Model&aspectFilter(1).aspectValueName=Q7
&aspectFilter(2).aspectName=Model+Year&aspectFilter(2).aspectValueName=2013
&itemFilter(0).name=MaxPrice&itemFilter(0).value=500000.00
Thanks. may be this can help someone who is finding the same question.
I have no experience with this API so this is just a shot in the dark. But I found this link:
http://developer.ebay.com/DevZone/finding/CallRef/findItemsAdvanced.html
From what Ive read within that MaxPrice is more of an "itemFilter" (things such as maxPrice, bestOfferOnly, featuredSeller) than an "aspectFilter" (things such as Make, Model, Optical Zoom).
Further down it also states that some itemFilters need a paramName, such as maxPrice
For example, if you use the MaxPrice itemFilter, you will need to specify
a parameter Name of Currency with a parameter Value that specifies the type
of currency desired.
Again never used this API but seems relevant to me.

show product list by store id magento

I have problem to show product list on magento. My current code only shows filter by category:
Example:
{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" category_id="18" template="catalog/product/list.phtml"}}
I only want it to filter by store id
{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" store_id="4" template="catalog/product/list.phtml"}}
This doesn't work.
Any suggestions?
That won't work. You will need to modify / override the product listing block.
copy
/app/code/core/Mage/Catalog/Block/Product/List.php
to
/app/code/local/Mage/Catalog/Block/Product/List.php
You would need to modify _getProductCollection()
You could add something like this
if($this->getStoreId()) {
$this->_productCollection->addStoreFilter($this->getStoreId());
}
$this->getStoreId() will pull through the value you use in your tag: store_id="3"

Magento Bulk update attributes

I am missing the SQL out of this to Bulk update attributes by SKU/UPC.
Running EE1.10 FYI
I have all the rest of the code working but I"m not sure the who/what/why of
actually updating our attributes, and haven't been able to find them, my logic
is
Open a CSV and grab all skus and associated attrib into a 2d array
Parse the SKU into an entity_id
Take the entity_id and the attribute and run updates until finished
Take the rest of the day of since its Friday
Here's my (almost finished) code, I would GREATLY appreciate some help.
/**
* FUNCTION: updateAttrib
*
* REQS: $db_magento
* Session resource
*
* REQS: entity_id
* Product entity value
*
* REQS: $attrib
* Attribute to alter
*
*/
See my response for working production code. Hope this helps someone in the Magento community.
While this may technically work, the code you have written is just about the last way you should do this.
In Magento, you really should be using the models provided by the code and not write database queries on your own.
In your case, if you need to update attributes for 1 or many products, there is a way for you to do that very quickly (and pretty safely).
If you look in: /app/code/core/Mage/Adminhtml/controllers/Catalog/Product/Action/AttributeController.php you will find that this controller is dedicated to updating multiple products quickly.
If you look in the saveAction() function you will find the following line of code:
Mage::getSingleton('catalog/product_action')
->updateAttributes($this->_getHelper()->getProductIds(), $attributesData, $storeId);
This code is responsible for updating all the product IDs you want, only the changed attributes for any single store at a time.
The first parameter is basically an array of Product IDs. If you only want to update a single product, just put it in an array.
The second parameter is an array that contains the attributes you want to update for the given products. For example if you wanted to update price to $10 and weight to 5, you would pass the following array:
array('price' => 10.00, 'weight' => 5)
Then finally, the third and final attribute is the store ID you want these updates to happen to. Most likely this number will either be 1 or 0.
I would play around with this function call and use this instead of writing and maintaining your own database queries.
General Update Query will be like:
UPDATE
catalog_product_entity_[backend_type] cpex
SET
cpex.value = ?
WHERE cpex.attribute_id = ?
AND cpex.entity_id = ?
In order to find the [backend_type] associated with the attribute:
SELECT
  backend_type
FROM
  eav_attribute
WHERE entity_type_id =
  (SELECT
    entity_type_id
  FROM
    eav_entity_type
  WHERE entity_type_code = 'catalog_product')
AND attribute_id = ?
You can get more info from the following blog article:
http://www.blog.magepsycho.com/magento-eav-structure-role-of-eav_attributes-backend_type-field/
Hope this helps you.