Version Notes
Facebook login added
Download this release
Release Info
| Developer | tmobtech |
| Extension | Tmob_Tappz |
| Version | 1.0.13 |
| Comparing to | |
| See all releases | |
Code changes from version 1.0.12 to 1.0.13
app/code/community/TmobLabs/Tappz/Model/Basket/Api.php
CHANGED
|
@@ -1,16 +1,18 @@
|
|
| 1 |
<?php
|
| 2 |
-
|
| 3 |
class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
| 4 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
public function get($quoteId, $customerId = null)
|
| 6 |
{
|
| 7 |
$decimalDivider = Mage::getStoreConfig('tappz/general/decimalSeparator');
|
| 8 |
$thousandDivider = Mage::getStoreConfig('tappz/general/groupSeparator');
|
| 9 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 10 |
-
|
| 11 |
$lineAverageDeliveryDaysAttributeCode = Mage::getStoreConfig('tappz/basket/averagedeliverydaysattributecode');
|
| 12 |
$creditCardPaymentType = Mage::getStoreConfig('tappz/basket/creditcardpaymenttype');
|
| 13 |
-
|
| 14 |
$basket = array();
|
| 15 |
$basket['id'] = null;
|
| 16 |
$basket['lines'] = array();
|
|
@@ -78,7 +80,6 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 78 |
$quoteShippingAddress = $quote->getShippingAddress();
|
| 79 |
if ($quoteShippingAddress) {
|
| 80 |
$basket['delivery']['shippingAddress'] = $addressApi->get($quoteShippingAddress->getData('customer_address_id'));
|
| 81 |
-
|
| 82 |
$basket['delivery']['shippingMethod']['id'] = $quoteShippingAddress->getData('shipping_method');
|
| 83 |
$basket['delivery']['shippingMethod']['displayName'] = $quoteShippingAddress->getData('shipping_description');
|
| 84 |
$basket['delivery']['shippingMethod']['trackingAddress'] = null;
|
|
@@ -88,8 +89,6 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 88 |
$basket['delivery']['shippingMethod']['imageUrl'] = null;
|
| 89 |
$basket['discountTotal'] = number_format($quoteShippingAddress->getData('discount_amount'), 2, $decimalDivider, $thousandDivider);
|
| 90 |
$basket['shippingTotal'] = number_format($quoteShippingAddress->getData('shipping_incl_tax'), 2, $decimalDivider, $thousandDivider);
|
| 91 |
-
} else {
|
| 92 |
-
|
| 93 |
}
|
| 94 |
$basket['itemsPriceTotal'] = number_format($quote->getData('base_subtotal'), 2, $decimalDivider, $thousandDivider);
|
| 95 |
if (!isset($basket['discountTotal']))
|
|
@@ -156,7 +155,7 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 156 |
$paymentData['accountNumber'] = null;
|
| 157 |
$paymentData['branch'] = null;
|
| 158 |
$paymentData['iban'] = null;
|
| 159 |
-
} else if ($method == 'stripe') {
|
| 160 |
$paymentData['methodType'] = 'ApplePay';
|
| 161 |
$paymentData['type'] = $method;
|
| 162 |
$paymentData['displayName'] = 'Apple Pay';
|
|
@@ -178,7 +177,7 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 178 |
$code = $method->getCode();
|
| 179 |
if ($code == $creditCardPaymentType) {
|
| 180 |
try {
|
| 181 |
-
$paymentOptions['creditCards'] = $this->
|
| 182 |
} catch (Exception $e) {
|
| 183 |
$paymentOptions['creditCards'] = array();
|
| 184 |
}
|
|
@@ -198,7 +197,7 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 198 |
$paymentOptions['moneyTransfers'][0]['branch'] = ' ';
|
| 199 |
$paymentOptions['moneyTransfers'][0]['accountNumber'] = ' ';
|
| 200 |
$paymentOptions['moneyTransfers'][0]['iban'] = ' ';
|
| 201 |
-
$paymentOptions['moneyTransfers'][0]['imageUrl'] = '
|
| 202 |
} elseif ($code == 'cashondelivery') {
|
| 203 |
$paymentOptions['cashOnDelivery'] = array();
|
| 204 |
$paymentOptions['cashOnDelivery']['type'] = null;
|
|
@@ -210,8 +209,8 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 210 |
$paymentOptions['cashOnDelivery']['PhoneNumber'] = null;
|
| 211 |
$paymentOptions['cashOnDelivery']['type'] = $code;
|
| 212 |
$paymentOptions['cashOnDelivery']['displayName'] = $method->getTitle();
|
| 213 |
-
$paymentOptions['cashOnDelivery']['additionalFee'] = '0';
|
| 214 |
-
$paymentOptions['cashOnDelivery']['description'] = 'Cash on delivery description text';
|
| 215 |
$paymentOptions['cashOnDelivery']['isSMSVerification'] = false;
|
| 216 |
$paymentOptions['cashOnDelivery']['SMSCode'] = null;
|
| 217 |
$paymentOptions['cashOnDelivery']['PhoneNumber'] = null;
|
|
@@ -227,27 +226,25 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 227 |
}
|
| 228 |
}
|
| 229 |
$basket['paymentOptions'] = $paymentOptions;
|
| 230 |
-
|
| 231 |
$shippingMethods = array();
|
| 232 |
if (isset($quoteShippingAddress)) {
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
}
|
| 247 |
}
|
|
|
|
| 248 |
}
|
| 249 |
$basket['shippingMethods'] = $shippingMethods;
|
| 250 |
-
|
| 251 |
$giftCheques = array();
|
| 252 |
if ($quote->getData('gift_cards')) {
|
| 253 |
// TODO
|
|
@@ -274,7 +271,11 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 274 |
$basket['errors'] = $quote->getErrors();
|
| 275 |
return $basket;
|
| 276 |
}
|
| 277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
public function merge($anonymousQuoteId, $customerId)
|
| 279 |
{
|
| 280 |
$store = Mage::getStoreConfig('tappz/general/store');
|
|
@@ -304,7 +305,11 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 304 |
}
|
| 305 |
return $this->get($quote->getId());
|
| 306 |
}
|
| 307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
public function updateItems($quoteId, $updateList)
|
| 309 |
{
|
| 310 |
$store = Mage::getStoreConfig('tappz/general/store');
|
|
@@ -328,10 +333,17 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 328 |
$quote->setTotalsCollectedFlag(false)->collectTotals()->save();
|
| 329 |
return $this->get($quote->getId());
|
| 330 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
public function setAddress($quoteId, $shippingAddressId, $billingAddressId, $shippingMethodId)
|
| 332 |
{
|
| 333 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 334 |
-
|
| 335 |
->setStoreId($store)
|
| 336 |
->load($quoteId);
|
| 337 |
if (!is_null($billingAddressId)) {
|
|
@@ -343,7 +355,6 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 343 |
->importCustomerAddress($customerBillingAddress);
|
| 344 |
$quote->setBillingAddress($billingAddress);
|
| 345 |
}
|
| 346 |
-
|
| 347 |
if (!is_null($shippingAddressId)) {
|
| 348 |
$customerShippingAddress = Mage::getModel('customer/address')
|
| 349 |
->load($shippingAddressId);
|
|
@@ -371,11 +382,15 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 371 |
$this->_fault('invalid_data', $e->getMessage());
|
| 372 |
}
|
| 373 |
}
|
| 374 |
-
|
| 375 |
$quote->setTotalsCollectedFlag(false)->collectTotals()->save();
|
| 376 |
return $this->get($quote->getId());
|
| 377 |
}
|
| 378 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 379 |
public function setGiftWrapping($quoteId, $isSelected, $message)
|
| 380 |
{
|
| 381 |
$store = Mage::getStoreConfig('tappz/general/store');
|
|
@@ -397,6 +412,11 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 397 |
}
|
| 398 |
return $this->get($quote->getId());
|
| 399 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
public function useDiscount($quoteId, $promoCode)
|
| 401 |
{
|
| 402 |
$store = Mage::getStoreConfig('tappz/general/store');
|
|
@@ -412,6 +432,10 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 412 |
}
|
| 413 |
return $this->get($quote->getId());
|
| 414 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 415 |
public function deleteDiscount($quoteId)
|
| 416 |
{
|
| 417 |
$store = Mage::getStoreConfig('tappz/general/store');
|
|
@@ -427,15 +451,24 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 427 |
}
|
| 428 |
return $this->get($quote->getId());
|
| 429 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
public function useGiftCheques($quoteId, $code)
|
| 431 |
{
|
| 432 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 433 |
-
|
| 434 |
$quote = Mage::getModel("sales/quote")
|
| 435 |
->setStoreId($store)
|
| 436 |
->load($quoteId);
|
| 437 |
return $this->get($quote->getId());
|
| 438 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 439 |
public function deleteGiftCheques($quoteId)
|
| 440 |
{
|
| 441 |
$store = Mage::getStoreConfig('tappz/general/store');
|
|
@@ -444,14 +477,24 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 444 |
->load($quoteId);
|
| 445 |
return $this->get($quote->getId());
|
| 446 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 447 |
public function useUserPoints($quoteId, $points)
|
| 448 |
{
|
| 449 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 450 |
$quote = Mage::getModel("sales/quote")
|
| 451 |
->setStoreId($store)
|
| 452 |
->load($quoteId);
|
| 453 |
-
|
| 454 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 455 |
public function selectPaymentMethod($quoteId, $payment)
|
| 456 |
{
|
| 457 |
$store = Mage::getStoreConfig('tappz/general/store');
|
|
@@ -485,10 +528,12 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 485 |
$paymentData['cc_exp_month'] = $creditCard->month;
|
| 486 |
$paymentData['cc_exp_year'] = $creditCard->year;
|
| 487 |
$paymentData['cc_cid'] = $creditCard->cvv;
|
|
|
|
| 488 |
$session->setData('ccNumber', $creditCard->number);
|
| 489 |
$session->setData('ccType', $type);
|
| 490 |
$session->setData('expYear', $creditCard->year);
|
| 491 |
$session->setData('expMonth', $creditCard->month);
|
|
|
|
| 492 |
} else {
|
| 493 |
return $this->get($quote->getId());
|
| 494 |
}
|
|
@@ -508,12 +553,17 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 508 |
return $this->get($quote->getId());
|
| 509 |
break;
|
| 510 |
}
|
| 511 |
-
|
| 512 |
$paymentData['method'] = $paymentMethod;
|
| 513 |
$quote = $this->setPaymentData($quote, $paymentData);
|
| 514 |
return $this->get($quote->getId());
|
| 515 |
-
|
| 516 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 517 |
protected function setPaymentData($quote, $paymentData)
|
| 518 |
{
|
| 519 |
/* @var $quote Mage_Sales_Model_Quote */
|
|
@@ -565,12 +615,12 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 565 |
}
|
| 566 |
return $quote;
|
| 567 |
}
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
protected function _canUsePaymentMethod($method, $quote)
|
| 575 |
{
|
| 576 |
if (!$method->canUseForCountry($quote->getBillingAddress()->getCountry())) {
|
|
@@ -587,10 +637,10 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 587 |
}
|
| 588 |
return true;
|
| 589 |
}
|
| 590 |
-
/**
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
protected function purchase($quote)
|
| 595 |
{
|
| 596 |
if ($quote->getIsMultiShipping()) {
|
|
@@ -629,7 +679,6 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 629 |
Mage::logException($e);
|
| 630 |
}
|
| 631 |
}
|
| 632 |
-
$this->_fault('invalid_data', $e->getMessage());
|
| 633 |
Mage::dispatchEvent(
|
| 634 |
'checkout_submit_all_after',
|
| 635 |
array('order' => $order, 'quote' => $quote)
|
|
@@ -640,9 +689,11 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 640 |
$quote->setIsActive(false)->save();
|
| 641 |
return $order->getIncrementId();
|
| 642 |
}
|
| 643 |
-
/* @var $quote Mage_Sales_Model_Quote */
|
| 644 |
-
/** @var $_a Mage_Checkout_Model_Agreement */
|
| 645 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 646 |
public function getContract($quoteId)
|
| 647 |
{
|
| 648 |
$store = Mage::getStoreConfig('tappz/general/store');
|
|
@@ -654,43 +705,91 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 654 |
$agreementsCollection = Mage::getModel('checkout/agreement')->getCollection()
|
| 655 |
->addStoreFilter($store)
|
| 656 |
->addFieldToFilter('is_active', 1);
|
| 657 |
-
|
| 658 |
foreach ($agreementsCollection as $_a) {
|
| 659 |
$agreements[] = $_a;
|
| 660 |
}
|
| 661 |
}
|
| 662 |
-
|
| 663 |
$contract = array();
|
| 664 |
$contract['salesContact'] = $agreements[0]['content'];
|
| 665 |
$contract['termOfUse'] = $agreements[1]['content'];
|
| 666 |
return $contract;
|
| 667 |
}
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
public function purchaseCreditCard($quoteId)
|
| 674 |
{
|
| 675 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 676 |
-
$quote = Mage::getModel("sales/quote")
|
| 677 |
-
->setStoreId($store)
|
| 678 |
-
->load($quoteId);
|
| 679 |
-
try {
|
| 680 |
-
$session = Mage::getSingleton('checkout/session');
|
| 681 |
-
$ch = curl_init();
|
| 682 |
-
curl_setopt($ch, CURLOPT_URL, 'http://www.annelutfen.com/gtrpay/grinet/teb_payment/');
|
| 683 |
-
curl_setopt($ch, CURLOPT_POST, 1);
|
| 684 |
-
$token_result_json = curl_exec($ch);
|
| 685 |
-
curl_close($ch);
|
| 686 |
-
$token_result = json_decode($token_result_json);
|
| 687 |
-
} catch (Mage_Core_Exception $e) {
|
| 688 |
-
$this->_fault('invalid_data', $e->getMessage());
|
| 689 |
-
}
|
| 690 |
$orderId = $this->purchase($quote);
|
| 691 |
-
return Mage::getSingleton('tappz/Customer_Order_Api')->info($orderId);
|
| 692 |
-
}
|
| 693 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 694 |
public function purchaseMoneyOrder($quoteId, $moneyOrderType)
|
| 695 |
{
|
| 696 |
$store = Mage::getStoreConfig('tappz/general/store');
|
|
@@ -700,7 +799,6 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 700 |
$orderId = $this->purchase($quote);
|
| 701 |
return Mage::getSingleton('tappz/Customer_Order_Api')->info($orderId);
|
| 702 |
}
|
| 703 |
-
/* @var $quote Mage_Sales_Model_Quote */
|
| 704 |
public function purchaseCashOnDelivery($quoteId, $cashOnDelivery)
|
| 705 |
{
|
| 706 |
$store = Mage::getStoreConfig('tappz/general/store');
|
|
@@ -710,11 +808,10 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 710 |
$orderId = $this->purchase($quote);
|
| 711 |
return Mage::getSingleton('tappz/Customer_Order_Api')->info($orderId);
|
| 712 |
}
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
/** @var Mage_Sales_Model_Order_Item $item */
|
| 718 |
public function createNewOrder($quote)
|
| 719 |
{
|
| 720 |
Mage::getSingleton('checkout/session')->replaceQuote($quote);
|
|
@@ -723,7 +820,7 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 723 |
$quote->setIsActive(false);
|
| 724 |
if ($quote->getCustomerId()) {
|
| 725 |
$transaction->addObject($quote->getCustomer());
|
| 726 |
-
}
|
| 727 |
$transaction->addObject($quote);
|
| 728 |
$quote->reserveOrderId();
|
| 729 |
if ($quote->isVirtual()) {
|
|
@@ -750,13 +847,11 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 750 |
}
|
| 751 |
$order->addItem($orderItem);
|
| 752 |
}
|
| 753 |
-
|
| 754 |
$order->setCanSendNewEmailFlag(false);
|
| 755 |
$order->setQuoteId($quote->getId());
|
| 756 |
$order->setExtOrderId($quote->getPayment()->getTransactionId());
|
| 757 |
$transaction->addObject($order);
|
| 758 |
$transaction->addCommitCallback(array($order, 'save'));
|
| 759 |
-
|
| 760 |
try {
|
| 761 |
$transaction->save();
|
| 762 |
$quote->setIsActive(false)->save();
|
|
@@ -768,14 +863,11 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 768 |
)
|
| 769 |
);
|
| 770 |
} catch (Exception $e) {
|
| 771 |
-
//reset order ID's on exception, because order not saved
|
| 772 |
$order->setId(null);
|
| 773 |
-
/** @var $item Mage_Sales_Model_Order_Item */
|
| 774 |
foreach ($order->getItemsCollection() as $item) {
|
| 775 |
$item->setOrderId(null);
|
| 776 |
$item->setItemId(null);
|
| 777 |
}
|
| 778 |
-
|
| 779 |
Mage::dispatchEvent(
|
| 780 |
'sales_model_service_quote_submit_failure',
|
| 781 |
array(
|
|
@@ -790,13 +882,17 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 790 |
Mage::dispatchEvent('sales_model_service_quote_submit_after', array('order' => $order, 'quote' => $quote));
|
| 791 |
return $order;
|
| 792 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 793 |
public function purchaseWithPayPal($quoteId, $transactionId)
|
| 794 |
{
|
| 795 |
$paypalIsSandBox = (bool)Mage::getStoreConfig('tappz/basket/paypalissandbox');
|
| 796 |
$paypalClientId = Mage::getStoreConfig('tappz/basket/paypalclientid');
|
| 797 |
$paypalSecret = Mage::getStoreConfig('tappz/basket/paypalSecret');
|
| 798 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 799 |
-
/* @var $quote Mage_Sales_Model_Quote */
|
| 800 |
$quote = Mage::getModel("sales/quote")
|
| 801 |
->setStoreId($store)
|
| 802 |
->load($quoteId);
|
|
@@ -819,7 +915,6 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 819 |
$token_result_json = curl_exec($ch);
|
| 820 |
curl_close($ch);
|
| 821 |
$token_result = json_decode($token_result_json);
|
| 822 |
-
|
| 823 |
$ch = curl_init();
|
| 824 |
curl_setopt($ch, CURLOPT_URL, $url . 'payments/payment/' . $transactionId);
|
| 825 |
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
@@ -844,7 +939,11 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 844 |
$this->_fault('invalid_data', 'PayPal transaction is not completed.');
|
| 845 |
}
|
| 846 |
}
|
| 847 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 848 |
public function purchaseWithApplePay($quoteId, $tokenId)
|
| 849 |
{
|
| 850 |
$stripeIsTest = (bool)Mage::getStoreConfig('tappz/basket/stripeistest');
|
|
@@ -872,7 +971,6 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 872 |
$charge_json = curl_exec($ch);
|
| 873 |
curl_close($ch);
|
| 874 |
$charge = json_decode($charge_json);
|
| 875 |
-
|
| 876 |
$ch = curl_init();
|
| 877 |
curl_setopt($ch, CURLOPT_URL, 'https://api.stripe.com/v1/charges/' . $charge->id . '/capture');
|
| 878 |
curl_setopt($ch, CURLOPT_USERPWD, $secretKey);
|
|
@@ -896,77 +994,112 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 896 |
$this->_fault('invalid_data', 'Apple Pay transaction is not completed.');
|
| 897 |
}
|
| 898 |
}
|
| 899 |
-
|
| 900 |
-
|
| 901 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 902 |
{
|
| 903 |
$bankInfos = array();
|
| 904 |
-
$
|
| 905 |
-
$show_taksits = true;
|
| 906 |
$cats = array();
|
| 907 |
$cart = Mage::getModel("sales/quote")->load($quoteId);
|
|
|
|
| 908 |
$cartItems = $cart->getItems();
|
| 909 |
-
|
| 910 |
-
|
| 911 |
-
|
| 912 |
-
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 918 |
}
|
| 919 |
}
|
| 920 |
}
|
| 921 |
}
|
| 922 |
-
|
| 923 |
-
|
| 924 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 925 |
}
|
| 926 |
-
if (!empty($
|
| 927 |
$bankCount = 0;
|
| 928 |
-
$
|
| 929 |
-
foreach ($
|
| 930 |
-
|
|
|
|
|
|
|
|
|
|
| 931 |
$valCount = 0;
|
| 932 |
-
foreach ($
|
| 933 |
-
$
|
| 934 |
-
$custom_title = Mage::getStoreConfig($bank_code . '/taksit_baslik/taksit_' . $
|
| 935 |
-
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
|
| 939 |
-
|
| 940 |
-
|
| 941 |
-
|
| 942 |
-
|
| 943 |
-
$taksit_title = 'Tek Çekim';
|
| 944 |
-
else
|
| 945 |
-
$taksit_title = $custom_title;
|
| 946 |
-
}
|
| 947 |
-
$bankInfos[$bankCount]['image'] = null; // TODO : annelutfen - banka imajı
|
| 948 |
$bankInfos[$bankCount]['displayName'] = trim($bank['name']);
|
| 949 |
-
|
| 950 |
-
|
| 951 |
-
|
| 952 |
-
$bankInfos[$bankCount]['
|
| 953 |
-
|
| 954 |
-
|
| 955 |
-
|
| 956 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 957 |
}
|
| 958 |
$valCount++;
|
| 959 |
}
|
| 960 |
$bankCount++;
|
| 961 |
}
|
| 962 |
-
} else
|
| 963 |
$bankInfos = null;
|
|
|
|
| 964 |
return $bankInfos;
|
| 965 |
}
|
| 966 |
-
|
| 967 |
-
|
| 968 |
-
|
| 969 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 970 |
public function getSupplyDate($quoteId)
|
| 971 |
{
|
| 972 |
$store = Mage::getStoreConfig('tappz/general/store');
|
|
@@ -1010,7 +1143,6 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 1010 |
$by_3 = false;
|
| 1011 |
$by_0 = false;
|
| 1012 |
}
|
| 1013 |
-
|
| 1014 |
$cMsg = '';
|
| 1015 |
if ($by_0) {
|
| 1016 |
$cMsg = "Sepetinizdeki ürünlerin tamamı aynı günde kargoya teslim edilecektir.";
|
|
@@ -1027,7 +1159,6 @@ class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
|
| 1027 |
if ($by_7) {
|
| 1028 |
$cMsg = "Sepetinizdeki ürünlerin tamamı 7 iş gününde kargoya teslim edilecektir.";
|
| 1029 |
}
|
| 1030 |
-
|
| 1031 |
return $cMsg;
|
| 1032 |
}
|
| 1033 |
}
|
| 1 |
<?php
|
|
|
|
| 2 |
class TmobLabs_Tappz_Model_Basket_Api extends Mage_Api_Model_Resource_Abstract
|
| 3 |
{
|
| 4 |
+
/**
|
| 5 |
+
* @param $quoteId
|
| 6 |
+
* @param null $customerId
|
| 7 |
+
* @return array
|
| 8 |
+
*/
|
| 9 |
public function get($quoteId, $customerId = null)
|
| 10 |
{
|
| 11 |
$decimalDivider = Mage::getStoreConfig('tappz/general/decimalSeparator');
|
| 12 |
$thousandDivider = Mage::getStoreConfig('tappz/general/groupSeparator');
|
| 13 |
$store = Mage::getStoreConfig('tappz/general/store');
|
|
|
|
| 14 |
$lineAverageDeliveryDaysAttributeCode = Mage::getStoreConfig('tappz/basket/averagedeliverydaysattributecode');
|
| 15 |
$creditCardPaymentType = Mage::getStoreConfig('tappz/basket/creditcardpaymenttype');
|
|
|
|
| 16 |
$basket = array();
|
| 17 |
$basket['id'] = null;
|
| 18 |
$basket['lines'] = array();
|
| 80 |
$quoteShippingAddress = $quote->getShippingAddress();
|
| 81 |
if ($quoteShippingAddress) {
|
| 82 |
$basket['delivery']['shippingAddress'] = $addressApi->get($quoteShippingAddress->getData('customer_address_id'));
|
|
|
|
| 83 |
$basket['delivery']['shippingMethod']['id'] = $quoteShippingAddress->getData('shipping_method');
|
| 84 |
$basket['delivery']['shippingMethod']['displayName'] = $quoteShippingAddress->getData('shipping_description');
|
| 85 |
$basket['delivery']['shippingMethod']['trackingAddress'] = null;
|
| 89 |
$basket['delivery']['shippingMethod']['imageUrl'] = null;
|
| 90 |
$basket['discountTotal'] = number_format($quoteShippingAddress->getData('discount_amount'), 2, $decimalDivider, $thousandDivider);
|
| 91 |
$basket['shippingTotal'] = number_format($quoteShippingAddress->getData('shipping_incl_tax'), 2, $decimalDivider, $thousandDivider);
|
|
|
|
|
|
|
| 92 |
}
|
| 93 |
$basket['itemsPriceTotal'] = number_format($quote->getData('base_subtotal'), 2, $decimalDivider, $thousandDivider);
|
| 94 |
if (!isset($basket['discountTotal']))
|
| 155 |
$paymentData['accountNumber'] = null;
|
| 156 |
$paymentData['branch'] = null;
|
| 157 |
$paymentData['iban'] = null;
|
| 158 |
+
} else if ($method == 'stripe') {
|
| 159 |
$paymentData['methodType'] = 'ApplePay';
|
| 160 |
$paymentData['type'] = $method;
|
| 161 |
$paymentData['displayName'] = 'Apple Pay';
|
| 177 |
$code = $method->getCode();
|
| 178 |
if ($code == $creditCardPaymentType) {
|
| 179 |
try {
|
| 180 |
+
$paymentOptions['creditCards'] = $this->installmentCash($quote->getId());
|
| 181 |
} catch (Exception $e) {
|
| 182 |
$paymentOptions['creditCards'] = array();
|
| 183 |
}
|
| 197 |
$paymentOptions['moneyTransfers'][0]['branch'] = ' ';
|
| 198 |
$paymentOptions['moneyTransfers'][0]['accountNumber'] = ' ';
|
| 199 |
$paymentOptions['moneyTransfers'][0]['iban'] = ' ';
|
| 200 |
+
$paymentOptions['moneyTransfers'][0]['imageUrl'] = ''; // TODO
|
| 201 |
} elseif ($code == 'cashondelivery') {
|
| 202 |
$paymentOptions['cashOnDelivery'] = array();
|
| 203 |
$paymentOptions['cashOnDelivery']['type'] = null;
|
| 209 |
$paymentOptions['cashOnDelivery']['PhoneNumber'] = null;
|
| 210 |
$paymentOptions['cashOnDelivery']['type'] = $code;
|
| 211 |
$paymentOptions['cashOnDelivery']['displayName'] = $method->getTitle();
|
| 212 |
+
$paymentOptions['cashOnDelivery']['additionalFee'] = '0';
|
| 213 |
+
$paymentOptions['cashOnDelivery']['description'] = 'Cash on delivery description text';
|
| 214 |
$paymentOptions['cashOnDelivery']['isSMSVerification'] = false;
|
| 215 |
$paymentOptions['cashOnDelivery']['SMSCode'] = null;
|
| 216 |
$paymentOptions['cashOnDelivery']['PhoneNumber'] = null;
|
| 226 |
}
|
| 227 |
}
|
| 228 |
$basket['paymentOptions'] = $paymentOptions;
|
|
|
|
| 229 |
$shippingMethods = array();
|
| 230 |
if (isset($quoteShippingAddress)) {
|
| 231 |
+
$quoteShippingAddress->collectShippingRates()->save();
|
| 232 |
+
$groupedRates = $quoteShippingAddress->getGroupedAllShippingRates();
|
| 233 |
+
foreach ($groupedRates as $carrierCode => $rates) {
|
| 234 |
+
foreach ($rates as $rate) {
|
| 235 |
+
$rateItem = array();
|
| 236 |
+
$rateItem['id'] = $rate->getData('code');
|
| 237 |
+
$rateItem['displayName'] = $rate->getData('method_title');
|
| 238 |
+
$rateItem['trackingAddress'] = null;
|
| 239 |
+
$rateItem['price'] = number_format($rate->getData('price'), 2, $decimalDivider, $thousandDivider);
|
| 240 |
+
$rateItem['priceForYou'] = null;
|
| 241 |
+
$rateItem['shippingMethodType'] = $rate->getData('code');
|
| 242 |
+
$rateItem['imageUrl'] = null;
|
| 243 |
+
$shippingMethods[] = $rateItem;
|
|
|
|
| 244 |
}
|
| 245 |
+
}
|
| 246 |
}
|
| 247 |
$basket['shippingMethods'] = $shippingMethods;
|
|
|
|
| 248 |
$giftCheques = array();
|
| 249 |
if ($quote->getData('gift_cards')) {
|
| 250 |
// TODO
|
| 271 |
$basket['errors'] = $quote->getErrors();
|
| 272 |
return $basket;
|
| 273 |
}
|
| 274 |
+
/**
|
| 275 |
+
* @param $anonymousQuoteId
|
| 276 |
+
* @param $customerId
|
| 277 |
+
* @return array
|
| 278 |
+
*/
|
| 279 |
public function merge($anonymousQuoteId, $customerId)
|
| 280 |
{
|
| 281 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 305 |
}
|
| 306 |
return $this->get($quote->getId());
|
| 307 |
}
|
| 308 |
+
/**
|
| 309 |
+
* @param $quoteId
|
| 310 |
+
* @param $updateList
|
| 311 |
+
* @return array
|
| 312 |
+
*/
|
| 313 |
public function updateItems($quoteId, $updateList)
|
| 314 |
{
|
| 315 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 333 |
$quote->setTotalsCollectedFlag(false)->collectTotals()->save();
|
| 334 |
return $this->get($quote->getId());
|
| 335 |
}
|
| 336 |
+
/**
|
| 337 |
+
* @param $quoteId
|
| 338 |
+
* @param $shippingAddressId
|
| 339 |
+
* @param $billingAddressId
|
| 340 |
+
* @param $shippingMethodId
|
| 341 |
+
* @return array
|
| 342 |
+
*/
|
| 343 |
public function setAddress($quoteId, $shippingAddressId, $billingAddressId, $shippingMethodId)
|
| 344 |
{
|
| 345 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 346 |
+
$quote = Mage::getModel("sales/quote")
|
| 347 |
->setStoreId($store)
|
| 348 |
->load($quoteId);
|
| 349 |
if (!is_null($billingAddressId)) {
|
| 355 |
->importCustomerAddress($customerBillingAddress);
|
| 356 |
$quote->setBillingAddress($billingAddress);
|
| 357 |
}
|
|
|
|
| 358 |
if (!is_null($shippingAddressId)) {
|
| 359 |
$customerShippingAddress = Mage::getModel('customer/address')
|
| 360 |
->load($shippingAddressId);
|
| 382 |
$this->_fault('invalid_data', $e->getMessage());
|
| 383 |
}
|
| 384 |
}
|
|
|
|
| 385 |
$quote->setTotalsCollectedFlag(false)->collectTotals()->save();
|
| 386 |
return $this->get($quote->getId());
|
| 387 |
}
|
| 388 |
+
/**
|
| 389 |
+
* @param $quoteId
|
| 390 |
+
* @param $isSelected
|
| 391 |
+
* @param $message
|
| 392 |
+
* @return array
|
| 393 |
+
*/
|
| 394 |
public function setGiftWrapping($quoteId, $isSelected, $message)
|
| 395 |
{
|
| 396 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 412 |
}
|
| 413 |
return $this->get($quote->getId());
|
| 414 |
}
|
| 415 |
+
/**
|
| 416 |
+
* @param $quoteId
|
| 417 |
+
* @param $promoCode
|
| 418 |
+
* @return array
|
| 419 |
+
*/
|
| 420 |
public function useDiscount($quoteId, $promoCode)
|
| 421 |
{
|
| 422 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 432 |
}
|
| 433 |
return $this->get($quote->getId());
|
| 434 |
}
|
| 435 |
+
/**
|
| 436 |
+
* @param $quoteId
|
| 437 |
+
* @return array
|
| 438 |
+
*/
|
| 439 |
public function deleteDiscount($quoteId)
|
| 440 |
{
|
| 441 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 451 |
}
|
| 452 |
return $this->get($quote->getId());
|
| 453 |
}
|
| 454 |
+
/**
|
| 455 |
+
* @param $quoteId
|
| 456 |
+
* @param $code
|
| 457 |
+
* @return array
|
| 458 |
+
*/
|
| 459 |
public function useGiftCheques($quoteId, $code)
|
| 460 |
{
|
| 461 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 462 |
+
|
| 463 |
$quote = Mage::getModel("sales/quote")
|
| 464 |
->setStoreId($store)
|
| 465 |
->load($quoteId);
|
| 466 |
return $this->get($quote->getId());
|
| 467 |
}
|
| 468 |
+
/**
|
| 469 |
+
* @param $quoteId
|
| 470 |
+
* @return array
|
| 471 |
+
*/
|
| 472 |
public function deleteGiftCheques($quoteId)
|
| 473 |
{
|
| 474 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 477 |
->load($quoteId);
|
| 478 |
return $this->get($quote->getId());
|
| 479 |
}
|
| 480 |
+
/**
|
| 481 |
+
* @param $quoteId
|
| 482 |
+
* @param $points
|
| 483 |
+
* @return array
|
| 484 |
+
*/
|
| 485 |
public function useUserPoints($quoteId, $points)
|
| 486 |
{
|
| 487 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 488 |
$quote = Mage::getModel("sales/quote")
|
| 489 |
->setStoreId($store)
|
| 490 |
->load($quoteId);
|
| 491 |
+
return $this->get($quote->getId());
|
| 492 |
}
|
| 493 |
+
/**
|
| 494 |
+
* @param $quoteId
|
| 495 |
+
* @param $payment
|
| 496 |
+
* @return array
|
| 497 |
+
*/
|
| 498 |
public function selectPaymentMethod($quoteId, $payment)
|
| 499 |
{
|
| 500 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 528 |
$paymentData['cc_exp_month'] = $creditCard->month;
|
| 529 |
$paymentData['cc_exp_year'] = $creditCard->year;
|
| 530 |
$paymentData['cc_cid'] = $creditCard->cvv;
|
| 531 |
+
$session = Mage::getSingleton('core/session');
|
| 532 |
$session->setData('ccNumber', $creditCard->number);
|
| 533 |
$session->setData('ccType', $type);
|
| 534 |
$session->setData('expYear', $creditCard->year);
|
| 535 |
$session->setData('expMonth', $creditCard->month);
|
| 536 |
+
$session->setData('cvv', $creditCard->cvv);
|
| 537 |
} else {
|
| 538 |
return $this->get($quote->getId());
|
| 539 |
}
|
| 553 |
return $this->get($quote->getId());
|
| 554 |
break;
|
| 555 |
}
|
|
|
|
| 556 |
$paymentData['method'] = $paymentMethod;
|
| 557 |
$quote = $this->setPaymentData($quote, $paymentData);
|
| 558 |
return $this->get($quote->getId());
|
| 559 |
+
}
|
| 560 |
|
| 561 |
+
|
| 562 |
+
/**
|
| 563 |
+
* @param $quote
|
| 564 |
+
* @param $paymentData
|
| 565 |
+
* @return Mage_Sales_Model_Quote
|
| 566 |
+
*/
|
| 567 |
protected function setPaymentData($quote, $paymentData)
|
| 568 |
{
|
| 569 |
/* @var $quote Mage_Sales_Model_Quote */
|
| 615 |
}
|
| 616 |
return $quote;
|
| 617 |
}
|
| 618 |
+
|
| 619 |
+
/**
|
| 620 |
+
* @param $method
|
| 621 |
+
* @param $quote
|
| 622 |
+
* @return bool
|
| 623 |
+
*/
|
| 624 |
protected function _canUsePaymentMethod($method, $quote)
|
| 625 |
{
|
| 626 |
if (!$method->canUseForCountry($quote->getBillingAddress()->getCountry())) {
|
| 637 |
}
|
| 638 |
return true;
|
| 639 |
}
|
| 640 |
+
/**
|
| 641 |
+
* @param $quote
|
| 642 |
+
* @return mixed
|
| 643 |
+
*/
|
| 644 |
protected function purchase($quote)
|
| 645 |
{
|
| 646 |
if ($quote->getIsMultiShipping()) {
|
| 679 |
Mage::logException($e);
|
| 680 |
}
|
| 681 |
}
|
|
|
|
| 682 |
Mage::dispatchEvent(
|
| 683 |
'checkout_submit_all_after',
|
| 684 |
array('order' => $order, 'quote' => $quote)
|
| 689 |
$quote->setIsActive(false)->save();
|
| 690 |
return $order->getIncrementId();
|
| 691 |
}
|
|
|
|
|
|
|
| 692 |
|
| 693 |
+
/**
|
| 694 |
+
* @param $quoteId
|
| 695 |
+
* @return array
|
| 696 |
+
*/
|
| 697 |
public function getContract($quoteId)
|
| 698 |
{
|
| 699 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 705 |
$agreementsCollection = Mage::getModel('checkout/agreement')->getCollection()
|
| 706 |
->addStoreFilter($store)
|
| 707 |
->addFieldToFilter('is_active', 1);
|
|
|
|
| 708 |
foreach ($agreementsCollection as $_a) {
|
| 709 |
$agreements[] = $_a;
|
| 710 |
}
|
| 711 |
}
|
|
|
|
| 712 |
$contract = array();
|
| 713 |
$contract['salesContact'] = $agreements[0]['content'];
|
| 714 |
$contract['termOfUse'] = $agreements[1]['content'];
|
| 715 |
return $contract;
|
| 716 |
}
|
| 717 |
+
/**
|
| 718 |
+
* @param $quoteId
|
| 719 |
+
* @return mixed
|
| 720 |
+
*
|
| 721 |
+
*/
|
| 722 |
+
public function purchaseCreditCard($quoteId,$payment)
|
| 723 |
{
|
| 724 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 725 |
+
$quote = Mage::getModel("sales/quote")->setStoreId($store)->load($quoteId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 726 |
$orderId = $this->purchase($quote);
|
|
|
|
|
|
|
| 727 |
|
| 728 |
+
$api_key = "214E94E11A1B2FF65839864CBFEEE";
|
| 729 |
+
$post_arr = array(
|
| 730 |
+
"banka" => $payment->bankCode,
|
| 731 |
+
"taksit" => $payment->installment,
|
| 732 |
+
"cc_owner" =>$payment->creditCard->owner,
|
| 733 |
+
"cc_number" =>$payment->creditCard->number,
|
| 734 |
+
"cc_cvv" => $payment->creditCard->cvv,
|
| 735 |
+
"cc_expire_month" => $payment->creditCard->month,
|
| 736 |
+
"cc_expire_year" =>$payment->creditCard->year,
|
| 737 |
+
"order_id" => "$orderId",
|
| 738 |
+
//"quote_id" => "$quoteId",
|
| 739 |
+
"date" => date("Y-m-d H:i:s"),
|
| 740 |
+
"customer_ip" => $this->getClientIP(),
|
| 741 |
+
);
|
| 742 |
+
$hash_text = $post_arr['order_id'].
|
| 743 |
+
//$post_arr['quote_id'].
|
| 744 |
+
$post_arr['banka'].
|
| 745 |
+
$post_arr['cc_number'].
|
| 746 |
+
$api_key.$post_arr['date'];
|
| 747 |
+
$hash = md5($hash_text);
|
| 748 |
+
$post_arr["grinet_mobile_hash"] = $hash;
|
| 749 |
+
$url = Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB)."gtrpay/grinet/".$post_arr['banka']."_payment/";
|
| 750 |
+
$ch = curl_init();
|
| 751 |
+
curl_setopt($ch, CURLOPT_URL,$url);
|
| 752 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,2);
|
| 753 |
+
curl_setopt($ch, CURLOPT_SSLVERSION, 1);
|
| 754 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,1);
|
| 755 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
|
| 756 |
+
curl_setopt($ch, CURLOPT_TIMEOUT, 90);
|
| 757 |
+
curl_setopt($ch, CURLOPT_POST, 1);
|
| 758 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_arr);
|
| 759 |
+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
|
| 760 |
+
$result = curl_exec($ch);
|
| 761 |
+
curl_close($ch);
|
| 762 |
+
$msg = json_decode($result);
|
| 763 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
|
| 764 |
+
if( strtolower( trim($msg->status)) == "error" ){
|
| 765 |
+
if(isset($msg->system_message)){
|
| 766 |
+
$error_msg = $msg->system_message;
|
| 767 |
+
}
|
| 768 |
+
elseif(isset($msg->error_message)){
|
| 769 |
+
$error_msg = $msg->error_message;
|
| 770 |
+
}elseif(isset($msg->customer_message)){
|
| 771 |
+
$error_msg = $msg->customer_message;
|
| 772 |
+
}
|
| 773 |
+
$order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true)->save();
|
| 774 |
+
$this->_fault('invalid_data',$error_msg);
|
| 775 |
+
}elseif(strtolower( trim($msg->status)) == "success") {
|
| 776 |
+
$order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save();
|
| 777 |
+
return Mage::getSingleton('tappz/Customer_Order_Api')->info($orderId);
|
| 778 |
+
}else{
|
| 779 |
+
$order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, true)->save();
|
| 780 |
+
$this->_fault('invalid_data',"Unknown payment status");
|
| 781 |
+
}
|
| 782 |
+
}
|
| 783 |
+
public function getClientIP(){
|
| 784 |
+
if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)){
|
| 785 |
+
return $_SERVER["HTTP_X_FORWARDED_FOR"];
|
| 786 |
+
}else if (array_key_exists('REMOTE_ADDR', $_SERVER)) {
|
| 787 |
+
return $_SERVER["REMOTE_ADDR"];
|
| 788 |
+
}else if (array_key_exists('HTTP_CLIENT_IP', $_SERVER)) {
|
| 789 |
+
return $_SERVER["HTTP_CLIENT_IP"];
|
| 790 |
+
}
|
| 791 |
+
return '';
|
| 792 |
+
}
|
| 793 |
public function purchaseMoneyOrder($quoteId, $moneyOrderType)
|
| 794 |
{
|
| 795 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 799 |
$orderId = $this->purchase($quote);
|
| 800 |
return Mage::getSingleton('tappz/Customer_Order_Api')->info($orderId);
|
| 801 |
}
|
|
|
|
| 802 |
public function purchaseCashOnDelivery($quoteId, $cashOnDelivery)
|
| 803 |
{
|
| 804 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 808 |
$orderId = $this->purchase($quote);
|
| 809 |
return Mage::getSingleton('tappz/Customer_Order_Api')->info($orderId);
|
| 810 |
}
|
| 811 |
+
/**
|
| 812 |
+
* @param $quote
|
| 813 |
+
* @return mixed
|
| 814 |
+
*/
|
|
|
|
| 815 |
public function createNewOrder($quote)
|
| 816 |
{
|
| 817 |
Mage::getSingleton('checkout/session')->replaceQuote($quote);
|
| 820 |
$quote->setIsActive(false);
|
| 821 |
if ($quote->getCustomerId()) {
|
| 822 |
$transaction->addObject($quote->getCustomer());
|
| 823 |
+
}
|
| 824 |
$transaction->addObject($quote);
|
| 825 |
$quote->reserveOrderId();
|
| 826 |
if ($quote->isVirtual()) {
|
| 847 |
}
|
| 848 |
$order->addItem($orderItem);
|
| 849 |
}
|
|
|
|
| 850 |
$order->setCanSendNewEmailFlag(false);
|
| 851 |
$order->setQuoteId($quote->getId());
|
| 852 |
$order->setExtOrderId($quote->getPayment()->getTransactionId());
|
| 853 |
$transaction->addObject($order);
|
| 854 |
$transaction->addCommitCallback(array($order, 'save'));
|
|
|
|
| 855 |
try {
|
| 856 |
$transaction->save();
|
| 857 |
$quote->setIsActive(false)->save();
|
| 863 |
)
|
| 864 |
);
|
| 865 |
} catch (Exception $e) {
|
|
|
|
| 866 |
$order->setId(null);
|
|
|
|
| 867 |
foreach ($order->getItemsCollection() as $item) {
|
| 868 |
$item->setOrderId(null);
|
| 869 |
$item->setItemId(null);
|
| 870 |
}
|
|
|
|
| 871 |
Mage::dispatchEvent(
|
| 872 |
'sales_model_service_quote_submit_failure',
|
| 873 |
array(
|
| 882 |
Mage::dispatchEvent('sales_model_service_quote_submit_after', array('order' => $order, 'quote' => $quote));
|
| 883 |
return $order;
|
| 884 |
}
|
| 885 |
+
/**
|
| 886 |
+
* @param $quoteId
|
| 887 |
+
* @param $transactionId
|
| 888 |
+
* @return mixed
|
| 889 |
+
*/
|
| 890 |
public function purchaseWithPayPal($quoteId, $transactionId)
|
| 891 |
{
|
| 892 |
$paypalIsSandBox = (bool)Mage::getStoreConfig('tappz/basket/paypalissandbox');
|
| 893 |
$paypalClientId = Mage::getStoreConfig('tappz/basket/paypalclientid');
|
| 894 |
$paypalSecret = Mage::getStoreConfig('tappz/basket/paypalSecret');
|
| 895 |
$store = Mage::getStoreConfig('tappz/general/store');
|
|
|
|
| 896 |
$quote = Mage::getModel("sales/quote")
|
| 897 |
->setStoreId($store)
|
| 898 |
->load($quoteId);
|
| 915 |
$token_result_json = curl_exec($ch);
|
| 916 |
curl_close($ch);
|
| 917 |
$token_result = json_decode($token_result_json);
|
|
|
|
| 918 |
$ch = curl_init();
|
| 919 |
curl_setopt($ch, CURLOPT_URL, $url . 'payments/payment/' . $transactionId);
|
| 920 |
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
| 939 |
$this->_fault('invalid_data', 'PayPal transaction is not completed.');
|
| 940 |
}
|
| 941 |
}
|
| 942 |
+
/**
|
| 943 |
+
* @param $quoteId
|
| 944 |
+
* @param $tokenId
|
| 945 |
+
* @return mixed
|
| 946 |
+
*/
|
| 947 |
public function purchaseWithApplePay($quoteId, $tokenId)
|
| 948 |
{
|
| 949 |
$stripeIsTest = (bool)Mage::getStoreConfig('tappz/basket/stripeistest');
|
| 971 |
$charge_json = curl_exec($ch);
|
| 972 |
curl_close($ch);
|
| 973 |
$charge = json_decode($charge_json);
|
|
|
|
| 974 |
$ch = curl_init();
|
| 975 |
curl_setopt($ch, CURLOPT_URL, 'https://api.stripe.com/v1/charges/' . $charge->id . '/capture');
|
| 976 |
curl_setopt($ch, CURLOPT_USERPWD, $secretKey);
|
| 994 |
$this->_fault('invalid_data', 'Apple Pay transaction is not completed.');
|
| 995 |
}
|
| 996 |
}
|
| 997 |
+
/**
|
| 998 |
+
*
|
| 999 |
+
* @param $quoteId
|
| 1000 |
+
* @return array
|
| 1001 |
+
*
|
| 1002 |
+
* İf you dont use
|
| 1003 |
+
*/
|
| 1004 |
+
public function installmentCash($quoteId)
|
| 1005 |
{
|
| 1006 |
$bankInfos = array();
|
| 1007 |
+
$showInstallments = true;
|
|
|
|
| 1008 |
$cats = array();
|
| 1009 |
$cart = Mage::getModel("sales/quote")->load($quoteId);
|
| 1010 |
+
$amount = $cart->getGrandTotal();
|
| 1011 |
$cartItems = $cart->getItems();
|
| 1012 |
+
/**
|
| 1013 |
+
* İf you have specific categories that not allowed installment please go to excludeCategories
|
| 1014 |
+
* and add your categories id
|
| 1015 |
+
*/
|
| 1016 |
+
$excludeCats = $this->excludeCategories();
|
| 1017 |
+
if(count($excludeCats) > 0){
|
| 1018 |
+
foreach ($cartItems as $item) {
|
| 1019 |
+
$cats[] = $item->getProduct()->getCategoryIds();
|
| 1020 |
+
}
|
| 1021 |
+
if (count($cats) > 0) {
|
| 1022 |
+
foreach ($cats as $rows) {
|
| 1023 |
+
foreach ($rows as $row) {
|
| 1024 |
+
if (in_array($row, $excludeCats)) {
|
| 1025 |
+
$showInstallments = false;
|
| 1026 |
+
}
|
| 1027 |
}
|
| 1028 |
}
|
| 1029 |
}
|
| 1030 |
}
|
| 1031 |
+
|
| 1032 |
+
/**
|
| 1033 |
+
* İf you use any extension you have to add here
|
| 1034 |
+
*/
|
| 1035 |
+
$model = Mage::getModel('Grinet_Turkpay_Model_Grinet');
|
| 1036 |
+
|
| 1037 |
+
if ($model) {
|
| 1038 |
+
/**
|
| 1039 |
+
* Get your banks
|
| 1040 |
+
*/
|
| 1041 |
+
$banks = $model->bankalar();
|
| 1042 |
}
|
| 1043 |
+
if (!empty($banks)) {
|
| 1044 |
$bankCount = 0;
|
| 1045 |
+
$fee = 0;
|
| 1046 |
+
foreach ($banks as $bank_code => $bank) {
|
| 1047 |
+
/**
|
| 1048 |
+
* Get Instalments
|
| 1049 |
+
*/
|
| 1050 |
+
$installments = $model->taksitler($bank_code, $amount);
|
| 1051 |
$valCount = 0;
|
| 1052 |
+
foreach ($installments as $key => $toran) {
|
| 1053 |
+
$totalAmount = $amount + (($amount / 100) * floatval($toran)) + $fee;
|
| 1054 |
+
$custom_title = Mage::getStoreConfig($bank_code . '/taksit_baslik/taksit_' . $key);
|
| 1055 |
+
$installmentTitle = (trim($custom_title) == '')? false :$custom_title;
|
| 1056 |
+
/**
|
| 1057 |
+
* Bank logo & image
|
| 1058 |
+
*/
|
| 1059 |
+
$bankInfos[$bankCount]['image'] = null;
|
| 1060 |
+
/**
|
| 1061 |
+
* Bank name
|
| 1062 |
+
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1063 |
$bankInfos[$bankCount]['displayName'] = trim($bank['name']);
|
| 1064 |
+
/**
|
| 1065 |
+
* Bank type
|
| 1066 |
+
*/
|
| 1067 |
+
$bankInfos[$bankCount]['type'] = $bank_code;
|
| 1068 |
+
/**
|
| 1069 |
+
* Bank installments (example : if you have 9 months installments you should simply add "9" )
|
| 1070 |
+
*/
|
| 1071 |
+
$bankInfos[$bankCount]['installmentNumber'] = null;
|
| 1072 |
+
$bankInfos[$bankCount]['installments'][$valCount]['installmentNumber'] = null;
|
| 1073 |
+
$bankInfos[$bankCount]['installments'][$valCount]['installmentPayment'] = round($totalAmount / $valCount, 2, PHP_ROUND_HALF_UP);
|
| 1074 |
+
$bankInfos[$bankCount]['installments'][$valCount]['total'] = round($totalAmount, 2, PHP_ROUND_HALF_UP);
|
| 1075 |
+
if ($showInstallments === false && $installmentTitle == false) {
|
| 1076 |
+
break;
|
| 1077 |
}
|
| 1078 |
$valCount++;
|
| 1079 |
}
|
| 1080 |
$bankCount++;
|
| 1081 |
}
|
| 1082 |
+
} else{
|
| 1083 |
$bankInfos = null;
|
| 1084 |
+
}
|
| 1085 |
return $bankInfos;
|
| 1086 |
}
|
| 1087 |
+
/**
|
| 1088 |
+
* İf you have specific categories that not allowed installment Cash
|
| 1089 |
+
* Please set category ids in array
|
| 1090 |
+
* Example : $categories = array("{{category_id}}","{{category_id}}");
|
| 1091 |
+
*
|
| 1092 |
+
*/
|
| 1093 |
+
public function excludeCategories()
|
| 1094 |
+
{
|
| 1095 |
+
$categories = array();
|
| 1096 |
+
return $categories;
|
| 1097 |
+
}
|
| 1098 |
+
/**
|
| 1099 |
+
* @param $quoteId
|
| 1100 |
+
* @return string
|
| 1101 |
+
*
|
| 1102 |
+
*/
|
| 1103 |
public function getSupplyDate($quoteId)
|
| 1104 |
{
|
| 1105 |
$store = Mage::getStoreConfig('tappz/general/store');
|
| 1143 |
$by_3 = false;
|
| 1144 |
$by_0 = false;
|
| 1145 |
}
|
|
|
|
| 1146 |
$cMsg = '';
|
| 1147 |
if ($by_0) {
|
| 1148 |
$cMsg = "Sepetinizdeki ürünlerin tamamı aynı günde kargoya teslim edilecektir.";
|
| 1159 |
if ($by_7) {
|
| 1160 |
$cMsg = "Sepetinizdeki ürünlerin tamamı 7 iş gününde kargoya teslim edilecektir.";
|
| 1161 |
}
|
|
|
|
| 1162 |
return $cMsg;
|
| 1163 |
}
|
| 1164 |
}
|
app/code/community/TmobLabs/Tappz/Model/Catalog/Api.php
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
<?php
|
| 2 |
-
|
| 3 |
class TmobLabs_Tappz_Model_Catalog_Api extends Mage_Catalog_Model_Api_Resource
|
| 4 |
{
|
|
|
|
|
|
|
|
|
|
| 5 |
public function getFrontPage()
|
| 6 |
{
|
| 7 |
$sampleEx['ads'][0]['name'] = null;
|
|
@@ -11,7 +13,7 @@ class TmobLabs_Tappz_Model_Catalog_Api extends Mage_Catalog_Model_Api_Resource
|
|
| 11 |
$frontPageCategory1 = Mage::getStoreConfig('tappz/catalog/catalog1');
|
| 12 |
if ($frontPageCategory1) {
|
| 13 |
$category = $this->getCategory($frontPageCategory1);
|
| 14 |
-
$productList = $this->getProductList(null, $frontPageCategory1, 0,
|
| 15 |
$group = array();
|
| 16 |
$group['partName'] = $category['name'];
|
| 17 |
$group['products'] = $productList['products'];
|
|
@@ -20,7 +22,7 @@ class TmobLabs_Tappz_Model_Catalog_Api extends Mage_Catalog_Model_Api_Resource
|
|
| 20 |
$frontPageCategory2 = Mage::getStoreConfig('tappz/catalog/catalog2');
|
| 21 |
if ($frontPageCategory2) {
|
| 22 |
$category = $this->getCategory($frontPageCategory2);
|
| 23 |
-
$productList = $this->getProductList(null, $frontPageCategory2, 0,
|
| 24 |
$group = array();
|
| 25 |
$group['partName'] = $category['name'];
|
| 26 |
$group['products'] = $productList['products'];
|
|
@@ -29,7 +31,7 @@ class TmobLabs_Tappz_Model_Catalog_Api extends Mage_Catalog_Model_Api_Resource
|
|
| 29 |
$frontPageCategory3 = Mage::getStoreConfig('tappz/catalog/catalog3');
|
| 30 |
if ($frontPageCategory3) {
|
| 31 |
$category = $this->getCategory($frontPageCategory3);
|
| 32 |
-
$productList = $this->getProductList(null, $frontPageCategory3, 0,
|
| 33 |
$group = array();
|
| 34 |
$group['partName'] = $category['name'];
|
| 35 |
$group['products'] = $productList['products'];
|
|
@@ -38,7 +40,7 @@ class TmobLabs_Tappz_Model_Catalog_Api extends Mage_Catalog_Model_Api_Resource
|
|
| 38 |
$frontPageCategory4 = Mage::getStoreConfig('tappz/catalog/catalog4');
|
| 39 |
if ($frontPageCategory4) {
|
| 40 |
$category = $this->getCategory($frontPageCategory4);
|
| 41 |
-
$productList = $this->getProductList(null, $frontPageCategory4, 0,
|
| 42 |
$group = array();
|
| 43 |
$group['partName'] = $category['name'];
|
| 44 |
$group['products'] = $productList['products'];
|
|
@@ -46,17 +48,18 @@ class TmobLabs_Tappz_Model_Catalog_Api extends Mage_Catalog_Model_Api_Resource
|
|
| 46 |
}
|
| 47 |
return $sampleEx;
|
| 48 |
}
|
| 49 |
-
|
|
|
|
|
|
|
| 50 |
public function getCategories()
|
| 51 |
{
|
| 52 |
$storeId = (int)Mage::getStoreConfig('tappz/general/store');
|
| 53 |
if ($storeId <= 0) {
|
| 54 |
$storeId = 1;
|
| 55 |
}
|
| 56 |
-
|
| 57 |
/** @var Mage_Core_Model_Store $store */
|
| 58 |
$store = Mage::getModel('core/store')->load($storeId);
|
| 59 |
-
|
| 60 |
$rootCategoryId = $store->getRootCategoryId();
|
| 61 |
if (!$rootCategoryId) {
|
| 62 |
$rootCategoryId = 2;
|
|
@@ -64,6 +67,10 @@ class TmobLabs_Tappz_Model_Catalog_Api extends Mage_Catalog_Model_Api_Resource
|
|
| 64 |
$rootCategory = $this->getCategory($rootCategoryId);
|
| 65 |
return $rootCategory['children'];
|
| 66 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
public function getCategory($categoryId)
|
| 68 |
{
|
| 69 |
$storeId = Mage::getStoreConfig('tappz/general/store');
|
|
@@ -77,12 +84,11 @@ class TmobLabs_Tappz_Model_Catalog_Api extends Mage_Catalog_Model_Api_Resource
|
|
| 77 |
->setStoreId($this->_getStoreId($storeId))
|
| 78 |
->addAttributeToSelect('name')
|
| 79 |
->addAttributeToSelect('is_active')
|
| 80 |
-
|
| 81 |
->addIsActiveFilter();
|
| 82 |
$tree->addCollectionData($collection, true);
|
| 83 |
return $this->categoryToModel($root);
|
| 84 |
}
|
| 85 |
-
|
| 86 |
/**
|
| 87 |
* @param $temp Mage_Catalog_Model_Category
|
| 88 |
* @param bool $getChildren
|
|
@@ -97,24 +103,43 @@ class TmobLabs_Tappz_Model_Catalog_Api extends Mage_Catalog_Model_Api_Resource
|
|
| 97 |
$category['isLeaf'] = $temp->getChildrenCount() == 0;
|
| 98 |
$category['parentCategoryId'] = $temp->getParentId();
|
| 99 |
$category['children'] = array();
|
| 100 |
-
|
| 101 |
if ($getChildren) {
|
| 102 |
foreach ($temp->getChildren() as $child) {
|
| 103 |
$category['children'][] = $this->categoryToModel($child, false);
|
| 104 |
}
|
| 105 |
}
|
| 106 |
-
|
| 107 |
return $category;
|
| 108 |
}
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
public function getProductList($phrase, $categoryId, $pageNumber, $pageSize, $filterQuery, $sort)
|
| 111 |
{
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
->getCollection()
|
| 114 |
->addAttributeToSelect('*')
|
| 115 |
->addAttributeToFilter('status', '1')
|
| 116 |
->addAttributeToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
|
| 117 |
-
|
| 118 |
|
| 119 |
if (!empty($filter)) {
|
| 120 |
foreach ($filter as $f) {
|
|
@@ -124,53 +149,58 @@ class TmobLabs_Tappz_Model_Catalog_Api extends Mage_Catalog_Model_Api_Resource
|
|
| 124 |
}
|
| 125 |
}
|
| 126 |
}
|
| 127 |
-
|
| 128 |
if (!empty($phrase))
|
| 129 |
$collection->addAttributeToFilter('name', array('like' => "%$phrase%"));
|
| 130 |
-
|
| 131 |
if (!empty($categoryId)) {
|
| 132 |
$collection->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left');
|
| 133 |
$collection->addAttributeToFilter('category_id', array('eq' => $categoryId));
|
| 134 |
}
|
| 135 |
-
|
| 136 |
$total = $collection->getSize();
|
| 137 |
if (!empty($sort)) {
|
| 138 |
$sortArr = explode("-", $sort);
|
| 139 |
$collection->addAttributeToSort($sortArr[0], $sortArr[1]);
|
| 140 |
}
|
| 141 |
-
$pageSize = 5;
|
| 142 |
-
empty($pageNumber) ? $pageNumber = 1 : $pageNumber +=1;
|
| 143 |
|
|
|
|
| 144 |
if (empty($pageSize))
|
| 145 |
-
$pageSize =
|
| 146 |
-
|
| 147 |
$collection->setPage($pageNumber, $pageSize);
|
| 148 |
-
|
| 149 |
$result = array();
|
| 150 |
$result['total'] = null;
|
| 151 |
$result['filters'] = array();
|
| 152 |
$result['sortList'] = array();
|
| 153 |
$result['products'] = array();
|
| 154 |
-
|
| 155 |
$result['sortList'][] = array('id' => 'name-asc', 'name' => 'Name (Ascending)');
|
| 156 |
$result['sortList'][] = array('id' => 'name-desc', 'name' => 'Name (Descending)');
|
| 157 |
$result['sortList'][] = array('id' => 'price-asc', 'name' => 'Price (Ascending)');
|
| 158 |
$result['sortList'][] = array('id' => 'price-desc', 'name' => 'Price (Descending)');
|
| 159 |
if (!empty($collection)) {
|
| 160 |
foreach ($collection as $_product) {
|
| 161 |
-
$
|
|
|
|
|
|
|
| 162 |
}
|
| 163 |
}
|
|
|
|
| 164 |
return $result;
|
| 165 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
public function getProduct($productId)
|
| 167 |
{
|
|
|
|
| 168 |
$storeId = (int)Mage::getStoreConfig('tappz/general/store');
|
| 169 |
if ($storeId <= 0) {
|
| 170 |
$storeId = 1;
|
| 171 |
}
|
| 172 |
-
|
| 173 |
$product = Mage::getModel('catalog/product')->load($productId);
|
|
|
|
| 174 |
$productInfo = array();
|
| 175 |
$productInfo['id'] = null;
|
| 176 |
$productInfo['productName'] = null;
|
|
@@ -222,17 +252,14 @@ class TmobLabs_Tappz_Model_Catalog_Api extends Mage_Catalog_Model_Api_Resource
|
|
| 222 |
} else {
|
| 223 |
$productInfo['pictures'][0]['url'] = $productInfo['picture'];
|
| 224 |
}
|
| 225 |
-
|
| 226 |
$productInfo['productDetailUrl'] = '<p>' . $product->getDescription() . '</p>';
|
| 227 |
-
|
| 228 |
$isInStock = false;
|
| 229 |
$stockStatus = Mage::getModel('cataloginventory/stock_item')
|
| 230 |
->loadByProduct($product)
|
| 231 |
->getIsInStock();
|
| 232 |
if ($stockStatus == 1)
|
| 233 |
-
|
| 234 |
$productInfo['inStock'] = $isInStock;
|
| 235 |
-
|
| 236 |
$productAttributeCodeIsShippingFree = Mage::getStoreConfig('tappz/catalog/productAttributeCodeShippingInfo');
|
| 237 |
$productInfo['isShipmentFree'] = $product->getData($productAttributeCodeIsShippingFree);
|
| 238 |
$productInfo['productUrl'] = $product->getProductUrl();
|
|
@@ -254,8 +281,6 @@ class TmobLabs_Tappz_Model_Catalog_Api extends Mage_Catalog_Model_Api_Resource
|
|
| 254 |
$group['values'] = array();
|
| 255 |
$group['id'] = $val['attribute_code'];
|
| 256 |
$group['name'] = $val['label'];
|
| 257 |
-
if ($val['attribute_code'] == 'beden')
|
| 258 |
-
$productInfo['additionalDetail'] = "<a href=\"http://annelutfen.com/skin/frontend/purple/purple/images/olcu_tablosu_gri.png\">Ölçü tablosu</a>";
|
| 259 |
foreach ($val['values'] as $vv) {
|
| 260 |
$groupValue = array();
|
| 261 |
$groupValue['id'] = null;
|
|
@@ -271,7 +296,10 @@ class TmobLabs_Tappz_Model_Catalog_Api extends Mage_Catalog_Model_Api_Resource
|
|
| 271 |
$productInfo['shipmentInformation'] = $product->getData($productAttributeCodeShippingInfo);
|
| 272 |
return $productInfo;
|
| 273 |
}
|
| 274 |
-
|
|
|
|
|
|
|
|
|
|
| 275 |
public function getRelatedProducts($productId)
|
| 276 |
{
|
| 277 |
$product = Mage::getModel('catalog/product')->load($productId);
|
|
@@ -289,6 +317,11 @@ class TmobLabs_Tappz_Model_Catalog_Api extends Mage_Catalog_Model_Api_Resource
|
|
| 289 |
}
|
| 290 |
return $arData;
|
| 291 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
public function getChildProductId($parentProductId, $attributeList)
|
| 293 |
{
|
| 294 |
$subProductIds = Mage::getModel('catalog/product_type_configurable')
|
| 1 |
<?php
|
|
|
|
| 2 |
class TmobLabs_Tappz_Model_Catalog_Api extends Mage_Catalog_Model_Api_Resource
|
| 3 |
{
|
| 4 |
+
/**
|
| 5 |
+
* @return mixed
|
| 6 |
+
*/
|
| 7 |
public function getFrontPage()
|
| 8 |
{
|
| 9 |
$sampleEx['ads'][0]['name'] = null;
|
| 13 |
$frontPageCategory1 = Mage::getStoreConfig('tappz/catalog/catalog1');
|
| 14 |
if ($frontPageCategory1) {
|
| 15 |
$category = $this->getCategory($frontPageCategory1);
|
| 16 |
+
$productList = $this->getProductList(null, $frontPageCategory1, 0, 20, null, null);
|
| 17 |
$group = array();
|
| 18 |
$group['partName'] = $category['name'];
|
| 19 |
$group['products'] = $productList['products'];
|
| 22 |
$frontPageCategory2 = Mage::getStoreConfig('tappz/catalog/catalog2');
|
| 23 |
if ($frontPageCategory2) {
|
| 24 |
$category = $this->getCategory($frontPageCategory2);
|
| 25 |
+
$productList = $this->getProductList(null, $frontPageCategory2, 0, 20, null, null);
|
| 26 |
$group = array();
|
| 27 |
$group['partName'] = $category['name'];
|
| 28 |
$group['products'] = $productList['products'];
|
| 31 |
$frontPageCategory3 = Mage::getStoreConfig('tappz/catalog/catalog3');
|
| 32 |
if ($frontPageCategory3) {
|
| 33 |
$category = $this->getCategory($frontPageCategory3);
|
| 34 |
+
$productList = $this->getProductList(null, $frontPageCategory3, 0, 20, null, null);
|
| 35 |
$group = array();
|
| 36 |
$group['partName'] = $category['name'];
|
| 37 |
$group['products'] = $productList['products'];
|
| 40 |
$frontPageCategory4 = Mage::getStoreConfig('tappz/catalog/catalog4');
|
| 41 |
if ($frontPageCategory4) {
|
| 42 |
$category = $this->getCategory($frontPageCategory4);
|
| 43 |
+
$productList = $this->getProductList(null, $frontPageCategory4, 0, 20, null, null);
|
| 44 |
$group = array();
|
| 45 |
$group['partName'] = $category['name'];
|
| 46 |
$group['products'] = $productList['products'];
|
| 48 |
}
|
| 49 |
return $sampleEx;
|
| 50 |
}
|
| 51 |
+
/**
|
| 52 |
+
* @return mixed
|
| 53 |
+
*/
|
| 54 |
public function getCategories()
|
| 55 |
{
|
| 56 |
$storeId = (int)Mage::getStoreConfig('tappz/general/store');
|
| 57 |
if ($storeId <= 0) {
|
| 58 |
$storeId = 1;
|
| 59 |
}
|
| 60 |
+
|
| 61 |
/** @var Mage_Core_Model_Store $store */
|
| 62 |
$store = Mage::getModel('core/store')->load($storeId);
|
|
|
|
| 63 |
$rootCategoryId = $store->getRootCategoryId();
|
| 64 |
if (!$rootCategoryId) {
|
| 65 |
$rootCategoryId = 2;
|
| 67 |
$rootCategory = $this->getCategory($rootCategoryId);
|
| 68 |
return $rootCategory['children'];
|
| 69 |
}
|
| 70 |
+
/**
|
| 71 |
+
* @param $categoryId
|
| 72 |
+
* @return array
|
| 73 |
+
*/
|
| 74 |
public function getCategory($categoryId)
|
| 75 |
{
|
| 76 |
$storeId = Mage::getStoreConfig('tappz/general/store');
|
| 84 |
->setStoreId($this->_getStoreId($storeId))
|
| 85 |
->addAttributeToSelect('name')
|
| 86 |
->addAttributeToSelect('is_active')
|
| 87 |
+
->addAttributeToFilter('include_in_menu', 1)
|
| 88 |
->addIsActiveFilter();
|
| 89 |
$tree->addCollectionData($collection, true);
|
| 90 |
return $this->categoryToModel($root);
|
| 91 |
}
|
|
|
|
| 92 |
/**
|
| 93 |
* @param $temp Mage_Catalog_Model_Category
|
| 94 |
* @param bool $getChildren
|
| 103 |
$category['isLeaf'] = $temp->getChildrenCount() == 0;
|
| 104 |
$category['parentCategoryId'] = $temp->getParentId();
|
| 105 |
$category['children'] = array();
|
|
|
|
| 106 |
if ($getChildren) {
|
| 107 |
foreach ($temp->getChildren() as $child) {
|
| 108 |
$category['children'][] = $this->categoryToModel($child, false);
|
| 109 |
}
|
| 110 |
}
|
|
|
|
| 111 |
return $category;
|
| 112 |
}
|
| 113 |
+
|
| 114 |
+
/**
|
| 115 |
+
* @param $phrase
|
| 116 |
+
* @param $categoryId
|
| 117 |
+
* @param $pageNumber
|
| 118 |
+
* @param $pageSize
|
| 119 |
+
* @param $filterQuery
|
| 120 |
+
* @param $sort
|
| 121 |
+
* @return array
|
| 122 |
+
*/
|
| 123 |
public function getProductList($phrase, $categoryId, $pageNumber, $pageSize, $filterQuery, $sort)
|
| 124 |
{
|
| 125 |
+
$storeId = (int)Mage::getStoreConfig('tappz/general/store');
|
| 126 |
+
if ($storeId <= 0) {
|
| 127 |
+
$storeId = 1;
|
| 128 |
+
}
|
| 129 |
+
Mage::app()->setCurrentStore($storeId); //this part is hard coded TODO
|
| 130 |
+
if($categoryId){
|
| 131 |
+
$layer = Mage::getModel('catalog/layer');
|
| 132 |
+
$category = Mage::getModel("catalog/category")->load($categoryId);
|
| 133 |
+
$layer->setCurrentCategory($category);
|
| 134 |
+
$collection = $layer->getProductCollection()
|
| 135 |
+
->addAttributeToSelect('*');
|
| 136 |
+
}else{
|
| 137 |
+
$collection = Mage::getModel('catalog/product')
|
| 138 |
->getCollection()
|
| 139 |
->addAttributeToSelect('*')
|
| 140 |
->addAttributeToFilter('status', '1')
|
| 141 |
->addAttributeToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
|
| 142 |
+
}
|
| 143 |
|
| 144 |
if (!empty($filter)) {
|
| 145 |
foreach ($filter as $f) {
|
| 149 |
}
|
| 150 |
}
|
| 151 |
}
|
| 152 |
+
|
| 153 |
if (!empty($phrase))
|
| 154 |
$collection->addAttributeToFilter('name', array('like' => "%$phrase%"));
|
|
|
|
| 155 |
if (!empty($categoryId)) {
|
| 156 |
$collection->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left');
|
| 157 |
$collection->addAttributeToFilter('category_id', array('eq' => $categoryId));
|
| 158 |
}
|
| 159 |
+
|
| 160 |
$total = $collection->getSize();
|
| 161 |
if (!empty($sort)) {
|
| 162 |
$sortArr = explode("-", $sort);
|
| 163 |
$collection->addAttributeToSort($sortArr[0], $sortArr[1]);
|
| 164 |
}
|
|
|
|
|
|
|
| 165 |
|
| 166 |
+
empty($pageNumber) ? $pageNumber = 1 : $pageNumber +=1;
|
| 167 |
if (empty($pageSize))
|
| 168 |
+
$pageSize = 20;
|
|
|
|
| 169 |
$collection->setPage($pageNumber, $pageSize);
|
|
|
|
| 170 |
$result = array();
|
| 171 |
$result['total'] = null;
|
| 172 |
$result['filters'] = array();
|
| 173 |
$result['sortList'] = array();
|
| 174 |
$result['products'] = array();
|
| 175 |
+
|
| 176 |
$result['sortList'][] = array('id' => 'name-asc', 'name' => 'Name (Ascending)');
|
| 177 |
$result['sortList'][] = array('id' => 'name-desc', 'name' => 'Name (Descending)');
|
| 178 |
$result['sortList'][] = array('id' => 'price-asc', 'name' => 'Price (Ascending)');
|
| 179 |
$result['sortList'][] = array('id' => 'price-desc', 'name' => 'Price (Descending)');
|
| 180 |
if (!empty($collection)) {
|
| 181 |
foreach ($collection as $_product) {
|
| 182 |
+
$product = $this->getProduct($_product->getId());
|
| 183 |
+
if($product)
|
| 184 |
+
$result['products'][] = $product;
|
| 185 |
}
|
| 186 |
}
|
| 187 |
+
$result['total'] = count( $result['products']);
|
| 188 |
return $result;
|
| 189 |
}
|
| 190 |
+
/**
|
| 191 |
+
* @param $productId
|
| 192 |
+
* @return array
|
| 193 |
+
*/
|
| 194 |
public function getProduct($productId)
|
| 195 |
{
|
| 196 |
+
|
| 197 |
$storeId = (int)Mage::getStoreConfig('tappz/general/store');
|
| 198 |
if ($storeId <= 0) {
|
| 199 |
$storeId = 1;
|
| 200 |
}
|
| 201 |
+
$store = Mage::getModel('core/store')->load($storeId);
|
| 202 |
$product = Mage::getModel('catalog/product')->load($productId);
|
| 203 |
+
|
| 204 |
$productInfo = array();
|
| 205 |
$productInfo['id'] = null;
|
| 206 |
$productInfo['productName'] = null;
|
| 252 |
} else {
|
| 253 |
$productInfo['pictures'][0]['url'] = $productInfo['picture'];
|
| 254 |
}
|
|
|
|
| 255 |
$productInfo['productDetailUrl'] = '<p>' . $product->getDescription() . '</p>';
|
|
|
|
| 256 |
$isInStock = false;
|
| 257 |
$stockStatus = Mage::getModel('cataloginventory/stock_item')
|
| 258 |
->loadByProduct($product)
|
| 259 |
->getIsInStock();
|
| 260 |
if ($stockStatus == 1)
|
| 261 |
+
$isInStock = true;
|
| 262 |
$productInfo['inStock'] = $isInStock;
|
|
|
|
| 263 |
$productAttributeCodeIsShippingFree = Mage::getStoreConfig('tappz/catalog/productAttributeCodeShippingInfo');
|
| 264 |
$productInfo['isShipmentFree'] = $product->getData($productAttributeCodeIsShippingFree);
|
| 265 |
$productInfo['productUrl'] = $product->getProductUrl();
|
| 281 |
$group['values'] = array();
|
| 282 |
$group['id'] = $val['attribute_code'];
|
| 283 |
$group['name'] = $val['label'];
|
|
|
|
|
|
|
| 284 |
foreach ($val['values'] as $vv) {
|
| 285 |
$groupValue = array();
|
| 286 |
$groupValue['id'] = null;
|
| 296 |
$productInfo['shipmentInformation'] = $product->getData($productAttributeCodeShippingInfo);
|
| 297 |
return $productInfo;
|
| 298 |
}
|
| 299 |
+
/**
|
| 300 |
+
* @param $productId
|
| 301 |
+
* @return array
|
| 302 |
+
*/
|
| 303 |
public function getRelatedProducts($productId)
|
| 304 |
{
|
| 305 |
$product = Mage::getModel('catalog/product')->load($productId);
|
| 317 |
}
|
| 318 |
return $arData;
|
| 319 |
}
|
| 320 |
+
/**
|
| 321 |
+
* @param $parentProductId
|
| 322 |
+
* @param $attributeList
|
| 323 |
+
* @return int
|
| 324 |
+
*/
|
| 325 |
public function getChildProductId($parentProductId, $attributeList)
|
| 326 |
{
|
| 327 |
$subProductIds = Mage::getModel('catalog/product_type_configurable')
|
app/code/community/TmobLabs/Tappz/Model/Customer/Api.php
CHANGED
|
@@ -1,7 +1,10 @@
|
|
| 1 |
<?php
|
| 2 |
-
|
| 3 |
class TmobLabs_Tappz_Model_Customer_Api extends Mage_Customer_Model_Api_Resource
|
| 4 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
protected function _prepareCustomerData($data)
|
| 6 |
{
|
| 7 |
$genderAttributeCode = Mage::getStoreConfig('tappz/customer/gender');
|
|
@@ -20,7 +23,10 @@ class TmobLabs_Tappz_Model_Customer_Api extends Mage_Customer_Model_Api_Resource
|
|
| 20 |
$result[$birthDateAttributeCode] = $data->birthDate;
|
| 21 |
return $result;
|
| 22 |
}
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
public function info($customerId)
|
| 25 |
{
|
| 26 |
$genderAttributeCode = Mage::getStoreConfig('tappz/customer/gender');
|
|
@@ -55,10 +61,8 @@ class TmobLabs_Tappz_Model_Customer_Api extends Mage_Customer_Model_Api_Resource
|
|
| 55 |
$result['email'] = $customer->getData($emailAttributeCode);
|
| 56 |
$result['phone'] = $customer->getData($phoneAttributeCode);
|
| 57 |
$result['birthDate'] = $customer->getData($birthDateAttributeCode);
|
| 58 |
-
|
| 59 |
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customer->getData($emailAttributeCode));
|
| 60 |
$result['isSubscribed'] = (bool)$subscriber->getId();
|
| 61 |
-
|
| 62 |
$points = Mage::getModel('enterprise_reward/reward');
|
| 63 |
if ($points) {
|
| 64 |
$points = $points->setCustomer($customer)
|
|
@@ -67,24 +71,22 @@ class TmobLabs_Tappz_Model_Customer_Api extends Mage_Customer_Model_Api_Resource
|
|
| 67 |
->getPointsBalance();
|
| 68 |
}
|
| 69 |
$result['points'] = $points;
|
| 70 |
-
|
| 71 |
$result['addresses'] = Mage::getSingleton('tappz/customer_address_api')->getList($customer->getId()); /// ??????
|
| 72 |
-
|
| 73 |
$result['giftCheques'] = array();
|
| 74 |
-
|
| 75 |
return $result;
|
| 76 |
}
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
public function login($userName, $password)
|
| 79 |
{
|
| 80 |
$storeId = Mage::getStoreConfig('tappz/general/store');
|
| 81 |
-
/** @var Mage_Core_Model_Store $store */
|
| 82 |
$store = Mage::getModel('core/store')->load($storeId);
|
| 83 |
-
|
| 84 |
$customer = Mage::getModel('customer/customer')
|
| 85 |
->setStore($store);
|
| 86 |
-
/* @var $customer Mage_Customer_Model_Customer */
|
| 87 |
-
|
| 88 |
try {
|
| 89 |
$customer->authenticate($userName, $password);
|
| 90 |
} catch (Exception $e) {
|
|
@@ -100,25 +102,64 @@ class TmobLabs_Tappz_Model_Customer_Api extends Mage_Customer_Model_Api_Resource
|
|
| 100 |
break;
|
| 101 |
}
|
| 102 |
}
|
| 103 |
-
|
| 104 |
$customer = $customer->loadByEmail($userName);
|
| 105 |
return $this->info($customer->getId());
|
| 106 |
}
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
| 108 |
public function facebookLogin($facebookAccessToken, $facebookUserId)
|
| 109 |
{
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
}
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
public function register($tCustomerData)
|
| 114 |
{
|
| 115 |
$storeId = Mage::getStoreConfig('tappz/general/store');
|
| 116 |
-
/** @var Mage_Core_Model_Store $store */
|
| 117 |
$store = Mage::getModel('core/store')->load($storeId);
|
| 118 |
-
|
| 119 |
$customerData = $this->_prepareCustomerData($tCustomerData);
|
| 120 |
try {
|
| 121 |
-
/* @var $customer Mage_Customer_Model_Customer */
|
| 122 |
$customer = Mage::getModel('customer/customer');
|
| 123 |
$customer->setData($customerData)
|
| 124 |
->setPassword($customerData['password'])
|
|
@@ -127,25 +168,23 @@ class TmobLabs_Tappz_Model_Customer_Api extends Mage_Customer_Model_Api_Resource
|
|
| 127 |
} catch (Mage_Core_Exception $e) {
|
| 128 |
$this->_fault('invalid_data', $e->getMessage());
|
| 129 |
}
|
| 130 |
-
|
| 131 |
return $this->info($customer->getId());
|
| 132 |
}
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
| 134 |
public function update($tCustomerData)
|
| 135 |
{
|
| 136 |
$genderAttributeCode = Mage::getStoreConfig('tappz/customer/gender');
|
| 137 |
$emailAttributeCode = Mage::getStoreConfig('tappz/customer/email');
|
| 138 |
$phoneAttributeCode = Mage::getStoreConfig('tappz/customer/phone');
|
| 139 |
$birthDateAttributeCode = Mage::getStoreConfig('tappz/customer/birthDate');
|
| 140 |
-
|
| 141 |
$customerData = $this->_prepareCustomerData($tCustomerData);
|
| 142 |
$customer = Mage::getModel('customer/customer')->load($customerData['entity_id']);
|
| 143 |
-
/* @var $customer Mage_Customer_Model_Customer */
|
| 144 |
-
|
| 145 |
if (!$customer->getId()) {
|
| 146 |
$this->_fault('not_exists');
|
| 147 |
}
|
| 148 |
-
|
| 149 |
try {
|
| 150 |
$customer->setData('firstname', $customerData['firstname']);
|
| 151 |
$customer->setData('lastname', $customerData['lastname']);
|
|
@@ -153,45 +192,41 @@ class TmobLabs_Tappz_Model_Customer_Api extends Mage_Customer_Model_Api_Resource
|
|
| 153 |
$customer->setData($emailAttributeCode, $customerData[$emailAttributeCode]);
|
| 154 |
$customer->setData($phoneAttributeCode, $customerData[$phoneAttributeCode]);
|
| 155 |
$customer->setData($birthDateAttributeCode, $customerData[$birthDateAttributeCode]);
|
| 156 |
-
|
| 157 |
if (isset($customerData['isSubscribed']))
|
| 158 |
$customer->setIsSubscribed($customerData['isSubscribed'] === 'true' ? true : false);
|
| 159 |
-
|
| 160 |
$customer->save();
|
| 161 |
} catch (Mage_Core_Exception $e) {
|
| 162 |
$this->_fault('invalid_data', $e->getMessage());
|
| 163 |
}
|
| 164 |
-
|
| 165 |
return $this->info($customer->getId());
|
| 166 |
}
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
| 168 |
public function lostPassword($email)
|
| 169 |
{
|
| 170 |
if (!isset($email) || trim($email) === '') {
|
| 171 |
$this->_fault("invalid_data", "Please enter a valid email address.");
|
| 172 |
}
|
| 173 |
-
|
| 174 |
$storeId = Mage::getStoreConfig('tappz/general/store');
|
| 175 |
-
/** @var Mage_Core_Model_Store $store */
|
| 176 |
$store = Mage::getModel('core/store')->load($storeId);
|
| 177 |
-
|
| 178 |
$customer = $customer = Mage::getModel('customer/customer')
|
| 179 |
->setStoreId($storeId)
|
| 180 |
->setWebsiteId($store->getWebsiteId())
|
| 181 |
->loadByEmail($email);
|
| 182 |
-
|
| 183 |
if (!$customer) {
|
| 184 |
$this->_fault("invalid_data", "Customer is not found");
|
| 185 |
}
|
| 186 |
$customer = $customer->sendPasswordReminderEmail();
|
| 187 |
-
|
| 188 |
if (!$customer) {
|
| 189 |
$this->_fault("invalid_data", "Error occured while sending email");
|
| 190 |
}
|
| 191 |
-
|
| 192 |
return "Your password reminder email has been sent.";
|
| 193 |
}
|
| 194 |
-
|
|
|
|
|
|
|
| 195 |
public function getUserAgreement()
|
| 196 |
{
|
| 197 |
$agreement = Mage::getStoreConfig('tappz/customer/agreement');
|
| 1 |
<?php
|
|
|
|
| 2 |
class TmobLabs_Tappz_Model_Customer_Api extends Mage_Customer_Model_Api_Resource
|
| 3 |
{
|
| 4 |
+
/**
|
| 5 |
+
* @param $data
|
| 6 |
+
* @return array
|
| 7 |
+
*/
|
| 8 |
protected function _prepareCustomerData($data)
|
| 9 |
{
|
| 10 |
$genderAttributeCode = Mage::getStoreConfig('tappz/customer/gender');
|
| 23 |
$result[$birthDateAttributeCode] = $data->birthDate;
|
| 24 |
return $result;
|
| 25 |
}
|
| 26 |
+
/**
|
| 27 |
+
* @param $customerId
|
| 28 |
+
* @return array
|
| 29 |
+
*/
|
| 30 |
public function info($customerId)
|
| 31 |
{
|
| 32 |
$genderAttributeCode = Mage::getStoreConfig('tappz/customer/gender');
|
| 61 |
$result['email'] = $customer->getData($emailAttributeCode);
|
| 62 |
$result['phone'] = $customer->getData($phoneAttributeCode);
|
| 63 |
$result['birthDate'] = $customer->getData($birthDateAttributeCode);
|
|
|
|
| 64 |
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customer->getData($emailAttributeCode));
|
| 65 |
$result['isSubscribed'] = (bool)$subscriber->getId();
|
|
|
|
| 66 |
$points = Mage::getModel('enterprise_reward/reward');
|
| 67 |
if ($points) {
|
| 68 |
$points = $points->setCustomer($customer)
|
| 71 |
->getPointsBalance();
|
| 72 |
}
|
| 73 |
$result['points'] = $points;
|
|
|
|
| 74 |
$result['addresses'] = Mage::getSingleton('tappz/customer_address_api')->getList($customer->getId()); /// ??????
|
|
|
|
| 75 |
$result['giftCheques'] = array();
|
| 76 |
+
|
| 77 |
return $result;
|
| 78 |
}
|
| 79 |
+
/**
|
| 80 |
+
* @param $userName
|
| 81 |
+
* @param $password
|
| 82 |
+
* @return array
|
| 83 |
+
*/
|
| 84 |
public function login($userName, $password)
|
| 85 |
{
|
| 86 |
$storeId = Mage::getStoreConfig('tappz/general/store');
|
|
|
|
| 87 |
$store = Mage::getModel('core/store')->load($storeId);
|
|
|
|
| 88 |
$customer = Mage::getModel('customer/customer')
|
| 89 |
->setStore($store);
|
|
|
|
|
|
|
| 90 |
try {
|
| 91 |
$customer->authenticate($userName, $password);
|
| 92 |
} catch (Exception $e) {
|
| 102 |
break;
|
| 103 |
}
|
| 104 |
}
|
|
|
|
| 105 |
$customer = $customer->loadByEmail($userName);
|
| 106 |
return $this->info($customer->getId());
|
| 107 |
}
|
| 108 |
+
/**
|
| 109 |
+
* @param $facebookAccessToken
|
| 110 |
+
* @param $facebookUserId
|
| 111 |
+
*/
|
| 112 |
public function facebookLogin($facebookAccessToken, $facebookUserId)
|
| 113 |
{
|
| 114 |
+
$storeId = Mage::getStoreConfig('tappz/general/store');
|
| 115 |
+
$store = Mage::getModel('core/store')->load($storeId);
|
| 116 |
+
$curl = curl_init();
|
| 117 |
+
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
|
| 118 |
+
curl_setopt($curl, CURLOPT_URL, "https://graph.facebook.com/$facebookUserId?fields=id,name,email,first_name,last_name,gender,verified,birthday&access_token=$facebookAccessToken");
|
| 119 |
+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
| 120 |
+
$result = curl_exec($curl);
|
| 121 |
+
$userInfo = json_decode($result);
|
| 122 |
+
curl_close($curl);
|
| 123 |
+
$email = $userInfo->email;
|
| 124 |
+
$customerExist = Mage::getModel('customer/customer')
|
| 125 |
+
->getCollection()
|
| 126 |
+
->addAttributeToSelect('*')
|
| 127 |
+
->addAttributeToFilter('email', "$email" )
|
| 128 |
+
->getFirstItem();
|
| 129 |
+
if(($customerExist['entity_id']) > 0){
|
| 130 |
+
$customer = Mage::getModel('customer/customer')->setStore($store);
|
| 131 |
+
$customer->loadByEmail($email);
|
| 132 |
+
return $this->info($customer->getId());
|
| 133 |
+
}else{
|
| 134 |
+
$password = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10);
|
| 135 |
+
$registerCustomer["fullName"] = $userInfo->name;
|
| 136 |
+
$registerCustomer["firstName"] = $userInfo->first_name;
|
| 137 |
+
$registerCustomer["lastName"] = $userInfo->last_name;
|
| 138 |
+
$registerCustomer["customerId"] = "";
|
| 139 |
+
$registerCustomer["isSubscribed"] = 1;
|
| 140 |
+
$registerCustomer["gender"] = $userInfo->gender ;
|
| 141 |
+
$registerCustomer["isAccepted"]=$userInfo->verified;
|
| 142 |
+
$registerCustomer[ "email"] = $email;
|
| 143 |
+
$registerCustomer[ "password"] = $password;
|
| 144 |
+
$registerCustomer["phone"] = "";
|
| 145 |
+
$registerCustomer["birthDate"] = $userInfo->birthday ;
|
| 146 |
+
$registerCustomer["points"] = "";
|
| 147 |
+
$registerCustomer[ "addresses"] = array();
|
| 148 |
+
$registerCustomer["giftCheques"] = array();
|
| 149 |
+
return$this->register((object)$registerCustomer);
|
| 150 |
+
}
|
| 151 |
}
|
| 152 |
+
/**
|
| 153 |
+
*
|
| 154 |
+
* @param type $tCustomerData
|
| 155 |
+
* @return type
|
| 156 |
+
*/
|
| 157 |
public function register($tCustomerData)
|
| 158 |
{
|
| 159 |
$storeId = Mage::getStoreConfig('tappz/general/store');
|
|
|
|
| 160 |
$store = Mage::getModel('core/store')->load($storeId);
|
|
|
|
| 161 |
$customerData = $this->_prepareCustomerData($tCustomerData);
|
| 162 |
try {
|
|
|
|
| 163 |
$customer = Mage::getModel('customer/customer');
|
| 164 |
$customer->setData($customerData)
|
| 165 |
->setPassword($customerData['password'])
|
| 168 |
} catch (Mage_Core_Exception $e) {
|
| 169 |
$this->_fault('invalid_data', $e->getMessage());
|
| 170 |
}
|
|
|
|
| 171 |
return $this->info($customer->getId());
|
| 172 |
}
|
| 173 |
+
/**
|
| 174 |
+
* @param $tCustomerData
|
| 175 |
+
* @return array
|
| 176 |
+
*/
|
| 177 |
public function update($tCustomerData)
|
| 178 |
{
|
| 179 |
$genderAttributeCode = Mage::getStoreConfig('tappz/customer/gender');
|
| 180 |
$emailAttributeCode = Mage::getStoreConfig('tappz/customer/email');
|
| 181 |
$phoneAttributeCode = Mage::getStoreConfig('tappz/customer/phone');
|
| 182 |
$birthDateAttributeCode = Mage::getStoreConfig('tappz/customer/birthDate');
|
|
|
|
| 183 |
$customerData = $this->_prepareCustomerData($tCustomerData);
|
| 184 |
$customer = Mage::getModel('customer/customer')->load($customerData['entity_id']);
|
|
|
|
|
|
|
| 185 |
if (!$customer->getId()) {
|
| 186 |
$this->_fault('not_exists');
|
| 187 |
}
|
|
|
|
| 188 |
try {
|
| 189 |
$customer->setData('firstname', $customerData['firstname']);
|
| 190 |
$customer->setData('lastname', $customerData['lastname']);
|
| 192 |
$customer->setData($emailAttributeCode, $customerData[$emailAttributeCode]);
|
| 193 |
$customer->setData($phoneAttributeCode, $customerData[$phoneAttributeCode]);
|
| 194 |
$customer->setData($birthDateAttributeCode, $customerData[$birthDateAttributeCode]);
|
|
|
|
| 195 |
if (isset($customerData['isSubscribed']))
|
| 196 |
$customer->setIsSubscribed($customerData['isSubscribed'] === 'true' ? true : false);
|
|
|
|
| 197 |
$customer->save();
|
| 198 |
} catch (Mage_Core_Exception $e) {
|
| 199 |
$this->_fault('invalid_data', $e->getMessage());
|
| 200 |
}
|
|
|
|
| 201 |
return $this->info($customer->getId());
|
| 202 |
}
|
| 203 |
+
/**
|
| 204 |
+
* @param $email
|
| 205 |
+
* @return string
|
| 206 |
+
*/
|
| 207 |
public function lostPassword($email)
|
| 208 |
{
|
| 209 |
if (!isset($email) || trim($email) === '') {
|
| 210 |
$this->_fault("invalid_data", "Please enter a valid email address.");
|
| 211 |
}
|
|
|
|
| 212 |
$storeId = Mage::getStoreConfig('tappz/general/store');
|
|
|
|
| 213 |
$store = Mage::getModel('core/store')->load($storeId);
|
|
|
|
| 214 |
$customer = $customer = Mage::getModel('customer/customer')
|
| 215 |
->setStoreId($storeId)
|
| 216 |
->setWebsiteId($store->getWebsiteId())
|
| 217 |
->loadByEmail($email);
|
|
|
|
| 218 |
if (!$customer) {
|
| 219 |
$this->_fault("invalid_data", "Customer is not found");
|
| 220 |
}
|
| 221 |
$customer = $customer->sendPasswordReminderEmail();
|
|
|
|
| 222 |
if (!$customer) {
|
| 223 |
$this->_fault("invalid_data", "Error occured while sending email");
|
| 224 |
}
|
|
|
|
| 225 |
return "Your password reminder email has been sent.";
|
| 226 |
}
|
| 227 |
+
/**
|
| 228 |
+
* @return mixed
|
| 229 |
+
*/
|
| 230 |
public function getUserAgreement()
|
| 231 |
{
|
| 232 |
$agreement = Mage::getStoreConfig('tappz/customer/agreement');
|
app/code/community/TmobLabs/Tappz/etc/wsdl.xml
CHANGED
|
@@ -890,6 +890,7 @@
|
|
| 890 |
<message name="tappzBasketPurchaseCreditCardRequest">
|
| 891 |
<part name="sessionId" type="xsd:string"/>
|
| 892 |
<part name="quoteId" type="xsd:string"/>
|
|
|
|
| 893 |
</message>
|
| 894 |
<message name="tappzBasketPurchaseCreditCardResponse">
|
| 895 |
<part name="order" type="typens:order"/>
|
| 890 |
<message name="tappzBasketPurchaseCreditCardRequest">
|
| 891 |
<part name="sessionId" type="xsd:string"/>
|
| 892 |
<part name="quoteId" type="xsd:string"/>
|
| 893 |
+
<part name="payment" type="typens:payment"/>
|
| 894 |
</message>
|
| 895 |
<message name="tappzBasketPurchaseCreditCardResponse">
|
| 896 |
<part name="order" type="typens:order"/>
|
package.xml
CHANGED
|
@@ -1,18 +1,18 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>Tmob_Tappz</name>
|
| 4 |
-
<version>1.0.
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>t-appz Adapter for Magento</summary>
|
| 10 |
<description>t-appz Adapter for Magento</description>
|
| 11 |
-
<notes>
|
| 12 |
-
<authors><author><name>tmobtech
|
| 13 |
-
<date>2016-
|
| 14 |
-
<time>
|
| 15 |
-
<contents><target name="magecommunity"><dir name="TmobLabs"><dir name="Tappz"><dir name="Block"><file name="Info.php" hash="f656ba90ea77040abb27cf8858a5e8bb"/></dir><dir name="Helper"><file name="Data.php" hash="8587ca8f702e61ae1b57dd7739a674e6"/></dir><dir name="Model"><dir name="Basket"><dir name="Api"><file name="V2.php" hash="e5860165902a6e3f0e29e238397d40f3"/></dir><file name="Api.php" hash="
|
| 16 |
<compatible/>
|
| 17 |
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
| 18 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>Tmob_Tappz</name>
|
| 4 |
+
<version>1.0.13</version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>t-appz Adapter for Magento</summary>
|
| 10 |
<description>t-appz Adapter for Magento</description>
|
| 11 |
+
<notes>Facebook login added</notes>
|
| 12 |
+
<authors><author><name>tmobtech</name><user>tmobLabs</user><email>info@tmobtech.com</email></author></authors>
|
| 13 |
+
<date>2016-03-31</date>
|
| 14 |
+
<time>16:27:00</time>
|
| 15 |
+
<contents><target name="magecommunity"><dir name="TmobLabs"><dir name="Tappz"><dir name="Block"><file name="Info.php" hash="f656ba90ea77040abb27cf8858a5e8bb"/></dir><dir name="Helper"><file name="Data.php" hash="8587ca8f702e61ae1b57dd7739a674e6"/></dir><dir name="Model"><dir name="Basket"><dir name="Api"><file name="V2.php" hash="e5860165902a6e3f0e29e238397d40f3"/></dir><file name="Api.php" hash="719f9f49c7c5df382192d8b87c719b9d"/></dir><dir name="Catalog"><dir name="Api"><file name="V2.php" hash="d28a03e359966fa0a0a9c48940ff4b2b"/></dir><file name="Api.php" hash="545d124c4c4d8e6c50dac59d029d534c"/></dir><dir name="Customer"><dir name="Address"><dir name="Api"><file name="V2.php" hash="9a3ca989261966e5d9195274311db0e6"/></dir><file name="Api.php" hash="88e9a010b0bf3a348d37bf45dbfbaf19"/></dir><dir name="Api"><file name="V2.php" hash="5089c4a89f24f09ff6ed41903d04d210"/></dir><file name="Api.php" hash="481cb0d07c1425474891ff0fab97062c"/><dir name="Order"><dir name="Api"><file name="V2.php" hash="9a4d34b33c98d7931c86a3af64718a88"/></dir><file name="Api.php" hash="8ef5f19e3941d12bfc4687c2d4ea1bae"/></dir></dir><dir name="System"><dir name="Config"><file name="Action.php" hash="696379a81774cc7022565d3d22c263e6"/><file name="Address.php" hash="d7aed1d204c8fa4bbf833c22ee643bc4"/><file name="Category.php" hash="eb4af019ee4494bd305195442378957e"/><file name="Customer.php" hash="14e8962dc72e73319e632e751c009193"/><file name="Divider.php" hash="3a3b599ba29e053ec9b804975cab5b21"/><file name="Enabled.php" hash="8db7b92b36d79a153fab01ceee8c53bd"/><file name="Payment.php" hash="0216068de66b431fba037923ee30a81a"/><dir name="Product"><file name="Attribute.php" hash="62800e9eed8a06444560c351a25de6e3"/></dir><file name="Store.php" hash="ac29ff3d2a9b915ed3e78e8ac4eca999"/></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="35aaf132195e63f958f33b59bd981b3e"/><file name="api.xml" hash="f2812af730d2d3f4ce92ef164f3b693c"/><file name="config.xml" hash="93b957b86d745252c3e9746c0df9c3c6"/><file name="system.xml" hash="9b122651372fa386e8beafd39e426696"/><file name="wsdl.xml" hash="bc931a16e6407f7154bcb4cb9da3e659"/></dir></dir></dir></target><target name="mage"><dir name="app"><dir name="etc"><dir name="modules"><file name="TmobLabs_Tappz.xml" hash="88f02743bbc8116ca67c615803436b74"/></dir></dir></dir></target></contents>
|
| 16 |
<compatible/>
|
| 17 |
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
| 18 |
</package>
|
