I am adding an item using the following code:
$some_data = array(
'attributes' => array(
6 => $domainName,
1 => $domain->oid,
2 => 705,
7 => 706,
8 => '',
9 => '',
10 => '',
11 => '',
),
);
$some_data = serialize($some_data);
uc_cart_add_item(
$domainProductNID,
1,
$some_data
);
It adds the item to the cart, with the correct configuration. However, if I then go to /cart and click on "remove", the item stays there. I am only able to remove it with:
uc_cart_empty();
Any idea why?
UPDATE
Removing the $some_data attribute and instead running:
uc_cart_add_item(
$domainProductNID,
1
);
Does in fact work... so it must have something to do with the attributes being submitted.
This solved my problem:
$domainProductNID = 27;
$form_state = array(
'values' => array(
'nid' => $domainProductNID,
'qty' => 1,
'attributes' => array(
6 => $domainName,
1 => $domain->oid,
2 => 705,
7 => 706,
8 => '',
9 => '',
10 => '',
11 => '',
)
),
);
$node = node_load($domainProductNID);
drupal_form_submit("uc_product_add_to_cart_form", $form_state, $node);
Hope it helps someone else...
Related
I have installed the Drupal 7 feeds module and created an Importer.
I can display the Stand-alone form, add a file but the upload / parse page just displays the message "Importing..." It doesn't do much else and does not import into a selected content type. No errors are displayed.
Any ideas?
// Importer below /////////////////////////////////////////////////////////
$feeds_importer = new stdClass();
$feeds_importer->disabled = FALSE;
$feeds_importer->api_version = 1;
$feeds_importer->id = 'shop_ids';
$feeds_importer->config = array(
'name' => 'Shop IDs',
'description' => 'Import a CSV file which feeds into Shop ID node type',
'fetcher' => array(
'plugin_key' => 'FeedsFileFetcher',
'config' => array(
'allowed_extensions' => 'txt csv tsv xml opml',
'direct' => 0,
'directory' => 'public://feeds',
'allowed_schemes' => array(
'public' => 'public',
'private' => 'private',
),
),
),
'parser' => array(
'plugin_key' => 'FeedsCSVParser',
'config' => array(
'delimiter' => ',',
'no_headers' => 1,
),
),
'processor' => array(
'plugin_key' => 'FeedsNodeProcessor',
'config' => array(
'expire' => '-1',
'author' => 0,
'authorize' => 1,
'mappings' => array(
0 => array(
'source' => '\'0\'',
'target' => 'title',
'unique' => 1,
),
1 => array(
'source' => '\'1\'',
'target' => 'body',
'unique' => FALSE,
),
),
'update_existing' => '1',
'input_format' => 'plain_text',
'skip_hash_check' => 0,
'bundle' => 'shop_ids',
),
),
'content_type' => '',
'update' => 0,
'import_period' => '-1',
'expire_period' => 3600,
'import_on_create' => 1,
'process_in_background' => 0,
);
Looks like there was an error with batch.js
JQuery causing function error
fix was to add ; to beginning of code.
;(function ($) {
and add the (jQuery); to the end of the file...
})(jQuery);
I've followed this great document which successfully creates a webform and associated components.
I am trying to adjust the code so it works for existing webforms instead of creating new ones.
My code is as follows:
$nid = 12;
$node = node_load(12);
// Create the webform components.
$components = array(
array(
'name' => 'Gender',
'form_key' => 'gender',
'type' => 'select',
'mandatory' => 1,
'weight' => 0,
'pid' => 0,
'extra' => array(
'title_display' => 'inline',
'private' => 0,
'items' => "Mrs|Mrs\nMiss|Miss\nMr|Mr",
'aslist' => 1,
),
),
);
// Setup notification email.
$emails = array(
array(
'email' => 'somebody#example.tld',
'subject' => 'default',
'from_name' => 'default',
'from_address' => 'default',
'template' => 'default',
'excluded_components' => array(),
),
);
// Attach the webform to the node.
$node->webform = array(
'confirmation' => '',
'confirmation_format' => NULL,
'redirect_url' => '<confirmation>',
'status' => '1',
'block' => '0',
'teaser' => '0',
'allow_draft' => '0',
'auto_save' => '0',
'submit_notice' => '1',
'submit_text' => '',
'submit_limit' => '-1', // User can submit more than once.
'submit_interval' => '-1',
'total_submit_limit' => '-1',
'total_submit_interval' => '-1',
'record_exists' => TRUE,
'roles' => array(
0 => '1', // Anonymous user can submit this webform.
),
'emails' => $emails,
'components' => $components,
);
// Save the node.
node_save($node);
When I attempt to execute my code I get the following error:
Error message SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'nid' cannot be null
First try to print all the available values of $node.
echo "<pre>";
print_r($node);
echo "</pre>"'
exit;
check that you are getting value for $node[nid] or not.
I have a model, Comment, that belongsto Module, Photo, Review, Article, and User. In turn, each of those models havemany Comment.
User belongsto Avatar and Avatar hasmany User
In the code below I successfully retrieve the latest 5 comments regardless of what model they come from (Photo, Article, Review) and I display some information about the User (username, online status).
$recentComments = $this->find('all',
array(
'limit' => '5',
'order' => array('Comment.id' => 'desc'),
'conditions' => array(
'Comment.page_id' => $page_id
),
'contain' => array(
'Photo' => array(
'fields' => array('Photo.id'),
'conditions' => array(
'Comment.module_id' => 8
),
),
'Review' => array(
'fields' => array('Review.title', 'Review.id'),
'conditions' => array(
'Comment.module_id' => 2
),
),
'Article' => array(
'fields' => array('Article.title', 'Article.id'),
'conditions' => array(
'Comment.module_id' => 3
),
),
'Module' => array(
'fields' => array('Module.model', 'Module.post_title'),
),
'User' => array(
'fields' => array('User.username', 'User.online'),
),
)
));
Unfortunately there are some issues with this. As you can see above I don't contain User->Avatar and all expected data is retrieved successfully.
$recentComments = Array
(
[0] => Array
(
[Comment] => Array
(
[id] => 179
[page_id] => 2
[module_id] => 3
[page] =>
[user_id] => 29
[post_id] => 9
[title] => test comment for article 9
[content] => here is the content for the comment
[created] => 2013-04-24 00:00:00
[redeemed] => 0
[status] => 0
)
[User] => Array
(
[username] => bowlerae
[online] => 0
)
[Module] => Array
(
[model] => Article
[post_title] => title
)
[Article] => Array
(
[title] => Test title for article 9
[id] => 9
[likes] => 0
[dislikes] => 0
[comments] => 2
)
[Photo] => Array
(
[id] =>
)
[Review] => Array
(
[title] =>
[id] =>
)
)
However, if I DO contain User->Avatar like this...
'User' => array(
'fields' => array('User.username', 'User.online'),
'Avatar' => array(
'fields' => array('Avatar.file')
)
),
Then the recursion basically becomes unlimited, ALL models related to Comment, User, Module, Article, Photo and Review are also retrieved which is A LOT.
Can anyone explain why this is happening? I will be happy to submit more code from some of the models if needed but I don't see any issues there.
Take a look at another example that works successfully...Below I am retrieving the 5 most recent articles. All information including the user Avatar is successfully retreived.
$this->set('articles_sidebar', ClassRegistry::init('Article')->find('all',
array(
'limit' => '5',
'order' => array('Article.id' => 'desc'),
'conditions' => array('
Article.page_id' => $page_id
),
'contain' => array(
'User' => array(
'fields' => array('User.username', 'User.online'),
'Avatar' => array(
'fields' => array('Avatar.file')
)
),
)
)));
Please note these two finds are performed in the AppController in the beforeRender given that $page_id > 0. $page_id is set in whatever the current controller is. I know people would probably ask about it but that's not what the issue is as I mentioned that example 2 retrieving the recent articles currently works.
EDIT: I discovered that it has something to do with my afterfind callback in the Article model. Is there a way I can tweak the queries in the afterfind and/or the $recentComments query so that they still work without breaking my contain? I don't need the likes, dislikes or comments virtual fields in my $recentComments query which is why they are not listed as one of the contained fields.
function afterFind($results, $primary = false) {
parent::afterFind($results, $primary);
foreach($results as $key => $val){
if (isset($val['Article']['id'])){
$results[$key]['Article']['likes'] = $this->Like->find('count', array('conditions' => array('Like.post_id' => $results[$key]['Article']['id'], 'Like.module_id' => 3, 'Like.status' => 0)));
$results[$key]['Article']['dislikes'] = $this->Like->find('count', array('conditions' => array('Like.post_id' => $results[$key]['Article']['id'], 'Like.module_id' => 3, 'Like.status' => 1)));
$results[$key]['Article']['comments'] = $this->Comment->find('count', array('conditions' => array('Comment.post_id' => $results[$key]['Article']['id'], 'Comment.module_id' => 3, 'Comment.status < 2')));
}
} // end for each
return $results;
} // end afterfind
My guess is your problem is this:
When using ‘fields’ and ‘contain’ options - be careful to include all
foreign keys that your query directly or indirectly requires.
Make sure you're including whatever field(s) are used to join User and Avatar models.
(read here)
For now I changed (in the Article model afterFind)
if (isset($val['Article']['id']))
to
if (isset($val['Article']['id']) && $val == "article")
Seems to be working in current controller but need further testing. Is there a better solution?
Ok i think i did this wrong.
This is my current collection however I need to order these by percentage.
array (
'_id' => new MongoId("505006de36314b4b27000001"),
'status' => 'pending',
'store_id' => new MongoId("505006de36314b4b27000000"),
'minspendone' => '50.00',
'cashbackone' => '1.50',
'percentageone'▼ => '0.03',
'minspendtwo' => '100.00',
'cashbacktwo' => '3.00',
'percentagetwo' => '0.03',
'minspendthree' => '',
'cashbackthree' => '',
'percentagethree' => '',
'minspendfour' => '',
'cashbackfour' => '',
'percentagefour' => '',
)
so would I better of changing it to the following
array (
'_id' => new MongoId("505006de36314b4b27000001"),
'status' => 'pending',
'store_id' => new MongoId("505006de36314b4b27000000"),
'offers' => array(
'minspend' => '50.00',
'cashback' => '1.50',
'percentage' => '0.03'),
array(
'minspend' => '100.00',
'cashback' => '3.00',
'percentage' => '0.03'))
)
could someone please advise me.
Russell,
If you wish to use the mongodb internal sort function you will need to split the array elements into separate documents.
Mongodb sort works to set the order of whole documents returned, rather the return order of elements within documents.
Hope that clarifies.
view/plans/index.ctp
<?php debug($plans); ?>
controllers/plans_controller.php (index function)
function index() {
$plansC = $this->Plan->find('all',
array('contain' => array('PlanDetail' => array('fields' => array('id',
'effective_date',
'expiration_date',
'active',
'name',
'plan_type_id',
'max_benefit',
'deductible',
'preventive',
'basic',
'major',
'ortho',
'company_id',
'plan_type_id',
'plan_detail_note_id'),
'Company' => array('fields' => array(
'id',
'company_logo_url'
)),
'PlanType' => array('fields' => array(
'id',
'name'
))
))));
debug($plansC);
$this->set('plans',$this->paginate($planC));
Here is a sample index() debug record from the plans_controller.php (as you can see all data is being contained properly using containable):
[0] => Array
(
[Plan] => Array
(
[id] => 7
[created] => 2011-01-10 14:11:40
[modified] => 2011-02-03 18:35:29
[plan_detail_id] => 32
[monthly_cost] => 25.49
[dental_cost] => 0.00
[age_id] => 2
[applicant_id] => 1
[state_id] => 1
)
[PlanDetail] => Array
(
[id] => 32
[effective_date] => 2011-01-10 14:07:00
[expiration_date] => 2011-01-10 14:07:00
[active] => 1
[name] => Classic 1500
[plan_type_id] => 2
[max_benefit] => 0.00
[deductible] => $75/year
[preventive] => 90%
[basic] => 75%
[major] => 50%
[ortho] =>
N/A
[company_id] => 4
[plan_detail_note_id] => 9
[Company] => Array
(
[id] => 4
[company_logo_url] => nationwide_logo.png
)
[PlanType] => Array
(
[id] => 2
[name] => Indemnity
)
)
)
The containable data is not being passed. Only data associated with Plan and PlanDetail (no deeper relations than PlanDetail such as Company or Plan type), but the debug in the index controller shows all data being passed! But none of this data is making it into the view debug???
Does anyone know if this is a bug with containable?
You must either paginate or find, you can't paginate the found data array. Pagination is retrieving data from the database. Replace your find call with a paginate call. Save the result of the paginate call in a variable and debug it, your problem is there, not in the set call.
After 8 hours pain, I solved it : ) and I added pagination to boot. I ended up using compact() in place of the baked set().
function index() {
//$this->Plan->find('all'); not needed
$this->paginate['Plan'] = array('contain' => array('PlanDetail' => array('fields' => array('id',
'effective_date',
'expiration_date',
'active',
'name',
'plan_type_id',
'max_benefit',
'deductible',
'preventive',
'basic',
'major',
'ortho',
'application_url',
'company_id',
'plan_type_id',
'plan_detail_note_id'),
'Company' => array('fields' => array(
'id',
'company_logo_url'
)),
'PlanType' => array('fields' => array(
'id',
'name'
))
)));
$plans = $this->paginate('Plan');
$this->set(compact('plans'));
}