Programatically add configurable products to cart in magento - magento-1.9

I want to add configurable products to cart for my mobile app for magento site. i have tried various solutions but fail to add. please help me. or suggest any rest api for add to cart functionality.

Please check product website id and current store website id whether they match or not.
Refer this file: core/mage/checkout/model/cart.php
$currentWebsiteId = Mage::app()->getStore()->getWebsiteId();
if (!$product
|| !$product->getId()
|| !is_array($product->getWebsiteIds())
|| !in_array($currentWebsiteId, $product->getWebsiteIds())
) {
Mage::throwException(Mage::helper('checkout')->__('The product could not be found.'));
}
return $product;

Related

Is there a way to create a list that auto populates with the the required articles?

I am a UI/UX designer and I have taken on a new project to overhaul our Zendesk. I have no experience but I am learning on the fly, I have already built a custom sidebar navigation and now my problem is this:
Is there a way to have the sidebar auto populate with the categories and articles from our knowledge base? I assume there is a way to do this, otherwise that would mean every time I upload a new document to our knowledge base I will also have to go back into the code and add the href with the link and title to the sidebar nav html and I'm certain that's not the way this works. I'm happy to do the research but I don't know what to search for, I've tried researching auto populating lists etc. but nothing matches my need. I can manually input every article into the side bar and it functions beautifully, I just figured there was an actual way to automate this once the code is input.
Thank you in advance,
-Newbie
Why are you adding a list manually, you can call API for all categories of your Help Centre and make a sidebar:
1). Add the below code to your script.js file at the bottom.
$.getJSON('/api/v2/help_center/categories/' , function(el){
console.log(el)
var _x = '';
$.each(el.categories, function (idx, itm){
_x += '' + itm.name + '<br>';
});
if("ul.categories"){
$(".categories").html(_x);
}
});
2). document_head.hbs should have jquery CDN.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
3). Add this HTML to your template where you want to show the categories.
Categories
The given solution is only for listing all categories not articles, you can add the articles inside the categories using the API inside it: https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/
If you want to show only articles not categories then replace the API with the article's API.
As, I said in my comment, if you have a db in the backend with your info, you should use Ajax.
Ajax allows JavaScript to send requests to the backend. When this request is sent, the backend should reply with data in some form, such as JSON, and then your client side JavaScript will need to populate the sidebar using the data.
If you give some more info about your backend and html, I can give an example!

Find all links by class with Selenium

On the web page there are a few articles. I need to get links to all articles.
I use Selenium and Powershell.
I do a search with:
FindElementByXPath("//*[contains(#class, 'without')]").getattribute("href")`
but only get a link to the first article.
How to get links to all the articles?
All links articles view:
<a class="without" href="http://articlelink.html"><h2>article</h2></a>
I don't know anything about Powershell But Using java with selenium you can do this like below mentioned code.
I know it's not a proper answer to deal with, but below code will give you the hint, that how you should go with other language.
List<WebElement> links = driver.findElements(By.className("without")); // Using list web-element get all web-elements, whose classname name as "without"
System.out.println(links.size()); //total number of links on the page.
for(int i = 0;i<links.size();i++)
{
System.out.println(links.get(i).getAttribute("href")); //Using for loop getting one by one links name.
links.get(i).click(); // click the link if you want to click
Thread.sleep(2500); //wait for 2.5 seconds
}
Hope my above answer will help you.

Is it possible to encrypt or hide the paypal auto return url?

I have a program that I wish to sell via paypal, but once the user pays for the software, they are taken to a download page which is simple to share. I know I can
t prevent people from sharing the file, but the customers who buy this software are not often that savvy, so making it a little difficult to share the link would probably work quite well. I thought maybe of passing a url parameter from the auto return that enabled the download? My web host is only html, so some of the more backend options won't work. I could email the link, but I was hoping for an auto response. I could password protect the file and have the password emailed, but that is less appealing. If anyone has a simple deterrent solution, I would love to hear it (hiding the url I guess is not possible with many browsers now?)
test_dl_test.php::
<?php
$email=$_REQUEST['email'];
$key = $_REQUEST['key'];
$go = $_REQUEST['go'];
/*
$query = "SELECT * FROM purchases WHERE key LIKE '".$key."' AND email LIKE '".$email."'"; // instead of (*), you could get the URL
$result = mysqli_query($db_handler,$query) or trigger_error(mysqli_error($dh_handler));
if (mysqli_num_rows($result)!=1) {
die("ERROR! Purchase history not found!");
}
// OPTIONALLY
// $result = mysqli_fetch_assoc($result);
// $software_url = result['URL'];
*/
if ($go==1) {
$url = "http://www.vbaccelerator.com/home/VB/Code/vbMedia/Audio/Lossless_WAV_Compression/Sample_APE_File.zip";
header('Location: '.$url);
}
?>
<html>
click here!
</html>

WordPress Paradox - Normal posts not being queried

I am in a situation that i can't figure out. I am running a WP 3.4.2 on a site with multiple custom post types. The normal posts are displayed in the blog section and are in a category called blog with different subcategories.
Blog posts and another post type called 'events' display tags in single view. The tags display fine but when you click on a blog post tag no posts are found. Tags related to events work as expected.
The really weird thing is in admin. when I search a tag that is related to a normal post, it finds it and counts how many posts it has, but when clicking on the number of posts is says "No posts found.". With the tags related to events this never happens.
Also, categories have the same problem.. display just posts from events..
Also I tried to make another post type called "blogposts" to display on the blog page instead of normal posts but same sad story.
As far as I see in the code, in archive.php and tag.php, normal posts are not returned from the query, just events get through.
I have this in functions.php
function namespace_add_custom_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array('post', 'events', 'blogposts' ));
return $query;
}
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );
Any ideas would be really welcomed.
Thanks!
This is a weird problem. Most likely caused by a combination of plugin(s) and/or theme.
So first we need to figure out where the problem comes from. So:
turn off all plugins to see if it changes.
Or do it one by one
turn off parts in functions.php in your theme.
turn as many off as possible and see if things change
To find this problem we need more specific information.
Is it your won theme or someone else's?
What plugins are active?
Is this problem new, or did it just 'popup'?
good luck and let me know what you find ;)

MediaWiki: page editing allowed by creator only or with approval

I'm trying to restraint editing on the Wiki (using MediaWiki) that I'm creating as an internal project for my company.
We would like to be able to let the page creators specify none or one of the two following options:
Nobody besides the creator of this page can edit the content of this page
Anybody can edit the content of this page, but there must be an approval by the page creator before the changes are visible (whether it'd be by mail, on the wiki directly or something else - does not matter).
If the creator does not specify any of the 2 options, anybody can edit the page, and the changes are immediatly visible (default behaviour).
I've been browsing the net but I did not find an out-of-the-box solution for this. We managed to make some great custom stuff thanks to the edition of the LocalSettings file but not this.
Is there a solution for that functionality?
I don't know of an extension that would make this easy.
What I think you could do would be to take an extension like Flagged Revs or Approved Revs and make it so that instead of using groups as the determiner of approval status, it uses username. This might not be too difficult. Does this make sense?
I had the same problem as you and now i fixed it, here is the solution:
I am using http://www.mediawiki.org/wiki/Extension%3aApproved_Revs for article protection but it didn't fulfil my need it allowed the user to change the currently approved revision of the article and so the change was immediately reflected on the main page so I hacked it a bit, basically you need only one change
go to ApprovedRevs/ApprovedRevs.hooks.php
and find the following code:
static public function setLatestAsApproved( &$article , &$user, $text,
$summary, $flags, $unused1, $unused2, &$flags, $revision,
&$status, $baseRevId ) {
this is a function declaration just after it add the following code:
return false;
and it will work the way you wanted it to be i.e (the change you did will not be reflected until you approve it)