As the title says. I don't want the ID of the current website, I want the ID of any website by supplying only that websites name.
I have this code:
$siteModel = Mage::getResourceModel( 'core/website_collection' )->addFieldToFilter( 'name', $site )->getFirstItem();
$siteId = $siteModel->getId();
But $siteId ends up empty.
If all I have is the name of a website, how do I get its IDs?
Many thanks.
You need debug the collection by ->getSelect()->__toString()
for checking it give right value or not.
$siteModelCollection = Mage::getResourceModel( 'core/website_collection' )->addFieldToFilter( 'name', $site );
// print the Query
echo $Query = $siteModelCollection ->getSelect()->__toString();
echo $siteId =$siteModelCollection->getFirstItem()->getId();
Update:
Use load():
for this case you need to call load() function of resource model of core/website for getting proper collection
Now you can get id of first store by using below code:
$siteModelCollection = Mage::getResourceModel('core/website_collection')->load()->addFieldToFilter( 'name', $site);
echo $Query = $siteModelCollection ->getSelect()->__toString();
echo $siteId =$siteModelCollection->getFirstItem()->getId();
You use addFieldToFilter method incorrectly.
Try this approach:
$website = Mage::getModel('core/website')
->getCollection()
->addFieldToFilter('name', array('eq', $siteName))
->getFirstItem();
$websiteId = $website->getId();
Related
I am sending a AJAx request to the server to query for all "properties" that are related to a certain category "destination".
The field in the entry is called Destination with the handle "destinationCategories"
My code currently looks like this;
public function actionGetLocation()
{
$locationId = craft()->request->getParam('id');
// Find the Actual Category Object from The DB, I did this just in case I need to query based on title, or something else
// The correct category is being returned
$criteria = craft()->elements->getCriteria(ElementType::Category);
$criteria->id = $locationId;
$criteria->limit = null;
$selectedCategory = $criteria->first();
unset($criteria);
$criteria = craft()->elements->getCriteria(ElementType::Entry);
// I am now attempting to query for
// destinationCategories = the category that I have queried from the DB
$criteria->destinationCategories = $selectedCategory->id;
$criteria->limit = null;
$properties = $criteria->find();
var_dump($properties);
foreach($properties as $property)
{
echo $property->title;
}
exit;
return $this->returnJson(array('status' => 'ok', 'options' => $subCategories));
}
The query is returning null even when results are available
Where am i going wrong I have tried
$criteria->destinationCategories = $selectedCategory->id;
$criteria->destinationCategories = $selectedCategory->title;
$criteria->destinationCategories = $selectedCategory->slug;
I guess you would have completed this project till now :) but to solve this could you try not to unset $criteria until you use any depending variable. Once your usage is done unset the variable.
I want to apply search filters in my project. I have options tables where options are being saved with the option values with parent id of option id. For example brand is saving as option with parent id set to 0 and all brands have brand id as their parent id set and while saving product I am saving product options in product_options table. Now i want to apply filters in product listing page. I am using following code for filtration:
$conditions = array();
$product_options = $this->ProductOption->find('list',array('fields'=>array('product_id'),'conditions'=>array('ProductOption.option_value_id'=>$data['data']['options'])));
$conditions = array_merge($conditions,array('Product.id'=>array_unique($product_options)));
$prod_info = $this->paginate('Product',$conditions);
$this->set(compact('prod_info'));
When I search any product with their brand name it works fine but if I try to search with the price (also an option) then it gives other brand products also which have price equal to filter price option. Please check following link to understand problem correctly.
http://primemart.in/Food-Processors-Ii4zRGAKYAo=
Please anyone help me to come out my problem.
Thanks.
Please have a look on my code which I used to pass conditions in and to get results
$product_options = $this->ProductOption->find('list',array(
'fields'=>array('product_id'),
'conditions'=>array('ProductOption.option_value_id'=>$data['data']['options'])
));
//$this->Option->unBindModel(array('belongsTo'=>'Product'));
$product_options = $this->Option->find('all', array(
'conditions'=>array('Option.id'=>$data['data']['options'])
));
//pr($product_options);
$opt_arr = array();
foreach ($product_options as $op) {
$opt_arr[$op['Option']['parent_id']][] = $op['Option']['id'];
}
$conditions_arr = array();
foreach($opt_arr as $opt) {
$key_arr = array();
foreach($opt as $op) {
$key_arr['OR']['ProductOption.option_value_id'][] = $op;
}
$conditions_arr['AND'][] = $key_arr;
}
$pr_options = $this->ProductOption->find('list', array(
'conditions'=>$conditions_arr,
'fields'=>array('product_id')
));
$conditions = array_merge($conditions, array('Product.id'=>array_unique($pr_options)));
I would try code bellow. I assume that $conditions constist of the other conditions you mention in your question.
$conditions = ... // other conditions you mentioned
$conditions = array('AND'=>array($conditions, array('Product.id'=>array_unique($product_options))));
$prod_info = $this->paginate('Product',$conditions);
So I have
$attribute_option_id = Mage::getResourceModel('catalog/product')
->getAttributeRawValue($productId, 'my_attribute', $storeId);
This gives me something like $attribute_option_id = 12345
Now how do I get the (text) value for this id?
Thanks
This should work.
$product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($productId);
$text = $product->getAttributeText('my_attribute');
[EDIT]
If you don't want to load the full product you can do a sneaky think. Impersonate a product.
So you get the option id like you already do
$attribute_option_id = Mage::getResourceModel('catalog/product')->getAttributeRawValue($productId, 'my_attribute', $storeId);
Then create just an empty instance of the product and set some attributes to it.
$product = Mage::getModel('catalog/product')
->setStoreId($storeId)
->setData('my_attribute', $attribute_option_id);//the result from above
$text = $product->getAttributeText('my_attribute');
There is already a confirmation that this works. See it here.
Here is a method that is a different approach that works for me.
Assume Known: $_current_productid
$_Current_OptionId = Mage::getResourceModel('catalog/product')->getAttributeRawValue($_current_productid, $attribute_id,$store_id);
$_write = Mage::getSingleton('core/resource')->getConnection('core_write');
// now $_write is an instance of Zend_Db_Adapter_Abstract
$_readresult=$_write->query("SELECT value FROM eav_attribute_option_value WHERE option_id ='".$_Current_OptionId."'");
while ($row = $_readresult->fetch() ) {$_Current_OptionValue=$row['value'];}
Hi I want to get order collection with multiple field values for same field.Already I tried to get the collections with addFieldToFilter for individual field values('status':pening & 'status':processing) and I merged both the collecions to a single collection.Now I'm getting problem like I can't able to access the resulted collection, its troughs error like getMethod can't call on non object.Give me any suggestions.
Here is my code :
$shippedCollection = array();
$processingCollection = array();
$orderSCollection = Mage::getModel('sales/order')->getCollection();
$shippedCollection = $orderSCollection->addFieldToFilter('status','delivered_carrier');
$orderPCollection = Mage::getModel('sales/order')->getCollection();
$processingCollection = $orderPCollection->addFieldToFilter('status','processing');
$order = array_merge($shippedCollection->getAllIds(),$processingCollection->getAllIds());
$order->getData('increment_id');
Hello check below code may be help you
$order_collection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('status', array('in' => array('delivered_carrier','pending')));
echo count($order_collection->getAllIds());
I've been trying all night to update a record like this:
$r = $this->Question->read(NULL, $question['Question']['id']);
debug($r);// This is a complete Question array
$this->Question->set('status', 'version');
$s = $this->Question->save();
//$s = $this->Question->save($r['Question']);//this also doesn't work
debug($s); // = False every time!! Why??
exit;
The two comments show variations I've tried but didn't work either.
#Dipesh:
$this->data = $this->Question->read(NULL, $question['Question']['id']);
$this->Question->status = 'version';
$s = $this->Question->save($this->data);
debug($s);
exit;
#Dipesh II:
$this->request->data = $this->Question->read(NULL, $question['Question']['id']);
debug($this->data);
//$this->Question->status = 'version';
$this->request->data['Question']['status'] = 'version';
$s = $this->Question->save($this->request->data);
//$s = $this->Question->save($r['Question']);
debug($s);
exit;
#Dipesh III:
(removed)
cakePHP provide a method called set() in both Models::set() as well as in Controller::set();
About Controller::set()
This method is used to set variables for view level from any of the controller method. For example fetching records and from models and setting them for views to display it to clients, like this
$data = $this->{ModelName}->find('first');
$this->set('dataForView',$data) // now you can access $data in your view as $dataForView
About Model::set()
This method is used to set data upon a model, the format of the array that will be passed must be same as that used in Model::save() method i.e. like this
$dataFormModel = array('ModelName'=>array('col_name'=>$colValue));
$this->{ModelName}->set($dataForModel);
Model::set() will accept its parameter only in this format, once successfully set you can do following
validate this data against the validation rules specified in model directly like this
$isValid = $this->ModelName->validate();
save/update data by calling Model::save()
Use $this->data instead of $r
Example
$this->data = $this->Question->read(NULL, $question['Question']['id']);
$this->set is used to set variable value and pass it to view so view can access it where as $this->data represent the data to be stored in database.
If You're using Cake 2.0 then replace $this->data which is read only in Cake 2.0 to $this->request->data.
It's not very "automagical" but I was able to get this working like this:
$set_perm_id = 42;//who cares
$data = array(
'Question'=> array(
'id'=> $question['Question']['id'],
'perm_id'=> $set_perm_id,
'status'=>'version'
)
);
$s=$this->Question->save($data);
Basically I'm just building the data array manually. If anyone knows why this works instead of what I was doing before, I'd love to hear it.
Just try these lines..
$this->Question->id = $question['Question']['id'];
$this->Question->set('status','version');
$this->Question->save();
OR
$aUpdate["id"] = $question['Question']['id'];
$aUpdate["status"] = "version";
$this->Question->save($aUpdate);