The concept of our project is, area wise products filtering, the products may be same or different. If the admin change the price of the product for particular area, then the price should change only that corresponding area.
For that, we have created new table as like oc_product_to_category with following new fields price,quantity,offer.
if the new table has the price value means then use that value for the process, if else means use default price value at the oc_product table. Upto category page we have successfully implemented this concept,
Category.php:
$this->load->model('mobile/product');
$price_by_category = $this->model_mobile_product->getpricebycategory($result['product_id'],$category_id);
if($price_by_category['price'] != ""){
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
'price' => "Rs.".$price_by_category['price'].".00",
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $result['rating'],
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
);;
}else{
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $result['rating'],
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
);
}
At cart , it takes the default price table value. If I create new function means, i have to change whole cart operation but i only want to change the price calculation, Based on the area id and product id.
I hope someone will give the solution.
Thanks..
There's no need to repeat the entire block for category.php. You can simply re-assign the price before adding to the array like $price = $price_by_category['price'] ?: $price.
To load your model in cart.php you can do it like this. In the __contruct block add:
public function __construct($registry) {
$this->registry = $registry;
Then in the getProducts() method you can load your model:
$this->load->model('mobile/product');
$mobileProduct = $this->registry->get('model_mobile_product');
$price_by_category = $mobileProduct->getpricebycategory($product_id,$category_id);
Of course the challenge here is you will need to add category data to the cart array when customer adds product to cart so you will be able to reference this later. My suggestion would be to encode it as a third slice in the cart session. Normally products look like this:
product-id:serialized-option-data:profile-id
So you can add another slice to store category id when adding to cart:
product-id:serialized-option-data:profile-id:category_id
Then afterward:
if (!empty($product[3])) {
$category_id = $product[3];
} else {
$category_id = 0;
}
You will also need to send category_id as POST data to controller/checkout/cart -> add() and then again pass it to system/library/cart.php to be encoded into the cart array.
Related
I need to display Mail subject in Related tab Grid of Lead module
I have checked getRelationQuery() function in that I got a subject, but while on the EmailRelatedlist.tpl file, the subject data is not displayed.
How we can display the Subject on the Related tab?
can you please go to below file and change below code
modules\Emails\Emails.php
var $list_fields = Array(
'Subject' => Array('activity' => 'subject'),
'Related to' => Array('seactivityrel' => 'parent_id'),
'Date Sent' => Array('activity' => 'date_start'),
'Time Sent' => Array('activity' => 'time_start'),
'Assigned To' => Array('crmentity', 'smownerid'),
'Access Count' => Array('email_track', 'access_count')
);
var $list_fields_name = Array(
'Subject' => 'subject',
'Related to' => 'parent_id',
'Date Sent' => 'date_start',
'Time Sent' => 'time_start',
'Assigned To' => 'assigned_user_id',
'Access Count' => 'access_count'
);
I have a problem validating if my user checked at least one option from a list of checkboxes.
Here is what i tried:
My view looks like this:
echo $this->Form->input('market_segment_targeted', array(
'multiple' => 'checkbox',
'label'=>array('text' => 'Market segment targeted', 'class'=>'w120'),
'options' => array(
'Home users' => 'Home users',
'SOHO' => 'SOHO',
'SMB' => 'SMB',
'Enterprise' => 'Enterprise'
),
));
In my controller i have added this snippet of code:
$validate_on_fly = array(
'market_segment_targeted' => array(
'notEmpty' => array(
'rule' => array('multiple', array('min' => 1)),
'required' => true,
'message' => 'Please select at least one!'
))
)));
$this->Partner->validate = Set::merge(
$this->Partner->validate,
$validate_on_fly
);
Any ideas what am i doing wrong?
Thank you
In CakePHP you can use Model Validation for checkboxes. Here is a quick example.
Your Form can look like:
$this->Form->create('User');
$this->Form->input('User.agree', array('type'=>'checkbox', 'hiddenField'=>false, 'value'=>'0'));
$this->Form->submit('Save'):
$this->Form->end();
Then in your Model under public $validate, use:
'agree'=>array(
'Not empty'=>array(
'rule'=>array('comparison', '!=', 0),
'required'=>true,
'message'=>'You must agree to the ToS'
)
)
I can't help myself and it's currently annoying, and yes, I used google a lot.
What I need:
A twitterlike follow button with the action to follow user.
What I already did:
Database
users table: id, username, password, ...
users_users table: id, user_id, follower_id
Code
In model User.php
public $hasAndBelongsToMany = array(
'Follower' => array(
'className' => 'User',
'joinTable' => 'users_users',
'foreignKey' => 'user_id',
'associationForeignKey' => 'follower_id',
'unique' => 'keepExisting',
)
);
In UsersController.php
public function follow() {
/*need help here*/
}
In Users\index.ctp
<?php if ($current_user['id'] != $user['User']['id']) echo $this->Html->link('Follow', array('action' => 'follow', $user['User']['id'])); ?>
Personally, I don't find hasAndBelongsToMany to be a good fit for situations like this. It's a good fit for when you want to display a list of checkboxes, or a select list, and allow the user to select/manage all their followings (or whatever the relationships might be) in one form.
It might just be my personal preference, but in situations like yours, where you're adding/deleting single links without worrying about any of the other links related to that user, I prefer to just create a separate 'Relationships' (or similarly named) Model / Controller, and consider the records as things in their own right, as opposed to just hasAndBelongsToMany links that are all sort of 'automagically' managed.
Here's how I'd do it:
Name your users_users table 'relationships'. And name the columns 'followed_by_id' and 'following_id' (or similar) to avoid any ambiguity as to which user is the follower / followee (if that was a word!).
In your users Model, you'd have these relationships:
var $hasMany = array(
'Followers' => array(
'className' => 'Relationship',
'foreignKey' => 'following_id',
'dependent'=> true
),
'FollowingUsers' => array(
'className' => 'Relationship',
'foreignKey' => 'followed_by_id',
'dependent'=> true
),
);
Then you'd have a Relationships model that looks something like this (the $belongsTo relationships are the important part):
<?php
class Relationship extends AppModel {
var $name = 'Relationship';
var $validate = array(
'followed_by_id' => array(
'numeric' => array(
'rule' => array('numeric'),
),
),
'following_id' => array(
'numeric' => array(
'rule' => array('numeric'),
),
),
);
var $belongsTo = array(
'FollowedBy' => array(
'className' => 'User',
'foreignKey' => 'followed_by_id'
),
'Following' => array(
'className' => 'User',
'foreignKey' => 'following_id'
)
);
}
?>
And then in your Relationships controller, you'd have something like this:
function add($following_id = null) {
$this->Relationship->create();
$this->Relationship->set('followed_by_id',$this->Auth->User('id'));
$this->Relationship->set('following_id',$following_id);
if ($this->Relationship->save($this->data)) {
// all good
} else {
// You could throw an error here if you want
$this->Session->setFlash(__('Error. Please, try again.', true));
}
$this->redirect($this->referer());
}
Then to add relationships, you obviously just call the add method of your relationships controller.
NOTE: Ideally, since adding a relationship is changing the database, it ideally shouldn't be done with a GET request accessed by a regular URL. It should be done via submitting a form via POST. I know that seems overkill when it's so easy to just do it via a regular link with GET. I haven't bothered to use forms/POST in this example - but if you want to stick to best practices, that's what you should do. See this for more info: https://softwareengineering.stackexchange.com/questions/188860/why-shouldnt-a-get-request-change-data-on-the-server
I have a Recipe, Item, and Units table/model. I have a HABTM relationship with Recipe and Item, and I get the default multiple-select box when adding/editing Recipe. (am using Bake for everything for the most part). The problem is I need to associate quantities and units with each Item.
Sample of UI I'm hoping for:
A big component of it is the ability to add/delete/edit the individual items. I imagine looking at the submitted form data, and using some jquery and clone would work. But I was wondering if someone already created a Behavior perhaps for this already?
Current Models (shortened to the relevant stuff, ie removed users/notes/etc):
class Item extends AppModel {
var $name = 'Item';
// id : int
// name : varchar
// unit_id : int
var $belongsTo = array(
'Unit' => array(
'className' => 'Unit',
'foreignKey' => 'unit_id'
),
);
var $hasAndBelongsToMany = array(
'Recipe' => array(
'className' => 'Recipe',
'joinTable' => 'recipes_items',
'foreignKey' => 'item_id',
'associationForeignKey' => 'recipe_id',
)
);
}
.
class Recipe extends AppModel {
var $name = 'recipe';
var $displayField = "name";
// id : int
// name : varchar
var $hasAndBelongsToMany = array(
'Item' => array(
'className' => 'Item',
'joinTable' => 'recipes_items',
'foreignKey' => 'recipe_id',
'associationForeignKey' => 'item_id',
)
);
}
.
class RecipesItem extends AppModel {
var $name = 'RecipesItem';
// id : int
// quantity : int
// unit_id : int
// recipe_id : int
// item_id : int
var $belongsTo = array(
'Unit' => array(
'className' => 'Unit',
'foreignKey' => 'unit_id'
),
'Recipe' => array(
'className' => 'Recipe',
'foreignKey' => 'recipe_id'
),
'Item' => array(
'className' => 'Item',
'foreignKey' => 'item_id'
)
);
}
Not quite sure what you're asking. For adding, editing and deleting items you would need create actions in your items controller. Saving association data (ie which Items a Recipe has) should be handled more-or-less automatically by the save() method in your controller action, assuming you have your forms set up correctly.
Out of curiosity, where did the RecipesItem model come from? What does that represent? If I am understanding you correctly, you have a Recipe model, and an Item model, with HABTM relationship. You shouldn't need a model for their join table, the recipes_items table just relates items from the two models.
that's not something Cake can do for you. Maybe there's some js that can helps you a bit, but you'll pretty much have to write your own javascript for that.
You have to use javascript to "transform" the select tag into something "cooler".
Here is the jquery-multiselect plugin which I use quite a bit. You can easily set it up to replace all of your multi selects with 1 line of code.
More info here:
http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/
I found a comment here: http://bakery.cakephp.org/articles/PHPdiddy/2006/10/06/custom-urls-from-the-site-root
That said:
Just change last line.
Router::connect('/',
array('controller' => 'members',
'action' => 'show'));
to
Router::connect('(?!admin|items|images)(.*)',
array('controller' => 'members', 'action' => 'show'));
Some people were able to get that to work... It didn't look quite right to me though so I tried the following, but still had no luck:
Router::connect('(?!/admin|/items|/images)(/.*)',
array('controller' => 'members','action' => 'show'));
In any case, the goal is to have a url like http://domainname/username , map to a users unique id. It works with /*, but I rather not use that method. Ideas?
Update to solution:
I used the selected answer below and added the following. It may be helpful to someone else.
$misc = array(*your misc webroot, admin route items here...*);
$notList = array_merge(Configure::listObjects('plugin'),Configure::listObjects('controller'));
$notListLowerCase = array();
foreach ($notList as $key=>$item):
$notListLowerCase[] = strtolower(preg_replace("/(.)([A-Z])/","\\1_\\2",$item));
endforeach;
$notList = array_merge($notList,$misc,$notListLowerCase);
$notList = implode('|', $notList);
Router::connect('/:username',
array(
'controller'=>'users',
'action'=>'view'
),
array(
'username' => '\b(?:(?!'.$notList.')\w)+\b'
)
);
Here ya go. You need to capture it as a param and then reference it in the regex. The username will be available in $this->params['username'] in the controller action.
Router::connect('/:username',
array(
'controller'=>'members',
'action'=>'show'
),
array(
'username' => '\b(?:(?!admin|items|images)\w)+\b'
)
);
$misc = array(*your misc webroot, admin route items here...*);
$notList = array_merge(App::objects('plugin'),str_replace('Controller','',App::objects('controller')));
$notListLowerCase = array();
foreach ($notList as $key=>$item):
$notListLowerCase[] = strtolower(preg_replace("/(.)([A-Z])/","\\1_\\2",$item));
endforeach;
$notList = array_merge($notList,$misc,$notListLowerCase);
$notList = implode('|', $notList);
Router::connect('/:username', array('controller' => 'members', 'action' => 'show'),array('pass'=>array('username'),'username'=>'\b(?:(?!'.$notList.')\w)+\b'));