Magento Cart API not showing prices - api

I am attempting to use the Magento Enterprise 1.10 XML-RPC API to handle cart/catalog functions outside of the Magento installation. The issue that I am having is when I add to cart. I can connect just fine to the API endpoint, login, and retrieve data. The following is the code that I am using to discover the workings of the Magento API.
<?php
require $_SERVER['DOCUMENT_ROOT'].'/Zend/XmlRpc/Client.php';
$url = 'http://mymagento.com/api/xmlrpc';
$user = 'apiuser';
$pass = 'apipass';
$proxy = new Zend_XmlRpc_Client( $url );
$sess = $proxy->call( 'login', array( $user, $pass ) );
$cartId = $proxy->call( 'call', array( $sess, 'cart.create', array( 1 ) ) );
$pList = $proxy->call( 'call', array( $sess, 'product.list', array() ) );
$cList = $proxy->call( 'call', array( $sess, 'customer.list', array() ) );
$cList[0]['mode'] = 'customer';
$setCart = $proxy->call( 'call', array( $sess,
'cart_customer.set',
array( $cartId, $cList[0] ) ) );
foreach( $pList as $prod)
{
if( $prod['product_id'] == 5 )
{
$prod['qty'] = 5;
$addCart = $proxy->call( 'call', array( $sess,
'cart_product.add',
array( $cartId, $pAdd ) ) );
}
}
$cList = $proxy->call( 'call', array( $sess, 'cart.info', array( $cartId ) ) );
print_r( $cList );
Outputs:
[store_id] => 1
[created_at] => 2011-05-27 13:30:57
[updated_at] => 2011-05-27 13:31:00
[converted_at] => 0000-00-00 00:00:00
[is_active] => 0
[is_virtual] => 0
[is_multi_shipping] => 0
[items_count] => 1
[items_qty] => 5.0000
[orig_order_id] => 0
[store_to_base_rate] => 1.0000
[store_to_quote_rate] => 1.0000
[base_currency_code] => USD
[store_currency_code] => USD
[quote_currency_code] => USD
[grand_total] => 0.0000
[base_grand_total] => 0.0000
[checkout_method] => customer
...
[items] => Array
(
[0] => Array
(
[item_id] => 93
[quote_id] => 119
[created_at] => 2011-05-27 13:31:00
[updated_at] => 2011-05-27 13:31:00
[product_id] => 5
[store_id] => 1
[parent_item_id] =>
[is_virtual] => 1
[sku] => product1
[name] => product
[description] =>
[applied_rule_ids] =>
[additional_data] =>
[free_shipping] => 0
[is_qty_decimal] => 0
[no_discount] => 0
[weight] =>
[qty] => 5
[price] => 0.0000
[base_price] => 0.0000
[custom_price] =>
[discount_percent] => 0.0000
[discount_amount] => 0.0000
[base_discount_amount] => 0.0000
However, I am to just call the following using the same above session
<?php
$pInfo = $proxy->call( 'call', array( $sess, 'catalog_product.info', '5' ) );
print_r( $pInfo );
I get the following information about the product:
[product_id] => 5
[sku] => product1
[set] => 9
[type] => virtual
[categories] => Array
(
)
[websites] => Array
(
[0] => 1
)
[type_id] => virtual
[name] => product
[description] => Test
[short_description] => Test
[news_from_date] =>
[old_id] =>
[news_to_date] =>
[status] => 1
[visibility] => 4
...
[created_at] => 2011-05-25 15:11:34
[updated_at] => 2011-05-25 15:11:34
...
[price] => 10.0000
In the end, the API sees that the price of the item is in fact $10.00, but when added to the cart via API the prices are not properly reflected.

Just so it can be an officially answered question, here is the solution found, http://magentocommerce.com/boards/viewthread/227044 I spent two days searching for this, and today come up with an obscure search term to try and find the solution

I've been looking at this issue for a couple days now. It didn't make sense to me that if you add a product to your cart through the normal web interface [ie Mage_Checkout_CartController::addAction() ]. It knows the price without you providing an address. I finally found the difference between the two. In addAction() they create an instance of Mage_Checkout_Model_Cart, add the product to that, and save it. In the api they use Mage_Sales_Model_Quote instead. If you look at Mage_Checkout_Model_Cart::save() you will see these two lines:
$this->getQuote()->getBillingAddress();
$this->getQuote()->getShippingAddress();
These two lines actually create empty Mage_Sales_Model_Quote_Address objects that get saved into the db.
If you are willing/able to modify magento's code, you can modify Mage_Checkout_Model_Cart_Api::create() and add a call to these two methods before $quote->save() and the api and the web interface will work the same way.
I have only tested this a little bit, but I really think this is a bug and not a feature. I'll see about getting this in front of actual magento devs and maybe they'll include it in the next release.

Magento frontend and API both are different. In frontend after registering customer it creates quote for customer and also set address with that created quote id. But in API it creates only quote using shoppingCartCreate service. For proper we need to customize create service. I did and it worked for me.
Here am providing solution:
Edit function in file - Mage/Checkout/Model/Cart/Api.php
public function create($store = null)
{
$storeId = $this->_getStoreId($store);
try {
/*#var $quote Mage_Sales_Model_Quote*/
$quote = Mage::getModel('sales/quote');
$quote->setStoreId($storeId)
->setIsActive(false)
->setIsMultiShipping(false)
->save();
/* Customized this for saving default address for quote and it will show price in cart info*/
$quote->getBillingAddress();
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->collectTotals();
$quote->save();
/* End cart here */
} catch (Mage_Core_Exception $e) {
$this->_fault('create_quote_fault', $e->getMessage());
}
return (int) $quote->getId();
}

Related

shopware 6 upload multiple product variation images

Can we upload multiple image to the variation using API. Single image upload can be possible using below code, but not sure about multiple image upload.
$mediaId ='random string';
$url = $images['url'];
$mediaData = array(
array(
'id' => $mediaId,
'mediaFolderId' => $mediaFolderID,
),
);
$mediaDataArr = array(
'payload' => array(
"action" => "upsert",
"entity" => "media",
'payload' => $mediaData,
),
);
$createMedia = $shopware6HelperObj->post('_action/sync', $mediaDataArr);
$urlArr = array(
'url' => $url,
);
$parts = pathinfo($url);
$params = array(
'extension' => $parts['extension'],
'fileName' => $parts['filename'] . '__' . md5(time()),
);
$uploadImage = $shopware6HelperObj->post('_action/media/' . $mediaId . '/upload', $urlArr, $params);
Please suggest if any idea.
I always recommend to try doing that via the Admin Panel and check the Browser's Dev Tools / Network Tab which requests are made. This can give you a good hint on how do to it programmatically.

Telegram photo format with getUserPhotos

I use getUserPhotos to get profile photos. What is the main standard source that I should use for html src attribute? (I searched even in telegram's docs, but didn't get the solution.)
A part of my result (type is photos.Photos):
Array
(
[_] => photos.photosSlice
[count] => 14
[photos] => Array
(
[0] => Array
(
[_] => photo
[has_stickers] =>
[id] => 195744071274310414
[access_hash] => -5116812755800708610
[date] => 1472714208
[sizes] => Array
(
[0] => Array
(
[_] => photoSize
[type] => a
[location] => Array
(
[_] => fileLocation
[dc_id] => 4
[volume_id] => 425426808
[local_id] => 100105
[secret] => -7781982930425156181
)
[w] => 160
[h] => 160
[size] => 11694
)
...
What you need to do is use the following method to download your file or picture:
upload.getFile#e3a6cfb5 location:InputFileLocation offset:int limit:int = upload.File;
Where InputFileLocation is defined below, and may be obtained from PhotoSize.location in your question above:
inputFileLocation#14637196 volume_id:long local_id:int secret:long = InputFileLocation;
more details on file download here: https://core.telegram.org/api/files#downloading-files

how to get result for api connecting to whoapi?

As according to the mention documentation at whoapi.com i have gone through as mention according to instruction and tried implementing the api but the variable doesn't pass from one page to other.For example i have one page which have input type and submit button then when i click submit button it should redirect to who api url and display result
http://api.whoapi.com/?domain=whoapi.com&apikey=demokey&r=blacklist
whoapi.com = name of url,demokey = key assigned by who api & blacklist = name of service of who api
guide me through the connecting protocol.
Not sure I understand the question. Using the API should be straight simple as any REST request is.
PHP example:
$domain = "whoapi.com";
$r = "blacklist";
$apikey = "demokey";
$request = "http://api.whoapi.com/?domain=$domain&r=$r&apikey=$apikey";
$output = json_decode(file_get_contents($request), true);
Resulting array with print_r($output) looks like this:
[status] => 0
[ip] => 88.198.98.181
[blacklisted] => 0
[blacklists] => Array
(
[0] => Array
(
[tracker] => invaluement.com
[blacklisted] => 0
)
[1] => Array
(
[tracker] => surbl.org
[blacklisted] => 0
)
[2] => Array
(
[tracker] => barracudacentral.org
[blacklisted] => 0
)
[3] => Array
(
[tracker] => sorbs.net
[blacklisted] => 0
)
[4] => Array
(
[tracker] => spamhaus.org
[blacklisted] => 0
)
)
Hope this helps.

PDO::FETCH_ASSOC Does not return the correct table columns

I'm new to PHP and I am currently developing a small web application. Below is the test code for the DB query using PDO:
try
{
$dsn = "mysql:host=localhost;dbname=auction";
$opt = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"
);
$pdo = new PDO($dsn, 'root', 'password', $opt);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
$stmt = $pdo->query("SELECT id,username,password,name,level FROM users");
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$test = $stmt->fetchALL();
print_r($test);
The output of the said code is the following:
Array ( [0] => Array ( [id] => 1 [username] => admin [users] => Administrator [auction] => 0 )
[1] => Array ( [id] => 2 [username] => jodel [users] => Jodel Ross [auction] => 1 ) )
I am confused because, from my point of view, the above code should have given an associative array whose index are the columns of the returned result set, i.e. id, username,password,name,level. But it is not so.
Moreover, If I used PDO::FETCH_NUM, the correct number of fields and corresponding data are returned correctly as show below:
Array ( [0] => Array ( [0] => 1
[1] => admin
[2] => 21232f297a57a5a743894a0e4a801fc3
[3] => Administrator
[4] => 0 )
[1] => Array ( [0] => 2
[1] => jodel_ross
[2] => 2cdaeb5df4cf941d9c5650591cba1fdc
[3] => Jodel Ross, Jr.
[4] => 1 ) )
Please help, I need to understand why and I have search the web for answers and have not found any.
Thanks.
Development environment:
Windows 7 x64
PHP 5.3.6
Mysql 5.5
Apache 2.0.64
Zend Framework 1.11
There is still an open error with Zend Framework 1.x, PHP 5.3.x and setFetchMode() and that's the reason why it doesn't work as expected.
see http://framework.zend.com/issues/browse/ZF-10866 and http://framework.zend.com/issues/browse/ZF-3470
Please vote for closing this error or submit a patch.

Where would you document standardized complex data that is passed between many objects and methods? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I often find myself with fairly complex data that represents something that my objects will be working on. For example, in a task-list app, several objects might work with an array of tasks, each of which has attributes, temporal expressions, sub tasks and sub sub tasks, etc.
One object will collect data from web forms, standardize it into a format consumable by the class that will save them to the database, another object will pull them from the database, put them in the standard format and pass them to the display object, or the update object, etc.
The data itself can become a fairly complex series of arrays and sub arrays, representing a 'task' or list of tasks.
For example, the below might be one entry in a task list, in the format that is consumable by the various objects that will work on it. Normally, I just document this in a file somewhere with an example. However, I am thinking about the best way to add it to something like PHPDoc, or another standard doc system.
Where would you document your consumable data formats that are for many or all of the objects / methods in your app?
Array
(
[Meta] => Array
(
//etc.
)
[Sched] => Array
(
[SchedID] => 32
[OwnerID] => 2
[StatusID] => 1
[DateFirstTask] => 2011-02-28
[DateLastTask] =>
[MarginMonths] => 3
)
[TemporalExpressions] => Array
(
[0] => Array
(
[type] => dw
[TemporalExpID] => 3
[ord] => 2
[day] => 6
[month] => 4
)
[1] => Array
(
[type] => dm
[TemporalExpID] => 32
[day] => 28
[month] => 2
)
)
[Task] => Array
(
[SchedTaskID] => 32
[SchedID] => 32
[OwnerID] => 2
[UserID] => 5
[ClientID] => 9
[Title] => Close Prior Year
[Body] =>
[DueTime] =>
)
[SubTasks] => Array
(
[101] => Array
(
[SchedSubTaskID] => 101
[ParentST] =>
[RootT] => 32
[UserID] => 2
[Title] => Review Profit and Loss by Class
[Body] =>
[DueDiff] => 0
)
[102] => Array
(
[SchedSubTaskID] => 102
[ParentST] =>
[RootT] => 32
[UserID] => 2
[Title] => Review Balance Sheet
[Body] =>
[DueDiff] => 0
)
[103] => Array
(
[SchedSubTaskID] => 103
[ParentST] =>
[RootT] => 32
[UserID] => 2
[Title] => Review Current Year for Prior Year Expenses to Accrue
[Body] => Look at Journal Entries that are templates as well.
[DueDiff] => 0
)
[104] => Array
(
[SchedSubTaskID] => 104
[ParentST] =>
[RootT] => 32
[UserID] => 2
[Title] => Review Prior Year Membership from 11/1 - 12/31 to Accrue to Current Year
[Body] =>
[DueDiff] => 0
)
[105] => Array
(
[SchedSubTaskID] => 105
[ParentST] =>
[RootT] => 32
[UserID] => 2
[Title] => Enter Vacation Accrual
[Body] =>
[DueDiff] => 0
)
[106] => Array
(
[SchedSubTaskID] => 106
[ParentST] => 105
[RootT] => 32
[UserID] => 2
[Title] => Email Peter requesting Vacation Status of Employees at Year End
[Body] => We need Employee Name, Rate and Days of Vacation left to use.
We also need to know if the employee used any of the prior year's vacation.
[DueDiff] => 43
)
[107] => Array
(
[SchedSubTaskID] => 107
[ParentST] =>
[RootT] => 32
[UserID] => 2
[Title] => Grants Receivable at Year End
[Body] =>
[DueDiff] => 0
)
[108] => Array
(
[SchedSubTaskID] => 108
[ParentST] => 107
[RootT] => 32
[UserID] => 2
[Title] => Email Peter Requesting if there were and Grants Receivable at year end
[Body] =>
[DueDiff] => 43
)
)
)
I would document with and in the code that defines the data. One way to self document is to use classes with well named attributes instead of arrays or hashes when things start to become complex. Just use comments sparingly to clear up any unobvious areas. Assume that the is smarter than you and avoid comments that clutter things.