Имам персонализиран контролер с функция в моя сайт на magento, който програмно създава клиент, добавя продукт в неговата количка и го пренасочва към страницата за плащане. Всичко работи добре. Функцията на контролера е достъпна чрез URL mymagentopage.de/namespace/controllername/functionname и ще пренасочи потребителя към страницата за плащане на една страница на magento.
Сега трябва да предам данни (име, имейл и адрес от потребителя) от външна страница към тази функция. Мислех, че мога да направя това с къдрици. Но няма да работи. Винаги получавам празна страница без никакви грешки. Никога не съм работил с curl преди и също съм съвсем нов в magento, така че наистина не знам какъв може да е проблемът. Може ли някой да ми помогне или да ми даде съвет? Или има друг/по-добър начин за предаване на данни от външен сайт?
Използвам кода в този пример на моя външен сайт, за да публикувам потребителски данни към моята функция mageno, използвайки връзката mymagentopage.de/namespace/controllername/functionname. Curl кодът на външния сайт се изпълнява, когато потребителят изпрати формуляр, но получих само празна страница...
Функцията на контролера на magento:
class MyModule_Test_CustomController extends Mage_Core_Controller_Front_Action {
// this is the action that loads the cart and redirects to the cart page
public function cartAction() {
// Get customer session
$session = Mage::getSingleton('customer/session');
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
$customer = Mage::getModel("customer/customer");
$email = '[email protected]'
$price = '20';
function IscustomerEmailExists($email, $websiteId = null){
$customer = Mage::getModel('customer/customer');
if ($websiteId) {
$customer->setWebsiteId($websiteId);
}
$customer->loadByEmail($email);
if ($customer->getId()) {
return $customer->getId();
}
return false;
}
$cust_exist = IscustomerEmailExists($email,$websiteId);
if($cust_exist){
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($email);
$session_customer = Mage::getSingleton('customer/session')->loginById($customer->getId());
$customerAddressId = Mage::getSingleton('customer/session')->getCustomer()->getDefaultBilling();
if ($customerAddressId){
$customAddress = Mage::getModel('customer/address')->load($customerAddressId);
$customAddress->getData();
}
}
else{
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($email);
if(!$customer->getId()) {
$customer->setStore($store);
$customer->setEmail($email);
$customer->setFirstname('John');
$customer->setLastname('Doe');
$customer->setPassword('somepassword');
}
try {
$customer->save();
$customer->setConfirmation(null);
$customer->save();
$session_customer = Mage::getSingleton('customer/session')->loginById($customer->getId());
}
catch (Exception $ex) {
}
//Build billing address for customer, for checkout
$_custom_address = array (
'firstname' => 'John',
'lastname' => 'Doe',
'street' => 'Sample address part1',
'city' => 'Munich',
'region_id' => 'BAY',
'region' => 'BAY',
'postcode' => '81234',
'country_id' => 'DE',
'telephone' => '0123455677',
);
$customAddress = Mage::getModel('customer/address');
$customAddress->setData($_custom_address)
->setCustomerId($customer->getId())
->setIsDefaultBilling('1')
->setIsDefaultShipping('1')
->setSaveInAddressBook('1');
try {
$customAddress->save();
}
catch (Exception $ex) {
}
}
Mage::getSingleton('checkout/session')->getQuote()->setBillingAddress(Mage::getSingleton('sales/quote_address')->importCustomerAddress($customAddress));
// Get cart instance
$cart = Mage::getSingleton('checkout/cart');
$cart->init();
$product = Mage::getModel('catalog/product');
$product->load('2');
$product->setPrice($price);
$product->save();
$cart->addProduct($product, array('qty' => 1));
$session->setCartWasUpdated(true);
$cart->save();
Mage::app()->getResponse()->setRedirect(Mage::helper('checkout/url')->getCheckoutUrl()); //redirect to Checkout
}
}