Magento 1.4 paypal bug - magento

i try to get the paypal payment run in my magento 1.4 but there is a serious problem with the workflow. after i select paypal and get routed to the paypal account to send the money you normally come back automatically into the magento shop to finish the order, but in my case magento tells you there is aproblem with the adress field. paypal does'nt send the adress back to magento correctly:
Error: Please check shipping address information. Please enter last name.
is this a known bug or is there a patch or workaround?
please help!
thnx.

The error seems to be in /app/code/core/Mage/Paypal/Model/Api/Nvp.php. Looks like the vars aren't mapped well. Because I couldn't find the concrete error in this file, I did a bit dirty workaround in /app/code/core/Mage/Paypal/Model/Express/Checkout.php.
In 1.4.2 just replace the method returnFromPaypal() with the following code...
public function returnFromPaypal($token)
{
$this->_getApi();
$this->_api->setToken($token)
->callGetExpressCheckoutDetails();
// import billing address
$billingAddress = $this->_quote->getBillingAddress();
$exportedBillingAddress = $this->_api->getExportedBillingAddress();
// import shipping address
$exportedShippingAddress = $this->_api->getExportedShippingAddress();
if (!$this->_quote->getIsVirtual()) {
$shippingAddress = $this->_quote->getShippingAddress();
if ($shippingAddress) {
if ($exportedShippingAddress) {
foreach ($exportedShippingAddress->getExportedKeys() as $key) {
if('firstname' == $key || 'lastname' == $key){
continue;
} // if
$shippingAddress->setDataUsingMethod($key, $exportedShippingAddress->getData($key));
$billingAddress->setDataUsingMethod($key, $exportedShippingAddress->getData($key));
}
// Correct First- and Lastnames
list($_firstname, $_lastname) = explode(' ', $exportedShippingAddress->getData('firstname'));
$shippingAddress->setDataUsingMethod('firstname', $_firstname);
$billingAddress->setDataUsingMethod('firstname', $_firstname);
$shippingAddress->setDataUsingMethod('lastname', $_lastname);
$billingAddress->setDataUsingMethod('lastname', $_lastname);
$shippingAddress->setCollectShippingRates(true);
}
// import shipping method
$code = '';
if ($this->_api->getShippingRateCode()) {
if ($code = $this->_matchShippingMethodCode($shippingAddress, $this->_api->getShippingRateCode())) {
// possible bug of double collecting rates :-/
$shippingAddress->setShippingMethod($code)->setCollectShippingRates(true);
}
}
$this->_quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD, $code);
}
}
$this->_ignoreAddressValidation();
// import payment info
$payment = $this->_quote->getPayment();
$payment->setMethod($this->_methodType);
Mage::getSingleton('paypal/info')->importToPayment($this->_api, $payment);
$payment->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_PAYER_ID, $this->_api->getPayerId())
->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_TOKEN, $token)
;
$this->_quote->collectTotals()->save();
}
The modified code replaces the whole billing address with the shipping address and pushes the name given in $firstname into $firstname and $lastname.
not clean, but working. :-)

any luck finding a solution to this, I'm having the same issue.
--- update ---
I finally figured out what was happening on this one for me. I had the Custom Shipping Admin module installed and it was overriding the address controller that validates the order. I updated the overrided module to reflect the version of Magento I was on and it worked.. no problems. Hope this helps someone.

Related

How to change the weight before sending to fedex magento?

In magento checkout page, after giving billing information and shipping information, i understand that these details are sending to fedex then the shipping rates are populating in chekout page, before sending theses details to fedex, i want to change the weight of the product, i Want to add additional weights for each products,
suppose user adding a product with weight of 2 pounds, i want to send
these weight to 2*5 = 10pounds, how can i do that in magento? please
help.
Not sure to understand what you want exactly but I'll give a try.
I think you can override Mage_Checkout_OnepageController::savePaymentAction method in your local pool and in your local method, dispatch your own new event 'save_payment_action_before' and pass your objects as parameters.
In your fedex module, create an observer, get your object and change the order weight before it's sent to fedex.
To create your custom event, check this post
Finally i find out that it is happening in the sales/quote/item.php file, there is a function called setProduct, here we need to add addititonal info while setting data.
public function setProduct($product)
{
$batchQty = Mage::getModel('catalog/product')->load($product->getId())->getBatchQty();
$roleId = Mage::getSingleton('customer/session')->getCustomerGroupId();
$userrole = Mage::getSingleton('customer/group')->load($roleId)->getData('customer_group_code');
$userrole = strtolower($userrole);
if ($this->getQuote()) {
$product->setStoreId($this->getQuote()->getStoreId());
$product->setCustomerGroupId($this->getQuote()->getCustomerGroupId());
}
if($userrole=="retailer" && $batchQty>0 ){
$this->setData('product', $product)
->setProductId($product->getId())
->setProductType($product->getTypeId())
->setSku($this->getProduct()->getSku())
->setName($product->getName())
->setWeight($this->getProduct()->getWeight()*$batchQty)
->setTaxClassId($product->getTaxClassId())
->setBaseCost($product->getCost())
->setIsRecurring($product->getIsRecurring());
} else {
$this->setData('product', $product)
->setProductId($product->getId())
->setProductType($product->getTypeId())
->setSku($this->getProduct()->getSku())
->setName($product->getName())
->setWeight($this->getProduct()->getWeight())
->setTaxClassId($product->getTaxClassId())
->setBaseCost($product->getCost())
->setIsRecurring($product->getIsRecurring());
}
if ($product->getStockItem()) {
$this->setIsQtyDecimal($product->getStockItem()->getIsQtyDecimal());
}
Mage::dispatchEvent('sales_quote_item_set_product', array(
'product' => $product,
'quote_item' => $this
));
return $this;
}

Magento billing address

I am using the one page checkout module from AheadWorks and I am trying to only retrieve billing addresses from logged in members.
Currently the dropdown menu for choosing their address to bill from shows all addresses created by a logged in member. Also shipping adresses.
I would like this to only show billingaddresses. Is there a way to do so?
I already took a look inside the block which should be used, but unfortunately, I don't understand.
public function getAddressesHtmlSelect($type)
{
if ($this->isCustomerLoggedIn()) {
$options = array();
foreach ($this->getCustomer()->getAddresses() as $address) {
$options[] = array(
'value' => $address->getId(),
'label' => $address->format('oneline')
);
}
$addressDetails = Mage::getSingleton('checkout/session')->getData('aw_onestepcheckout_form_values');
if (isset($addressDetails[$type.'_address_id'])) {
if (empty($addressDetails[$type.'_address_id'])) {
$addressId = 0;
} else {
$addressId = $addressDetails[$type.'_address_id'];
}
} else {
$addressId = $this->getQuote()->getBillingAddress()->getCustomerAddressId();
}
if (empty($addressId) && $addressId !== 0) {
$address = $this->getCustomer()->getPrimaryBillingAddress();
if ($address) {
$addressId = $address->getId();
}
}
$select = $this->getLayout()->createBlock('core/html_select')
->setName($type.'_address_id')
->setId($type.'-address-select')
->setClass('address-select')
->setValue($addressId)
->setOptions($options);
return $select->getHtml();
}
return '';
}
Simple answer is no, you can't do that. In principle magento has customer entity and customer address entity. Customer address can have type which is billing or shipping but this only applies for quote and order. But when the address is saved in customer addresses it has no indication which one it is so you can use it for both steps.
Long answer. To achieve what you need you would have to extend magento customer address entity and put this division inside the entity itself. This would however require to rewrite some portion of the code which is to broad to give exact answer here.
Alternatively you could try to determine if an address is billing or shipping by going through previous orders of the user and checking which type it was there.
I was looking for this as well, here is something that I found, try it out: http://www.magebuzz.com/blog/disable-shipping-address-in-magento-checkout/

Add checkbox to Magento checkout?

I've been searching, trying, and failing alot here. What I want is to add a checkbox, on the Shipping page of Onepage checkout, the standard magento checkout.
I want to create a checkbox so that customers can check it if they want their products to be placed on their address without a signature.
I've been messing around with some old "Accept Terms" checkboxes, but with no luck.
I'm hoping that somebody might have had to make the same kind of customization.
What you can do is save the preference in the checkout/session via an observer. First, add the checkbox to the shipping section and give it the property of name=shipping[no_signature]. Then, create a new module and hook into the event controller_action_postdispatch_checkout_onepage_saveShipping and then use this code:
public function controller_action_postdispatch_checkout_onepage_saveShipping($observer)
{
$params = (Mage::app()->getRequest()->getParams()) ? Mage::app()->getRequest()->getParams() : array();
if (isset($params['shipping']['no_signature']) && $params['shipping']['no_signature']) {
Mage::getSingleton('checkout/session')->setNoSignature(true);
} else {
Mage::getSingleton('checkout/session')->setNoSignature(false);
}
return $this;
}
Then, when the order is about to be placed, hook into the event sales_order_place_before you can add a comment to the order like this:
public function sales_order_place_before($observer)
{
$order = $observer->getOrder();
if (Mage::getSingleton('checkout/session')->getNoSignature()) {
$order->setCustomerNote('No signature required.');
} else {
$order->setCustomerNote(null);
}
return $this;
}
When you go to Sales > Orders, you should see a comment on the order regarding if the customer requires a signature or not. This is under the assumption that no other module or custom code is injecting anything into the customer_note field on the order object.

Get customer in Mage_Tax_Model_Calculation::getRate in magento

I have overwritten the Mage_Tax_model_Calculation::getRate, so that I want to not tax certain customers. I do not have a special customer class for them.
I have a custom field in my customer model, which I want to check after I am able to load my customer model and if this field has a value I do not tax him, otherwise I call parent::getRate($request)
Is it possible to get that in the function.
Try something like this:
function getRate($request) {
// find a customer ID
$admin_session = Mage::getSingleton('adminhtml/session_quote');
if($admin_session) {
if($admin_session->getCustomerId()) {
$customer_id = $admin_session->getCustomerId();
}
} else {
$customer_id = Mage::getSingleton("customer/session")->getCustomerId();
}
// find customer attr
if($customer_id) {
$customer = Mage::getModel("customer/customer")->load($customer_id);
if($customer->getSomeColumnValue()) {
return 0;
}
}
// fallthrough
return parent::getRate($request);
}
Hope that helps!
Thanks,
Joe
EDIT: good point ;)
Looking through the adminhtml code, it seems to be far less useful than the normal customer code. I was hoping for a call to Mage::register but that's not happening. I found a possible solution, though loading sessions in Magento seems to have side effects. See above.
RE-EDIT: to incorporate your fixes for posterity.
Try this to load the current logged-in customer:
$session = Mage::getSingleton('customer/session');
$customer = Mage::getModel('customer/customer')->load($session->getCustomerId());
$customValue = $customer->getCustomFieldName();
Cheers,
JD

Magento - Use Short description for Google base description

I am using magento and it's built in functionality for adding products to google base. I would like to change it so that it uses the Short description as the Description in Google base. As opposed to the detailed description.
According to this Screencast you should be able to setup attribute attribute mappings. Is that not working for you?
Looking deeper, I don't have a google base account, so I can't test this, BUT, when I search through the Google Base module it looks like this is where it's grabbing the description
app/code/core/Mage/GoogleBase/Model/Service/Item.php
protected function _setUniversalData()
{
//...
if ($object->getDescription()) {
$content = $service->newContent()->setText( $object->getDescription() );
$entry->setContent($content);
}
//...
}
My general approach here would be to create an override for the _setUniversalData method on the Mage_GoogleBase_Model_Service_Item class that looks something like this
protected function _setUniversalData()
{
parent::_setUniversalData();
//your code to parse through this object, find the long desription,
//and replace with the short. The following is pseudo code and just
//a guess at what would work
$service = $this->getService();
$object = $this->getObject();
$entry = $this->getEntry();
$new_text = $object->getShortDescription(); //not sure on getter method
$content = $service->newContent()->setText( $new_text );
$entry->setContent($content);
return $this;
}
Good luck!
Figured out all I had to do was change:
if ($object->getDescription()) {
$content = $service->newContent()->setText( $object->getDescription() );
$entry->setContent($content);
}
to
if ($object->getDescription()) {
$content = $service->newContent()->setText( $object->getShortDescription() );
$entry->setContent($content);
}
in app/code/core/Mage/GoogleBase/Model/Service/Item.php
I eventually got the module to work and managed to fix all errors.
I put together short step-by-step guide on how to set up the Magento Google Base feed, including account configuration, adding the condition attribute & mapping attributes and publishing them here http://blog.pod1.com/e-commerce/magento-google-base-feed/
Magento 1.7.0.2 Google Shopping 1.7.0.0
app/code/core/Mage/GoogleShopping/Model/Attribute/Content.php
Change $description = $this->getGroupAttributeDescription();
In $description = $this->getGroupAttributeShortDescription();

Resources