Version Notes
Order callback improvements and bugfixes.
Download this release
Release Info
| Developer | PriceWaiter |
| Extension | nypwidget |
| Version | 2.5.0 |
| Comparing to | |
| See all releases | |
Code changes from version 2.2.2 to 2.5.0
- app/code/community/PriceWaiter/NYPWidget/Block/Adminhtml/Link.php +0 -17
- app/code/community/PriceWaiter/NYPWidget/Block/Adminhtml/Signup.php +0 -17
- app/code/community/PriceWaiter/NYPWidget/Block/Adminhtml/Widget.php +0 -17
- app/code/community/PriceWaiter/NYPWidget/Block/Category.php +0 -17
- app/code/community/PriceWaiter/NYPWidget/Block/Payment/Info/Pricewaiter.php +101 -0
- app/code/community/PriceWaiter/NYPWidget/Block/Widget.php +0 -17
- app/code/community/PriceWaiter/NYPWidget/Exception/Abstract.php +36 -0
- app/code/community/PriceWaiter/NYPWidget/Exception/ApiKey.php +16 -0
- app/code/community/PriceWaiter/NYPWidget/Exception/DuplicateOrder.php +25 -0
- app/code/community/PriceWaiter/NYPWidget/Exception/InvalidOrderData.php +17 -0
- app/code/community/PriceWaiter/NYPWidget/Exception/InvalidRegion.php +30 -0
- app/code/community/PriceWaiter/NYPWidget/Exception/OutOfStock.php +10 -0
- app/code/community/PriceWaiter/NYPWidget/Exception/Product/Abstract.php +9 -0
- app/code/community/PriceWaiter/NYPWidget/Exception/Product/NotFound.php +10 -0
- app/code/community/PriceWaiter/NYPWidget/Exception/Signature.php +11 -0
- app/code/community/PriceWaiter/NYPWidget/Helper/Data.php +89 -41
- app/code/community/PriceWaiter/NYPWidget/Model/Callback.php +782 -284
- app/code/community/PriceWaiter/NYPWidget/Model/Callback/Inventory.php +74 -0
- app/code/community/PriceWaiter/NYPWidget/Model/Carrier/ShippingMethod.php +0 -17
- app/code/community/PriceWaiter/NYPWidget/Model/Category.php +0 -17
- app/code/community/PriceWaiter/NYPWidget/Model/Display/Phrase.php +0 -17
- app/code/community/PriceWaiter/NYPWidget/Model/Display/Size.php +0 -17
- app/code/community/PriceWaiter/NYPWidget/Model/Mysql4/Category.php +0 -17
- app/code/community/PriceWaiter/NYPWidget/Model/Mysql4/Category/Collection.php +0 -17
- app/code/community/PriceWaiter/NYPWidget/Model/Mysql4/Order.php +0 -17
- app/code/community/PriceWaiter/NYPWidget/Model/Mysql4/Order/Collection.php +0 -17
- app/code/community/PriceWaiter/NYPWidget/Model/Observer.php +0 -17
- app/code/community/PriceWaiter/NYPWidget/Model/Order.php +21 -18
- app/code/community/PriceWaiter/NYPWidget/Model/PaymentMethod.php +91 -18
- app/code/community/PriceWaiter/NYPWidget/Model/Resource/Eav/Mysql4/Setup.php +0 -17
- app/code/community/PriceWaiter/NYPWidget/controllers/Adminhtml/PricewaiterController.php +0 -17
- app/code/community/PriceWaiter/NYPWidget/controllers/CallbackController.php +53 -39
- app/code/community/PriceWaiter/NYPWidget/controllers/ProductinfoController.php +6 -17
- app/code/community/PriceWaiter/NYPWidget/etc/adminhtml.xml +0 -15
- app/code/community/PriceWaiter/NYPWidget/etc/config.xml +5 -18
- app/code/community/PriceWaiter/NYPWidget/etc/system.xml +25 -17
- app/code/community/PriceWaiter/NYPWidget/sql/nypwidget_setup/mysql4-install-1.0.0.php +0 -16
- app/code/community/PriceWaiter/NYPWidget/sql/nypwidget_setup/mysql4-upgrade-1.1.2-1.1.3.php +0 -16
- app/code/community/PriceWaiter/NYPWidget/sql/nypwidget_setup/mysql4-upgrade-1.1.7-1.1.8.php +0 -16
- app/code/community/PriceWaiter/NYPWidget/sql/nypwidget_setup/mysql4-upgrade-1.2.4-1.2.5.php +0 -16
- app/code/community/PriceWaiter/NYPWidget/sql/nypwidget_setup/mysql4-upgrade-1.3.0-1.3.1.php +0 -16
- app/code/community/PriceWaiter/NYPWidget/sql/nypwidget_setup/mysql4-upgrade-2.1.5-2.2.0.php +0 -16
- app/code/community/PriceWaiter/NYPWidget/sql/nypwidget_setup/mysql4-upgrade-2.2.0-2.5.0.php +42 -0
- app/design/adminhtml/default/default/layout/pricewaiter.xml +0 -15
- app/design/adminhtml/default/default/template/pricewaiter/categorytab.phtml +0 -18
- app/design/frontend/base/default/layout/pricewaiter.xml +0 -15
- app/design/frontend/base/default/template/pricewaiter/widget.phtml +0 -18
- app/etc/modules/PriceWaiter_NYPWidget.xml +0 -15
- js/pricewaiter/product-pages.js +1 -22
- js/pricewaiter/token.js +0 -18
- package.xml +7 -7
- skin/adminhtml/default/default/pricewaiter.css +0 -16
app/code/community/PriceWaiter/NYPWidget/Block/Adminhtml/Link.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Block_Adminhtml_Link extends Varien_Data_Form_Element_Link implements Varien_Data_Form_Element_Renderer_Interface
|
| 21 |
{
|
| 22 |
public function render(Varien_Data_Form_Element_Abstract $element)
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Block_Adminhtml_Link extends Varien_Data_Form_Element_Link implements Varien_Data_Form_Element_Renderer_Interface
|
| 4 |
{
|
| 5 |
public function render(Varien_Data_Form_Element_Abstract $element)
|
app/code/community/PriceWaiter/NYPWidget/Block/Adminhtml/Signup.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Block_Adminhtml_Signup extends Mage_Adminhtml_Block_System_Config_Form_Field
|
| 21 |
{
|
| 22 |
protected function _construct()
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Block_Adminhtml_Signup extends Mage_Adminhtml_Block_System_Config_Form_Field
|
| 4 |
{
|
| 5 |
protected function _construct()
|
app/code/community/PriceWaiter/NYPWidget/Block/Adminhtml/Widget.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Block_Adminhtml_Widget extends Mage_Adminhtml_Block_Abstract
|
| 21 |
{
|
| 22 |
public function _getHelper()
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Block_Adminhtml_Widget extends Mage_Adminhtml_Block_Abstract
|
| 4 |
{
|
| 5 |
public function _getHelper()
|
app/code/community/PriceWaiter/NYPWidget/Block/Category.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Block_Category extends Mage_Adminhtml_Block_Template
|
| 21 |
implements Mage_Adminhtml_Block_Widget_Tab_Interface
|
| 22 |
{
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Block_Category extends Mage_Adminhtml_Block_Template
|
| 4 |
implements Mage_Adminhtml_Block_Widget_Tab_Interface
|
| 5 |
{
|
app/code/community/PriceWaiter/NYPWidget/Block/Payment/Info/Pricewaiter.php
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Block used to display PriceWaiter payment details.
|
| 5 |
+
*/
|
| 6 |
+
class PriceWaiter_NYPWidget_Block_Payment_Info_Pricewaiter extends Mage_Payment_Block_Info
|
| 7 |
+
{
|
| 8 |
+
/**
|
| 9 |
+
* @return String
|
| 10 |
+
*/
|
| 11 |
+
public function getCcLast4()
|
| 12 |
+
{
|
| 13 |
+
$info = $this->getInfo();
|
| 14 |
+
return $info ? $info->getCcLast4() : '';
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* @return String
|
| 19 |
+
*/
|
| 20 |
+
public function getCcTypeName()
|
| 21 |
+
{
|
| 22 |
+
$types = Mage::getSingleton('payment/config')->getCcTypes();
|
| 23 |
+
$ccType = $this->getInfo()->getCcType();
|
| 24 |
+
|
| 25 |
+
if (!$ccType) {
|
| 26 |
+
return '';
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
if (isset($types[$ccType])) {
|
| 30 |
+
return $types[$ccType];
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
return (empty($ccType)) ? Mage::helper('payment')->__('N/A') : $ccType;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* @return String|false The full name of the payment method used on PriceWaiter.
|
| 38 |
+
*/
|
| 39 |
+
public function getPriceWaiterPaymentMethodName()
|
| 40 |
+
{
|
| 41 |
+
$payment = $this->getInfo();
|
| 42 |
+
|
| 43 |
+
// HACK: We stash PW payment method information (serialized) in the
|
| 44 |
+
// "additional data" field on payment.
|
| 45 |
+
|
| 46 |
+
$data = $payment->getAdditionalData();
|
| 47 |
+
$data = $data ? @unserialize($data) : $data;
|
| 48 |
+
$data = is_array($data) ? $data : array();
|
| 49 |
+
|
| 50 |
+
if (isset($data['pricewaiter_payment_method_nice'])) {
|
| 51 |
+
return $data['pricewaiter_payment_method_nice'];
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
if (isset($data['pricewaiter_payment_method'])) {
|
| 55 |
+
return ucfirst($data['pricewaiter_payment_method']);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
return false;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
* Prepare credit card related payment info
|
| 63 |
+
*
|
| 64 |
+
* @param Varien_Object|array $transport
|
| 65 |
+
* @return Varien_Object
|
| 66 |
+
*/
|
| 67 |
+
protected function _prepareSpecificInformation($transport = null)
|
| 68 |
+
{
|
| 69 |
+
// This is adapted from Mage_Payment_Block_Info_Cc
|
| 70 |
+
|
| 71 |
+
if ($this->_paymentSpecificInformation !== null) {
|
| 72 |
+
return $this->_paymentSpecificInformation;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
/**
|
| 76 |
+
* @var Mage_Payment_Helper_Data
|
| 77 |
+
*/
|
| 78 |
+
$p = Mage::helper('payment');
|
| 79 |
+
|
| 80 |
+
$transport = parent::_prepareSpecificInformation($transport);
|
| 81 |
+
$data = array();
|
| 82 |
+
|
| 83 |
+
$method = $this->getPriceWaiterPaymentMethodName();
|
| 84 |
+
if ($method) {
|
| 85 |
+
$data[$p->__('Paid via')] = $method;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
$ccType = $this->getCcTypeName();
|
| 89 |
+
if ($ccType) {
|
| 90 |
+
$data[$p->__('Credit Card Type')] = $ccType;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
$ccLast4 = $this->getCcLast4();
|
| 94 |
+
|
| 95 |
+
if ($ccLast4) {
|
| 96 |
+
$data[$p->__('Credit Card Number')] = sprintf('xxxx-%s', $ccLast4);
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
return $transport->setData(array_merge($data, $transport->getData()));
|
| 100 |
+
}
|
| 101 |
+
}
|
app/code/community/PriceWaiter/NYPWidget/Block/Widget.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Block_Widget extends Mage_Core_Block_Template
|
| 21 |
{
|
| 22 |
public function _getHelper()
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Block_Widget extends Mage_Core_Block_Template
|
| 4 |
{
|
| 5 |
public function _getHelper()
|
app/code/community/PriceWaiter/NYPWidget/Exception/Abstract.php
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Base for implementing exceptions to be thrown by the PriceWaiter extension.
|
| 5 |
+
*/
|
| 6 |
+
abstract class PriceWaiter_NYPWidget_Exception_Abstract extends RuntimeException
|
| 7 |
+
{
|
| 8 |
+
/**
|
| 9 |
+
* Unchanging error code to be reported back to clients.
|
| 10 |
+
* This is a string, favored over PHP's built-in int `code` property.
|
| 11 |
+
* @var String
|
| 12 |
+
*/
|
| 13 |
+
public $errorCode;
|
| 14 |
+
|
| 15 |
+
/**
|
| 16 |
+
* HTTP status code to be used when reporting this error back to the client.
|
| 17 |
+
* @var integer
|
| 18 |
+
*/
|
| 19 |
+
public $httpStatusCode = 400;
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* @return Array Representation of this error, ready to be passed to json_encode.
|
| 23 |
+
*/
|
| 24 |
+
public function jsonSerialize()
|
| 25 |
+
{
|
| 26 |
+
$json = array(
|
| 27 |
+
'message' => $this->getMessage(),
|
| 28 |
+
);
|
| 29 |
+
|
| 30 |
+
if ($this->errorCode) {
|
| 31 |
+
$json['code'] = $this->errorCode;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
return $json;
|
| 35 |
+
}
|
| 36 |
+
}
|
app/code/community/PriceWaiter/NYPWidget/Exception/ApiKey.php
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Exception thrown when an incoming PriceWaiter API key does not match any
|
| 5 |
+
* store in the system.
|
| 6 |
+
*/
|
| 7 |
+
class PriceWaiter_NYPWidget_Exception_ApiKey
|
| 8 |
+
extends PriceWaiter_NYPWidget_Exception_Abstract
|
| 9 |
+
{
|
| 10 |
+
public $errorCode = 'invalid_api_key';
|
| 11 |
+
|
| 12 |
+
public function __construct()
|
| 13 |
+
{
|
| 14 |
+
parent::__construct('An invalid PriceWaiter API key was detected.');
|
| 15 |
+
}
|
| 16 |
+
}
|
app/code/community/PriceWaiter/NYPWidget/Exception/DuplicateOrder.php
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Exception thrown when an order already exists for an incoming order callback request.
|
| 5 |
+
*/
|
| 6 |
+
class PriceWaiter_NYPWidget_Exception_DuplicateOrder
|
| 7 |
+
extends PriceWaiter_NYPWidget_Exception_Abstract
|
| 8 |
+
{
|
| 9 |
+
public $errorCode = 'duplicate_order';
|
| 10 |
+
|
| 11 |
+
public function __construct(PriceWaiter_NYPWidget_Model_Order $existingOrder)
|
| 12 |
+
{
|
| 13 |
+
$id = $this->data['existing_order_id'] = $existingOrder->getId();
|
| 14 |
+
|
| 15 |
+
parent::__construct(sprintf(
|
| 16 |
+
'Duplicate order callback detected: Order %s already exists.',
|
| 17 |
+
$id
|
| 18 |
+
));
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
public function getExistingOrderId()
|
| 22 |
+
{
|
| 23 |
+
return $this->data['existing_order_id'];
|
| 24 |
+
}
|
| 25 |
+
}
|
app/code/community/PriceWaiter/NYPWidget/Exception/InvalidOrderData.php
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Exception thrown when an incoming order callback request cannot be validated.
|
| 5 |
+
*/
|
| 6 |
+
class PriceWaiter_NYPWidget_Exception_InvalidOrderData
|
| 7 |
+
extends PriceWaiter_NYPWidget_Exception_Abstract
|
| 8 |
+
{
|
| 9 |
+
public $errorCode = 'invalid_order_data';
|
| 10 |
+
|
| 11 |
+
public function __construct()
|
| 12 |
+
{
|
| 13 |
+
parent::__construct(
|
| 14 |
+
'An invalid PriceWaiter order notification has been received.'
|
| 15 |
+
);
|
| 16 |
+
}
|
| 17 |
+
}
|
app/code/community/PriceWaiter/NYPWidget/Exception/InvalidRegion.php
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Exception thrown when an order comes in for a geographic region we don't know about.
|
| 5 |
+
*/
|
| 6 |
+
class PriceWaiter_NYPWidget_Exception_InvalidRegion
|
| 7 |
+
extends PriceWaiter_NYPWidget_Exception_Abstract
|
| 8 |
+
{
|
| 9 |
+
public $errorCode = 'invalid_region';
|
| 10 |
+
|
| 11 |
+
/**
|
| 12 |
+
* @var String
|
| 13 |
+
*/
|
| 14 |
+
public $regionCode = null;
|
| 15 |
+
|
| 16 |
+
/**
|
| 17 |
+
* @var String
|
| 18 |
+
*/
|
| 19 |
+
public $countryCode = null;
|
| 20 |
+
|
| 21 |
+
public function __construct($regionCode, $countryCode)
|
| 22 |
+
{
|
| 23 |
+
$this->regionCode = $regionCode;
|
| 24 |
+
$this->countryCode = $countryCode;
|
| 25 |
+
|
| 26 |
+
parent::__construct(
|
| 27 |
+
"Invalid region: '$regionCode, $countryCode'"
|
| 28 |
+
);
|
| 29 |
+
}
|
| 30 |
+
}
|
app/code/community/PriceWaiter/NYPWidget/Exception/OutOfStock.php
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Exception thrown when there's not enough inventory of an item.
|
| 5 |
+
*/
|
| 6 |
+
class PriceWaiter_NYPWidget_Exception_OutOfStock
|
| 7 |
+
extends PriceWaiter_NYPWidget_Exception_Abstract
|
| 8 |
+
{
|
| 9 |
+
public $errorCode = 'out_of_stock';
|
| 10 |
+
}
|
app/code/community/PriceWaiter/NYPWidget/Exception/Product/Abstract.php
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Base for product data related exceptions.
|
| 5 |
+
*/
|
| 6 |
+
abstract class PriceWaiter_NYPWidget_Exception_Product_Abstract
|
| 7 |
+
extends PriceWaiter_NYPWidget_Exception_Abstract
|
| 8 |
+
{
|
| 9 |
+
}
|
app/code/community/PriceWaiter/NYPWidget/Exception/Product/NotFound.php
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Exception thrown when a product cannot be found.
|
| 5 |
+
*/
|
| 6 |
+
class PriceWaiter_NYPWidget_Exception_Product_NotFound
|
| 7 |
+
extends PriceWaiter_NYPWidget_Exception_Product_Abstract
|
| 8 |
+
{
|
| 9 |
+
public $errorCode = 'product_not_found';
|
| 10 |
+
}
|
app/code/community/PriceWaiter/NYPWidget/Exception/Signature.php
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Exception thrown when an incoming request's signature does not match what
|
| 5 |
+
* was expected.
|
| 6 |
+
*/
|
| 7 |
+
class PriceWaiter_NYPWidget_Exception_Signature
|
| 8 |
+
extends PriceWaiter_NYPWidget_Exception_Abstract
|
| 9 |
+
{
|
| 10 |
+
public $errorCode = 'signature';
|
| 11 |
+
}
|
app/code/community/PriceWaiter/NYPWidget/Helper/Data.php
CHANGED
|
@@ -1,51 +1,90 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Helper_Data extends Mage_Core_Helper_Abstract
|
| 21 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
private $_product = false;
|
| 23 |
-
private $_testing = false;
|
| 24 |
private $_buttonEnabled = null;
|
| 25 |
private $_conversionToolsEnabled = null;
|
| 26 |
|
| 27 |
-
private $_apiUrl = 'https://api.pricewaiter.com';
|
| 28 |
-
private $_retailerUrl = 'https://retailer.pricewaiter.com';
|
| 29 |
private $_widgetUrl = 'https://widget.pricewaiter.com';
|
| 30 |
|
| 31 |
public function __construct()
|
| 32 |
{
|
| 33 |
-
if (!!getenv('
|
| 34 |
-
$this->
|
| 35 |
}
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
}
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
| 47 |
{
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
}
|
| 50 |
|
| 51 |
public function isEnabledForStore()
|
|
@@ -161,9 +200,7 @@ class PriceWaiter_NYPWidget_Helper_Data extends Mage_Core_Helper_Abstract
|
|
| 161 |
|
| 162 |
public function getPriceWaiterSettingsUrl()
|
| 163 |
{
|
| 164 |
-
$
|
| 165 |
-
|
| 166 |
-
return sprintf("%s/", $this->_retailerUrl);
|
| 167 |
}
|
| 168 |
|
| 169 |
public function getWidgetUrl()
|
|
@@ -177,11 +214,6 @@ class PriceWaiter_NYPWidget_Helper_Data extends Mage_Core_Helper_Abstract
|
|
| 177 |
return $this->_widgetUrl . '/nyp/script/widget.js';
|
| 178 |
}
|
| 179 |
|
| 180 |
-
public function getApiUrl()
|
| 181 |
-
{
|
| 182 |
-
return $this->_apiUrl . '/1/order/verify?api_key='
|
| 183 |
-
. Mage::getStoreConfig('pricewaiter/configuration/api_key');
|
| 184 |
-
}
|
| 185 |
|
| 186 |
public function getProductPrice($product)
|
| 187 |
{
|
|
@@ -269,19 +301,29 @@ class PriceWaiter_NYPWidget_Helper_Data extends Mage_Core_Helper_Abstract
|
|
| 269 |
return $javascript;
|
| 270 |
}
|
| 271 |
|
| 272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
{
|
| 274 |
$stores = Mage::app()->getStores();
|
| 275 |
|
| 276 |
-
// Find the store with the matching API key by checking the key for each store
|
| 277 |
-
// in Magento
|
| 278 |
foreach ($stores as $store) {
|
| 279 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
return $store;
|
| 281 |
}
|
| 282 |
}
|
| 283 |
|
| 284 |
-
return
|
| 285 |
}
|
| 286 |
|
| 287 |
/**
|
|
@@ -341,6 +383,7 @@ class PriceWaiter_NYPWidget_Helper_Data extends Mage_Core_Helper_Abstract
|
|
| 341 |
* @param {String} $sku SKU of the product
|
| 342 |
* @param {Array} $productOptions An array of options for the product, name => value
|
| 343 |
* @return {Object} Returns Mage_Catalog_Model_Product of product that matches options.
|
|
|
|
| 344 |
*/
|
| 345 |
public function getProductWithOptions($sku, $productOptions)
|
| 346 |
{
|
|
@@ -375,6 +418,11 @@ class PriceWaiter_NYPWidget_Helper_Data extends Mage_Core_Helper_Abstract
|
|
| 375 |
|
| 376 |
$parentProduct = $product;
|
| 377 |
$product = $product->getTypeInstance()->getProductByAttributes($productOptions, $product);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
$product->load($product->getId());
|
| 379 |
}
|
| 380 |
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Helper_Data extends Mage_Core_Helper_Abstract
|
| 4 |
{
|
| 5 |
+
const PRICEWAITER_API_URL = 'https://api.pricewaiter.com';
|
| 6 |
+
const PRICEWAITER_RETAILER_URL = 'https://retailer.pricewaiter.com';
|
| 7 |
+
|
| 8 |
+
const XML_PATH_DEFAULT_ORDER_STATUS = 'pricewaiter/orders/default_status';
|
| 9 |
+
|
| 10 |
private $_product = false;
|
|
|
|
| 11 |
private $_buttonEnabled = null;
|
| 12 |
private $_conversionToolsEnabled = null;
|
| 13 |
|
|
|
|
|
|
|
| 14 |
private $_widgetUrl = 'https://widget.pricewaiter.com';
|
| 15 |
|
| 16 |
public function __construct()
|
| 17 |
{
|
| 18 |
+
if (!!getenv('PRICEWAITER_WIDGET_URL')) {
|
| 19 |
+
$this->_widgetUrl = getenv('PRICEWAITER_WIDGET_URL');
|
| 20 |
}
|
| 21 |
+
}
|
| 22 |
|
| 23 |
+
/**
|
| 24 |
+
* @return String URL of the PriceWaiter API.
|
| 25 |
+
*/
|
| 26 |
+
public function getApiUrl()
|
| 27 |
+
{
|
| 28 |
+
$url = getenv('PRICEWAITER_API_URL');
|
| 29 |
+
|
| 30 |
+
if ($url) {
|
| 31 |
+
return $url;
|
| 32 |
}
|
| 33 |
|
| 34 |
+
return self::PRICEWAITER_API_URL;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
/**
|
| 38 |
+
* @return String The status to assign to new PriceWaiter orders.
|
| 39 |
+
*/
|
| 40 |
+
public function getDefaultOrderStatus($store = null)
|
| 41 |
+
{
|
| 42 |
+
return Mage::getStoreConfig(self::XML_PATH_DEFAULT_ORDER_STATUS, $store);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
/**
|
| 46 |
+
* @param String $id
|
| 47 |
+
* @return String URL to view the given offer on PriceWaiter.
|
| 48 |
+
*/
|
| 49 |
+
public function getOfferUrl($id)
|
| 50 |
+
{
|
| 51 |
+
$url = $this->getRetailerUrl();
|
| 52 |
+
$url = rtrim($url, '/');
|
| 53 |
+
$url .= '/offers/' . rawurlencode($id);
|
| 54 |
+
|
| 55 |
+
return $url;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
/**
|
| 59 |
+
* @return String URL to which to POST order data for verification.
|
| 60 |
+
*/
|
| 61 |
+
public function getOrderVerificationUrl()
|
| 62 |
+
{
|
| 63 |
+
$url = getenv('PRICEWAITER_ORDER_VERIFICATION_URL');
|
| 64 |
+
if ($url) {
|
| 65 |
+
return $url;
|
| 66 |
}
|
| 67 |
+
|
| 68 |
+
// Build verification URL off base API url.
|
| 69 |
+
$url = $this->getApiUrl();
|
| 70 |
+
$url = rtrim($url, '/');
|
| 71 |
+
$url .= '/1/order/verify';
|
| 72 |
+
|
| 73 |
+
return $url;
|
| 74 |
}
|
| 75 |
|
| 76 |
+
/**
|
| 77 |
+
* @return String The URL of the PriceWaiter Retailer area.
|
| 78 |
+
*/
|
| 79 |
+
public function getRetailerUrl()
|
| 80 |
{
|
| 81 |
+
$url = getenv('PRICEWAITER_RETAILER_URL');
|
| 82 |
+
|
| 83 |
+
if ($url) {
|
| 84 |
+
return $url;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
return self::PRICEWAITER_RETAILER_URL;
|
| 88 |
}
|
| 89 |
|
| 90 |
public function isEnabledForStore()
|
| 200 |
|
| 201 |
public function getPriceWaiterSettingsUrl()
|
| 202 |
{
|
| 203 |
+
return $this->getRetailerUrl();
|
|
|
|
|
|
|
| 204 |
}
|
| 205 |
|
| 206 |
public function getWidgetUrl()
|
| 214 |
return $this->_widgetUrl . '/nyp/script/widget.js';
|
| 215 |
}
|
| 216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
public function getProductPrice($product)
|
| 219 |
{
|
| 301 |
return $javascript;
|
| 302 |
}
|
| 303 |
|
| 304 |
+
/**
|
| 305 |
+
* Returns the Magento store configured with the given PriceWaiter API key, or false if none is found.
|
| 306 |
+
* @param String $apiKey
|
| 307 |
+
* @return Mage_Core_Model_Store|false
|
| 308 |
+
* @throws PriceWaiter
|
| 309 |
+
*/
|
| 310 |
+
public function getStoreByPriceWaiterApiKey($apiKey)
|
| 311 |
{
|
| 312 |
$stores = Mage::app()->getStores();
|
| 313 |
|
|
|
|
|
|
|
| 314 |
foreach ($stores as $store) {
|
| 315 |
+
|
| 316 |
+
$storeApiKey = Mage::getStoreConfig(
|
| 317 |
+
'pricewaiter/configuration/api_key',
|
| 318 |
+
$store->getId()
|
| 319 |
+
);
|
| 320 |
+
|
| 321 |
+
if (strcasecmp($apiKey, $storeApiKey) === 0) {
|
| 322 |
return $store;
|
| 323 |
}
|
| 324 |
}
|
| 325 |
|
| 326 |
+
return false;
|
| 327 |
}
|
| 328 |
|
| 329 |
/**
|
| 383 |
* @param {String} $sku SKU of the product
|
| 384 |
* @param {Array} $productOptions An array of options for the product, name => value
|
| 385 |
* @return {Object} Returns Mage_Catalog_Model_Product of product that matches options.
|
| 386 |
+
* @throws PriceWaiter_NYPWidget_Exception_Product_NotFound If no product can be found.
|
| 387 |
*/
|
| 388 |
public function getProductWithOptions($sku, $productOptions)
|
| 389 |
{
|
| 418 |
|
| 419 |
$parentProduct = $product;
|
| 420 |
$product = $product->getTypeInstance()->getProductByAttributes($productOptions, $product);
|
| 421 |
+
|
| 422 |
+
if (!$product) {
|
| 423 |
+
throw new PriceWaiter_NYPWidget_Exception_Product_NotFound();
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
$product->load($product->getId());
|
| 427 |
}
|
| 428 |
|
app/code/community/PriceWaiter/NYPWidget/Model/Callback.php
CHANGED
|
@@ -1,322 +1,820 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Model_Callback
|
| 21 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
{
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
-
$pricewaiterOrder = Mage::getModel('nypwidget/order');
|
| 58 |
-
$pricewaiterOrder->loadByPriceWaiterId($request['pricewaiter_id']);
|
| 59 |
-
if ($pricewaiterOrder->getId()) {
|
| 60 |
-
$message = "Received a duplicate order from the PriceWaiter Callback API. Ignoring.";
|
| 61 |
-
throw(new Exception($message));
|
| 62 |
-
}
|
| 63 |
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
// This is a new feature as of 1.2.2, so we need to make sure the API
|
| 67 |
-
// is compatible first.
|
| 68 |
-
if (array_key_exists('api_key', $request)
|
| 69 |
-
&& $request['api_key'] != ''
|
| 70 |
-
) {
|
| 71 |
-
$store = Mage::helper('nypwidget')->getStoreByApiKey($request['api_key']);
|
| 72 |
-
$this->_store = $store;
|
| 73 |
-
} else {
|
| 74 |
-
// Fallback for when the API key isn't found
|
| 75 |
-
$this->_store = Mage::app()->getStore();
|
| 76 |
-
}
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
if (!$customer->getId()) {
|
| 84 |
-
// Create a new customer with this email
|
| 85 |
-
$customer->reset();
|
| 86 |
-
$passwordLength = 10;
|
| 87 |
-
$passwordCharacters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
| 88 |
-
$password = '';
|
| 89 |
-
for ($p = 0; $p < $passwordLength; $p++) {
|
| 90 |
-
$password .= $passwordCharacters[mt_rand(0, strlen($passwordCharacters))];
|
| 91 |
-
}
|
| 92 |
-
|
| 93 |
-
$customer->setEmail($request['buyer_email']);
|
| 94 |
-
$customer->setFirstname($request['buyer_first_name']);
|
| 95 |
-
$customer->setLastname($request['buyer_last_name']);
|
| 96 |
-
$customer->setPassword($password);
|
| 97 |
-
$customer->setConfirmation(null);
|
| 98 |
-
$customer->setWebsiteId($this->_store->getWebsiteId());
|
| 99 |
-
$customer->save();
|
| 100 |
-
if (Mage::getStoreConfig('pricewaiter/customer_interaction/send_welcome_email')) {
|
| 101 |
-
$customer->sendNewAccountEmail('registered', '', $this->_store->getId());
|
| 102 |
-
}
|
| 103 |
-
$customer->load($customer->getId());
|
| 104 |
-
}
|
| 105 |
|
| 106 |
-
|
| 107 |
-
$reservedOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($this->_store->getId());
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
} else {
|
| 114 |
-
$currencyCode = $this->_store->getDefaultCurrencyCode();
|
| 115 |
-
}
|
| 116 |
|
| 117 |
-
|
| 118 |
-
->setIncrementId($reservedOrderId)
|
| 119 |
-
->setStoreId($this->_store->getId())
|
| 120 |
-
->setQuoteId(0)
|
| 121 |
-
->setGlobal_currency_code($currencyCode)
|
| 122 |
-
->setBase_currency_code($currencyCode)
|
| 123 |
-
->setStore_currency_code($currencyCode)
|
| 124 |
-
->setOrder_currency_code($currencyCode);
|
| 125 |
-
|
| 126 |
-
// set Customer data
|
| 127 |
-
$order->setCustomer_email($customer->getEmail())
|
| 128 |
-
->setCustomerFirstname($customer->getFirstname())
|
| 129 |
-
->setCustomerLastname($customer->getLastname())
|
| 130 |
-
->setCustomerGroupId($customer->getGroupId())
|
| 131 |
-
->setCustomer_is_guest(0)
|
| 132 |
-
->setCustomer($customer);
|
| 133 |
-
|
| 134 |
-
// Find billing Region ID
|
| 135 |
-
$regionModel = Mage::getModel('directory/region')->loadByCode($request['buyer_billing_state'], $request['buyer_billing_country']);
|
| 136 |
-
|
| 137 |
-
//Get a phone number, or make a dummy one
|
| 138 |
-
if ($request['buyer_billing_phone']) {
|
| 139 |
-
$telephone = $request['buyer_billing_phone'];
|
| 140 |
-
} else {
|
| 141 |
-
$telephone = "000-000-0000";
|
| 142 |
-
}
|
| 143 |
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
$
|
| 147 |
-
|
| 148 |
-
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING)
|
| 149 |
-
->setCustomerId($customer->getId())
|
| 150 |
-
->setPrefix('')
|
| 151 |
-
->setFirstname($request['buyer_billing_first_name'])
|
| 152 |
-
->setMiddlename('')
|
| 153 |
-
->setLastname($request['buyer_billing_last_name'])
|
| 154 |
-
->setSuffix('')
|
| 155 |
-
->setCompany('')
|
| 156 |
-
->setStreet(array($request['buyer_billing_address'], $request['buyer_billing_address2']))
|
| 157 |
-
->setCity($request['buyer_billing_city'])
|
| 158 |
-
->setCountry_id($request['buyer_billing_country'])
|
| 159 |
-
->setRegion($request['buyer_billing_state'])
|
| 160 |
-
->setRegion_id($regionModel->getId())
|
| 161 |
-
->setPostcode($request['buyer_billing_zip'])
|
| 162 |
-
->setTelephone($telephone)
|
| 163 |
-
->setFax('');
|
| 164 |
-
$order->setBillingAddress($billingAddress);
|
| 165 |
-
|
| 166 |
-
// Find shipping Region ID
|
| 167 |
-
$regionModel = Mage::getModel('directory/region')->loadByCode($request['buyer_shipping_state'], $request['buyer_shipping_country']);
|
| 168 |
-
|
| 169 |
-
//Get a phone number, or make a dummy one
|
| 170 |
-
if ($request['buyer_shipping_phone']) {
|
| 171 |
-
$telephone = $request['buyer_shipping_phone'];
|
| 172 |
-
} else {
|
| 173 |
-
$telephone = "000-000-0000";
|
| 174 |
-
}
|
| 175 |
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
$
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
}
|
| 261 |
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
$
|
| 265 |
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
->setBaseGrandTotal($subTotal + $request['shipping']);
|
| 270 |
|
| 271 |
-
$
|
|
|
|
|
|
|
| 272 |
|
| 273 |
// Ok, done with the order.
|
| 274 |
-
$
|
| 275 |
-
|
| 276 |
-
$
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
$
|
| 281 |
-
'store_id' => $order->getStoreId(),
|
| 282 |
-
'pricewaiter_id' => $request['pricewaiter_id'],
|
| 283 |
-
'order_id' => $order->getId()
|
| 284 |
-
));
|
| 285 |
-
$pricewaiterOrder->save();
|
| 286 |
|
| 287 |
-
|
| 288 |
-
|
|
|
|
|
|
|
| 289 |
}
|
| 290 |
|
| 291 |
-
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
|
| 301 |
-
|
| 302 |
-
$
|
| 303 |
-
->create($order->getIncrementId(), array());
|
| 304 |
-
$invoice = Mage::getModel('sales/order_invoice')
|
| 305 |
-
->loadByIncrementId($invoiceId);
|
| 306 |
-
$invoice->capture()->save();
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
Mage::log("The Name Your Price Widget has created order #"
|
| 310 |
-
. $order->getIncrementId() . " with order ID " . $order->getId());
|
| 311 |
-
$this->_log("The Name Your Price Widget has created order #"
|
| 312 |
-
. $order->getIncrementId() . " with order ID " . $order->getId());
|
| 313 |
-
} catch (Exception $e) {
|
| 314 |
-
Mage::app()->getResponse()->setHeader('HTTP/1.0 500 Internal Server Error', 500, true);
|
| 315 |
-
Mage::app()->getResponse()->setHeader('X-Platform-Error', $e->getMessage(), true);
|
| 316 |
-
$this->_log("PriceWaiter Name Your Price Widget was unable to create order. Check log for details.");
|
| 317 |
-
$this->_log($e->getMessage());
|
| 318 |
}
|
| 319 |
|
|
|
|
| 320 |
}
|
| 321 |
|
| 322 |
private function _log($message)
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Model_Callback
|
| 4 |
{
|
| 5 |
+
/**
|
| 6 |
+
* Description used for shipping if none specified.
|
| 7 |
+
*/
|
| 8 |
+
const DEFAULT_SHIPPING_DESCRIPTION = 'PriceWaiter';
|
| 9 |
+
|
| 10 |
+
const LOGFILE = 'PriceWaiter_Callback.log';
|
| 11 |
+
|
| 12 |
+
const XML_PATH_ORDER_LOGGING = 'pricewaiter/orders/log';
|
| 13 |
+
|
| 14 |
+
/**
|
| 15 |
+
* @var PriceWaiter_NYPWidget_Helper_Data
|
| 16 |
+
*/
|
| 17 |
+
private $_helper = null;
|
| 18 |
+
|
| 19 |
+
/**
|
| 20 |
+
* @internal Probably redundant, but don't want to tie our field names to internal Magento constants.
|
| 21 |
+
* @var array
|
| 22 |
+
*/
|
| 23 |
+
protected static $magentoAddressTypes = array(
|
| 24 |
+
'billing' => Mage_Sales_Model_Quote_Address::TYPE_BILLING,
|
| 25 |
+
'shipping' => Mage_Sales_Model_Quote_Address::TYPE_SHIPPING
|
| 26 |
+
);
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* @internal
|
| 30 |
+
* @var string
|
| 31 |
+
*/
|
| 32 |
+
protected $passwordCharacters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* @internal Adds items to the given order and calculates final total.
|
| 36 |
+
* @param Mage_Sales_Model_Order $order [description]
|
| 37 |
+
* @param Array $request [description]
|
| 38 |
+
* @param Mage_Core_Model_Store $store [description]
|
| 39 |
+
* @param Mage_Customer_Model_Customer $customer [description]
|
| 40 |
+
*/
|
| 41 |
+
public function addItemsToOrder(
|
| 42 |
+
Mage_Sales_Model_Order $order,
|
| 43 |
+
Array $request,
|
| 44 |
+
Mage_Core_Model_Store $store,
|
| 45 |
+
Mage_Customer_Model_Customer $customer
|
| 46 |
+
)
|
| 47 |
+
{
|
| 48 |
+
$product = $this->findProduct($request);
|
| 49 |
+
|
| 50 |
+
if (!$product) {
|
| 51 |
+
throw new PriceWaiter_NYPWidget_Exception_Product_NotFound();
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// Build the pricing information of the product
|
| 55 |
+
$orderItem = Mage::getModel('sales/order_item')
|
| 56 |
+
->setStoreId($store->getId())
|
| 57 |
+
->setQuoteItemId(0)
|
| 58 |
+
->setQuoteParentItemId(null)
|
| 59 |
+
->setProductId($product->getId())
|
| 60 |
+
->setProductType($product->getTypeId())
|
| 61 |
+
->setTotalQtyOrdered($request['quantity'])
|
| 62 |
+
->setQtyOrdered($request['quantity'])
|
| 63 |
+
->setName($product->getName())
|
| 64 |
+
->setSku($product->getSku())
|
| 65 |
+
->setIsNominal(0);
|
| 66 |
+
|
| 67 |
+
// Delegate out to some more unit-testable code to calculate all the
|
| 68 |
+
// various amount fields present on the order item.
|
| 69 |
+
$amounts = $this->calculateOrderItemAmounts(
|
| 70 |
+
$request,
|
| 71 |
+
$product->getPrice(),
|
| 72 |
+
array($store, 'roundPrice')
|
| 73 |
+
);
|
| 74 |
+
foreach($amounts as $key => $value) {
|
| 75 |
+
$orderItem->setData($key, $value);
|
| 76 |
+
$orderItem->setData("base_$key", $value);
|
| 77 |
+
}
|
| 78 |
|
| 79 |
+
$additionalOptions = array();
|
| 80 |
+
foreach($this->buildProductOptionsArray($request) as $label => $value) {
|
| 81 |
+
$additionalOptions[] = array(
|
| 82 |
+
'label' => $label,
|
| 83 |
+
'value' => $value,
|
| 84 |
+
);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
$orderItem->setProductOptions(array('additional_options' => $additionalOptions));
|
| 88 |
|
| 89 |
+
$order->addItem($orderItem);
|
| 90 |
+
}
|
| 91 |
|
| 92 |
+
/**
|
| 93 |
+
* @internal Constructs address models based on request data.
|
| 94 |
+
* @param String $type 'billing' or 'shipping'.
|
| 95 |
+
* @param Array $request
|
| 96 |
+
* @param Mage_Customer_Model_Customer $customer
|
| 97 |
+
* @param Mage_Core_Model_Store $store
|
| 98 |
+
* @return Mage_Sales_Model_Order_Address
|
| 99 |
+
* @throws PriceWaiter_NYPWidget_Exception_InvalidRegion
|
| 100 |
+
*/
|
| 101 |
+
public function buildAddress($type, Array $request, Mage_Customer_Model_Customer $customer, Mage_Core_Model_Store $store)
|
| 102 |
{
|
| 103 |
+
$state = $request["buyer_{$type}_state"];
|
| 104 |
+
$country = $request["buyer_{$type}_country"];
|
| 105 |
+
|
| 106 |
+
// Resolve state + country into a Mage_Directory_Model_Region
|
| 107 |
+
$regionModel = Mage::getModel('directory/region')
|
| 108 |
+
->loadByCode($state, $country);
|
| 109 |
+
|
| 110 |
+
if (!$regionModel->getId()) {
|
| 111 |
+
throw new PriceWaiter_NYPWidget_Exception_InvalidRegion($state, $country);
|
| 112 |
}
|
| 113 |
|
| 114 |
+
return Mage::getModel('sales/order_address')
|
| 115 |
+
// System data
|
| 116 |
+
->setStoreId($store->getId())
|
| 117 |
+
->setAddressType(self::$magentoAddressTypes[$type])
|
| 118 |
+
|
| 119 |
+
// Customer + name
|
| 120 |
+
->setCustomerId($customer->getId())
|
| 121 |
+
->setPrefix('')
|
| 122 |
+
->setFirstname($request["buyer_{$type}_first_name"])
|
| 123 |
+
->setMiddlename('')
|
| 124 |
+
->setLastname($request["buyer_{$type}_last_name"])
|
| 125 |
+
->setSuffix('')
|
| 126 |
+
->setCompany('')
|
| 127 |
+
|
| 128 |
+
// Actual address
|
| 129 |
+
->setStreet(array_filter(array(
|
| 130 |
+
$request["buyer_{$type}_address"],
|
| 131 |
+
$request["buyer_{$type}_address2"],
|
| 132 |
+
$request["buyer_{$type}_address3"],
|
| 133 |
+
)))
|
| 134 |
+
->setCity($request["buyer_{$type}_city"])
|
| 135 |
+
->setRegionId($regionModel->getId())
|
| 136 |
+
->setPostcode($request["buyer_{$type}_zip"])
|
| 137 |
+
->setCountryId($country)
|
| 138 |
+
|
| 139 |
+
// Phone numbers
|
| 140 |
+
->setTelephone($request["buyer_{$type}_phone"])
|
| 141 |
+
->setFax('');
|
| 142 |
+
}
|
| 143 |
|
| 144 |
+
/**
|
| 145 |
+
* @internal Assembles a Mage_Sales_Model_Order out of all incoming request data.
|
| 146 |
+
* @param Array $request
|
| 147 |
+
* @param Mage_Core_Model_Store $store
|
| 148 |
+
* @param Mage_Customer_Model_Customer $customer
|
| 149 |
+
* @return Mage_Sales_Model_Order
|
| 150 |
+
*/
|
| 151 |
+
public function buildMagentoOrder(Array $request, Mage_Core_Model_Store $store, Mage_Customer_Model_Customer $customer)
|
| 152 |
+
{
|
| 153 |
+
$reservedOrderId = Mage::getSingleton('eav/config')
|
| 154 |
+
->getEntityType('order')
|
| 155 |
+
->fetchNewIncrementId($store->getId());
|
| 156 |
+
|
| 157 |
+
$currencyCode = $request['currency'];
|
| 158 |
+
|
| 159 |
+
$order = Mage::getModel('sales/order')
|
| 160 |
+
// System fields
|
| 161 |
+
->setIncrementId($reservedOrderId)
|
| 162 |
+
->setStoreId($store->getId())
|
| 163 |
+
->setQuoteId(0)
|
| 164 |
+
->setGlobalCurrencyCode($currencyCode)
|
| 165 |
+
->setBaseCurrencyCode($currencyCode)
|
| 166 |
+
->setStoreCurrencyCode($currencyCode)
|
| 167 |
+
->setOrderCurrencyCode($currencyCode)
|
| 168 |
+
|
| 169 |
+
// Customer
|
| 170 |
+
->setCustomerEmail($customer->getEmail())
|
| 171 |
+
->setCustomerFirstname($customer->getFirstname())
|
| 172 |
+
->setCustomerLastname($customer->getLastname())
|
| 173 |
+
->setCustomerGroupId($customer->getGroupId())
|
| 174 |
+
->setCustomerIsGuest(0)
|
| 175 |
+
->setCustomer($customer)
|
| 176 |
+
|
| 177 |
+
// Addresses
|
| 178 |
+
->setBillingAddress($this->buildAddress(
|
| 179 |
+
'billing',
|
| 180 |
+
$request,
|
| 181 |
+
$customer,
|
| 182 |
+
$store
|
| 183 |
+
))
|
| 184 |
+
->setShippingAddress($this->buildAddress(
|
| 185 |
+
'shipping',
|
| 186 |
+
$request,
|
| 187 |
+
$customer,
|
| 188 |
+
$store
|
| 189 |
+
));
|
| 190 |
|
| 191 |
+
$this->setOrderShippingMethod($order, $request, $store, $customer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
+
$this->setOrderPaymentMethod($order, $request, $store, $customer);
|
| 194 |
|
| 195 |
+
$this->addItemsToOrder($order, $request, $store, $customer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
|
| 197 |
+
$product = $this->findProduct($request);
|
| 198 |
+
if (!$product) {
|
| 199 |
+
throw new PriceWaiter_NYPWidget_Exception_Product_NotFound();
|
| 200 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
+
$amounts = $this->calculateOrderAmounts($request, $product->getPrice(), array($store, 'roundPrice'));
|
|
|
|
| 203 |
|
| 204 |
+
foreach($amounts as $key => $value) {
|
| 205 |
+
$order->setData($key, $value);
|
| 206 |
+
$order->setData("base_$key", $value);
|
| 207 |
+
}
|
|
|
|
|
|
|
|
|
|
| 208 |
|
| 209 |
+
$order->setDiscountDescription('PriceWaiter');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
|
| 211 |
+
$comment = $this->getNewOrderComment($request);
|
| 212 |
+
if ($comment) {
|
| 213 |
+
$order->addStatusHistoryComment($comment);
|
| 214 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
+
return $order;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
/**
|
| 220 |
+
* @internal
|
| 221 |
+
* Assembles an array of product options in the format array("name" => "value", "name" => "value")
|
| 222 |
+
* @param Array $request
|
| 223 |
+
*/
|
| 224 |
+
public function buildProductOptionsArray(Array $request)
|
| 225 |
+
{
|
| 226 |
+
$options = array();
|
| 227 |
+
|
| 228 |
+
$count = intval($request['product_option_count']);
|
| 229 |
+
|
| 230 |
+
// Decode product_option_name<N> and product_option_value<N>-style incoming data.
|
| 231 |
+
// Note that we start numbering at 1.
|
| 232 |
+
|
| 233 |
+
for ($i = 1; $i <= $count; $i++) {
|
| 234 |
+
$nameKey = "product_option_name{$i}";
|
| 235 |
+
$name = $request[$nameKey];
|
| 236 |
+
|
| 237 |
+
$valueKey = "product_option_value{$i}";
|
| 238 |
+
$value = $request[$valueKey];
|
| 239 |
+
|
| 240 |
+
$options[$name] = $value;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
return $options;
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
/**
|
| 247 |
+
* @internal Calculates pricing-related fields to go on the order.
|
| 248 |
+
* @param Array $request
|
| 249 |
+
* @return Array
|
| 250 |
+
*/
|
| 251 |
+
public function calculateOrderAmounts(Array $request, $productPrice, Callable $rounder)
|
| 252 |
+
{
|
| 253 |
+
$amountPerItem = $request['unit_price'];
|
| 254 |
+
$qty = $request['quantity'];
|
| 255 |
+
$shipping = $request['shipping'];
|
| 256 |
+
$tax = $request['tax'];
|
| 257 |
+
$subtotal = $amountPerItem * $qty;
|
| 258 |
+
|
| 259 |
+
$regularSubtotal = $productPrice * $qty;
|
| 260 |
+
$discountAmount = $regularSubtotal - $subtotal;
|
| 261 |
+
|
| 262 |
+
$total = $rounder($subtotal + $shipping + $tax);
|
| 263 |
+
|
| 264 |
+
return array(
|
| 265 |
+
'discount_amount' => $rounder(-$discountAmount),
|
| 266 |
+
'grand_total' => $total,
|
| 267 |
+
'shipping_amount' => $shipping,
|
| 268 |
+
'shipping_discount_amount' => 0,
|
| 269 |
+
'shipping_incl_tax' => $shipping,
|
| 270 |
+
'shipping_tax_amount' => 0,
|
| 271 |
+
'subtotal' => $rounder($regularSubtotal),
|
| 272 |
+
'subtotal_incl_tax' => $rounder($regularSubtotal + $tax),
|
| 273 |
+
'tax_amount' => $rounder($tax),
|
| 274 |
+
);
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
/**
|
| 278 |
+
* @internal Calculates pricing-related fields to be set on an order item.
|
| 279 |
+
* @param Array $request
|
| 280 |
+
* @param Mage_Catalog_Model_Product $product
|
| 281 |
+
*/
|
| 282 |
+
public function calculateOrderItemAmounts(Array $request, $productPrice, Callable $rounder)
|
| 283 |
+
{
|
| 284 |
+
$amountPerItem = $request['unit_price'];
|
| 285 |
+
$qty = $request['quantity'];
|
| 286 |
+
$subtotal = $amountPerItem * $qty;
|
| 287 |
+
$tax = $request['tax'];
|
| 288 |
+
$taxPercent = $tax / ($amountPerItem * $qty);
|
| 289 |
+
|
| 290 |
+
$regularSubtotal = $productPrice * $qty;
|
| 291 |
+
$taxBeforeDiscount = $regularSubtotal * $taxPercent;
|
| 292 |
+
|
| 293 |
+
$discountAmount = $regularSubtotal - $subtotal;
|
| 294 |
+
$discountPercent = $discountAmount / $regularSubtotal * 100;
|
| 295 |
+
|
| 296 |
+
return array(
|
| 297 |
+
'discount_amount' => $rounder($discountAmount),
|
| 298 |
+
'discount_percent' => $rounder($discountPercent),
|
| 299 |
+
'original_price' => $productPrice,
|
| 300 |
+
'price' => $productPrice,
|
| 301 |
+
'price_incl_tax' => $rounder($productPrice + ($tax / $qty)),
|
| 302 |
+
'row_total' => $rounder($regularSubtotal),
|
| 303 |
+
'row_total_incl_tax' => $rounder($regularSubtotal + $tax),
|
| 304 |
+
'tax_amount' => $tax,
|
| 305 |
+
'tax_before_discount' => $rounder($taxBeforeDiscount),
|
| 306 |
+
'tax_percent' => $rounder($taxPercent * 100),
|
| 307 |
+
);
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
/**
|
| 311 |
+
* @internal Creates a new customer, saves it, and returns it.
|
| 312 |
+
* @param Array $request
|
| 313 |
+
* @param Mage_Core_Model_Store $store
|
| 314 |
+
* @return Mage_Customer_Model_Customer
|
| 315 |
+
*/
|
| 316 |
+
public function createCustomer(Array $request, Mage_Core_Model_Store $store)
|
| 317 |
+
{
|
| 318 |
+
$customer = Mage::getModel('customer/customer')
|
| 319 |
+
// System
|
| 320 |
+
->setWebsiteId($store->getWebsiteId())
|
| 321 |
+
->setPassword($this->generatePassword(10))
|
| 322 |
+
->setConfirmation(null)
|
| 323 |
+
|
| 324 |
+
// Person
|
| 325 |
+
->setEmail($request['buyer_email'])
|
| 326 |
+
->setFirstname($request['buyer_first_name'])
|
| 327 |
+
->setLastname($request['buyer_last_name']);
|
| 328 |
|
| 329 |
+
$customer->save();
|
| 330 |
+
|
| 331 |
+
$this->sendWelcomeEmail($customer, $store);
|
| 332 |
+
|
| 333 |
+
return $customer;
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
/**
|
| 337 |
+
* @internal Either returns an existing customer (by email) or creates a new one.
|
| 338 |
+
* @param Array $request
|
| 339 |
+
* @param Mage_Core_Model_Store $store
|
| 340 |
+
* @return Mage_Customer_Model_Customer
|
| 341 |
+
*/
|
| 342 |
+
public function findOrCreateCustomer(Array $request, Mage_Core_Model_Store $store)
|
| 343 |
+
{
|
| 344 |
+
$customer = Mage::getModel('customer/customer')
|
| 345 |
+
->setWebsiteId($store->getWebsiteId())
|
| 346 |
+
->loadByEmail($request['buyer_email']);
|
| 347 |
+
|
| 348 |
+
if ($customer->getId()) {
|
| 349 |
+
// This an existing customer for this Magento store.
|
| 350 |
+
return $customer;
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
return $this->createCustomer($request, $store);
|
| 354 |
+
}
|
| 355 |
+
|
| 356 |
+
/**
|
| 357 |
+
* @internal Resolves the product for an incoming request.
|
| 358 |
+
* @param Array $request
|
| 359 |
+
* @return Mage_Catalog_Model_Product|false
|
| 360 |
+
*/
|
| 361 |
+
public function findProduct(Array $request)
|
| 362 |
+
{
|
| 363 |
+
$productSku = $request['product_sku'];
|
| 364 |
+
$productOptions = $this->buildProductOptionsArray($request);
|
| 365 |
+
|
| 366 |
+
$product = $this->getHelper()->getProductWithOptions($productSku, $productOptions);
|
| 367 |
+
|
| 368 |
+
return $product->getId() ? $product : false;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
/**
|
| 372 |
+
* Looks for an existing order that matches the given order callback request.
|
| 373 |
+
* @param Array $request
|
| 374 |
+
* @return PriceWaiter_NYPWidget_Model_Order|false
|
| 375 |
+
*/
|
| 376 |
+
public function getExistingOrder(Array $request)
|
| 377 |
+
{
|
| 378 |
+
$existingOrder = Mage::getModel('nypwidget/order');
|
| 379 |
+
$existingOrder->loadByPriceWaiterId($request['pricewaiter_id']);
|
| 380 |
+
|
| 381 |
+
if ($existingOrder->getId()) {
|
| 382 |
+
return $existingOrder;
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
return false;
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
/**
|
| 389 |
+
* @param Array $request
|
| 390 |
+
* @return String Comment to be added to the order generated from $request.
|
| 391 |
+
*/
|
| 392 |
+
public function getNewOrderComment(Array $request)
|
| 393 |
+
{
|
| 394 |
+
$helper = $this->getHelper();
|
| 395 |
+
$url = $helper->getOfferUrl($request['pricewaiter_id']);
|
| 396 |
+
|
| 397 |
+
$safeUrl = htmlentities($url, ENT_QUOTES);
|
| 398 |
+
|
| 399 |
+
return sprintf(
|
| 400 |
+
'Ordered via PriceWaiter (<a href="%s" target="_blank">%s</a>).',
|
| 401 |
+
$safeUrl,
|
| 402 |
+
$safeUrl
|
| 403 |
+
);
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
/**
|
| 407 |
+
* @param Array $request
|
| 408 |
+
* @return Mage_Core_Model_Store
|
| 409 |
+
* @throws PriceWaiter_NYPWidget_Exception_ApiKey If no store configured for API key.
|
| 410 |
+
*/
|
| 411 |
+
public function getStore(Array $request)
|
| 412 |
+
{
|
| 413 |
+
$apiKey = isset($request['api_key']) ? $request['api_key'] : null;
|
| 414 |
+
$store = false;
|
| 415 |
+
|
| 416 |
+
if ($apiKey) {
|
| 417 |
+
$store = $this->getHelper()->getStoreByPriceWaiterApiKey($apiKey);
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
if (!$store) {
|
| 421 |
+
throw new PriceWaiter_NYPWidget_Exception_ApiKey();
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
return $store;
|
| 425 |
+
}
|
| 426 |
+
|
| 427 |
+
/**
|
| 428 |
+
* @return boolean
|
| 429 |
+
*/
|
| 430 |
+
public function isTestOrder(Array $request)
|
| 431 |
+
{
|
| 432 |
+
return !empty($request['test']);
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
/**
|
| 436 |
+
* @param Array $request
|
| 437 |
+
* @return Mage_Sales_Model_Order
|
| 438 |
+
*/
|
| 439 |
+
public function processRequest(Array $request)
|
| 440 |
+
{
|
| 441 |
+
$this->logIncomingRequest($request);
|
| 442 |
+
|
| 443 |
+
// Hint to our custom payment method about the incoming request
|
| 444 |
+
PriceWaiter_NYPWidget_Model_PaymentMethod::setCurrentOrderCallbackRequest($request);
|
| 445 |
+
|
| 446 |
+
try
|
| 447 |
+
{
|
| 448 |
+
if (!$this->verifyRequest($request)) {
|
| 449 |
+
throw new PriceWaiter_NYPWidget_Exception_InvalidOrderData();
|
| 450 |
}
|
| 451 |
|
| 452 |
+
$store = $this->getStore($request);
|
| 453 |
+
|
| 454 |
+
$existingOrder = $this->getExistingOrder($request);
|
| 455 |
|
| 456 |
+
if ($existingOrder) {
|
| 457 |
+
throw new PriceWaiter_NYPWidget_Exception_DuplicateOrder($existingOrder);
|
| 458 |
+
}
|
|
|
|
| 459 |
|
| 460 |
+
$customer = $this->findOrCreateCustomer($request, $store);
|
| 461 |
+
|
| 462 |
+
$order = $this->buildMagentoOrder($request, $store, $customer);
|
| 463 |
|
| 464 |
// Ok, done with the order.
|
| 465 |
+
$this->saveAndPlaceOrder($order);
|
| 466 |
+
|
| 467 |
+
$this->logOrderCreated($request, $order);
|
| 468 |
+
|
| 469 |
+
// --- After this point, we have a *live* order in the system. ---
|
| 470 |
+
|
| 471 |
+
$this->recordOrderCreation($request, $order);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 472 |
|
| 473 |
+
$this->sendNewOrderEmail($order, $store);
|
| 474 |
+
|
| 475 |
+
if ($this->isTestOrder($request)) {
|
| 476 |
+
$this->cancelOrder($order);
|
| 477 |
}
|
| 478 |
|
| 479 |
+
PriceWaiter_NYPWidget_Model_PaymentMethod::resetCurrentOrderCallbackRequest();
|
| 480 |
+
return $order;
|
| 481 |
+
}
|
| 482 |
+
catch (Exception $ex)
|
| 483 |
+
{
|
| 484 |
+
$this->logException($request, $ex);
|
| 485 |
+
PriceWaiter_NYPWidget_Model_PaymentMethod::resetCurrentOrderCallbackRequest();
|
| 486 |
+
throw $ex;
|
| 487 |
+
}
|
| 488 |
+
}
|
| 489 |
|
| 490 |
+
/**
|
| 491 |
+
* @internal Assigns details around order payment.
|
| 492 |
+
* @param Mage_Sales_Model_Order $order
|
| 493 |
+
* @param Array $request
|
| 494 |
+
* @param Mage_Core_Model_Store $store
|
| 495 |
+
* @param Mage_Customer_Model_Customer $customer
|
| 496 |
+
*/
|
| 497 |
+
public function setOrderPaymentMethod(
|
| 498 |
+
Mage_Sales_Model_Order $order,
|
| 499 |
+
Array $request,
|
| 500 |
+
Mage_Core_Model_Store $store,
|
| 501 |
+
Mage_Customer_Model_Customer $customer
|
| 502 |
+
)
|
| 503 |
+
{
|
| 504 |
+
// Add PriceWaiter payment method
|
| 505 |
+
$orderPayment = Mage::getModel('sales/order_payment')
|
| 506 |
+
->setMethod('nypwidget')
|
| 507 |
+
->setStoreId($store->getId())
|
| 508 |
+
->setCustomerPaymentId(0)
|
| 509 |
+
->setTransactionId($request['transaction_id']);
|
| 510 |
+
|
| 511 |
+
// Extra details for credit card payments
|
| 512 |
+
if (!empty($request['cc_type'])) {
|
| 513 |
+
$ccType = $this->translateCcType($request['cc_type']);
|
| 514 |
+
if ($ccType) {
|
| 515 |
+
$orderPayment->setCcType($ccType);
|
| 516 |
}
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
if (!empty($request['cc_last4'])) {
|
| 520 |
+
$orderPayment->setCcLast4($request['cc_last4']);
|
| 521 |
+
}
|
| 522 |
+
|
| 523 |
+
if (!empty($request['avs_result'])) {
|
| 524 |
+
$orderPayment->setCcAvsStatus($request['avs_result']);
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
// Stash PW-specific stuff in "additional data"
|
| 528 |
+
$additionalData = array(
|
| 529 |
+
'pricewaiter_payment_method' => $request['payment_method'],
|
| 530 |
+
);
|
| 531 |
+
|
| 532 |
+
if (!empty($request['payment_method_nice'])) {
|
| 533 |
+
$additionalData['pricewaiter_payment_method_nice'] =
|
| 534 |
+
$request['payment_method_nice'];
|
| 535 |
+
}
|
| 536 |
+
|
| 537 |
+
$orderPayment->setAdditionalData(serialize($additionalData));
|
| 538 |
+
|
| 539 |
+
$order->setPayment($orderPayment);
|
| 540 |
+
}
|
| 541 |
+
|
| 542 |
+
/**
|
| 543 |
+
* @internal Assigns details around shipping method to $order.
|
| 544 |
+
* @param Mage_Sales_Model_Order $order
|
| 545 |
+
* @param Array $request
|
| 546 |
+
* @param Mage_Core_Model_Store $store
|
| 547 |
+
* @param Mage_Customer_Model_Customer $customer
|
| 548 |
+
*/
|
| 549 |
+
public function setOrderShippingMethod(
|
| 550 |
+
Mage_Sales_Model_Order $order,
|
| 551 |
+
Array $request,
|
| 552 |
+
Mage_Core_Model_Store $store,
|
| 553 |
+
Mage_Customer_Model_Customer $customer
|
| 554 |
+
)
|
| 555 |
+
{
|
| 556 |
+
$description = $request['shipping_method'];
|
| 557 |
+
if (trim($description) === '') {
|
| 558 |
+
// Leaving description blank results in "No shipping information available" in PW admin
|
| 559 |
+
$description = self::DEFAULT_SHIPPING_DESCRIPTION;
|
| 560 |
+
}
|
| 561 |
+
|
| 562 |
+
// Use PriceWaiter shipping method
|
| 563 |
+
$order->setShippingMethod('nypwidget_nypwidget')
|
| 564 |
+
->setShippingAmount($request['shipping'])
|
| 565 |
+
->setShippingDescription($description);
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
/**
|
| 569 |
+
* @internal
|
| 570 |
+
* @return PriceWaiter_NYPWidget_Helper_Data
|
| 571 |
+
*/
|
| 572 |
+
public function getHelper()
|
| 573 |
+
{
|
| 574 |
+
if ($this->_helper === null) {
|
| 575 |
+
$this->_helper = Mage::helper('nypwidget');
|
| 576 |
+
}
|
| 577 |
+
return $this->_helper;
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
/**
|
| 581 |
+
* @internal
|
| 582 |
+
* @param PriceWaiter_NYPWidget_Helper_Data $helper
|
| 583 |
+
* @return PriceWaiter_NYPWidget_Model_Callback $this
|
| 584 |
+
*/
|
| 585 |
+
public function setHelper(PriceWaiter_NYPWidget_Helper_Data $helper)
|
| 586 |
+
{
|
| 587 |
+
$this->_helper = $helper;
|
| 588 |
+
return $this;
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
/**
|
| 592 |
+
* Attempts to validate incoming PriceWaiter order data by POSTing it back
|
| 593 |
+
* to the PriceWaiter Order Verification endpoint.
|
| 594 |
+
* @param Array $request
|
| 595 |
+
*/
|
| 596 |
+
public function verifyRequest(Array $request)
|
| 597 |
+
{
|
| 598 |
+
$verifyUrl = $this->getHelper()->getOrderVerificationUrl();
|
| 599 |
+
$ch = curl_init($verifyUrl);
|
| 600 |
+
|
| 601 |
+
if (!$ch) {
|
| 602 |
+
return false;
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
// NOTE: Building $postFields string manually to avoid multipart/form-data content type
|
| 606 |
+
// assigned by default when using Array.
|
| 607 |
+
$postFields = http_build_query(
|
| 608 |
+
$request,
|
| 609 |
+
'',
|
| 610 |
+
'&',
|
| 611 |
+
// NOTE: PHP_QUERY_RFC1738 added in PHP 5.4
|
| 612 |
+
defined('PHP_QUERY_RFC1738') ? PHP_QUERY_RFC1738 : 0
|
| 613 |
+
);
|
| 614 |
+
|
| 615 |
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
| 616 |
+
curl_setopt($ch, CURLOPT_POST, true);
|
| 617 |
+
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
|
| 618 |
+
|
| 619 |
+
if (defined('CURLOPT_SAFE_UPLOAD')) {
|
| 620 |
+
// Disable curl's dumb '@filename' upload option
|
| 621 |
+
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
$response = curl_exec($ch);
|
| 625 |
+
$valid = ($response === '1');
|
| 626 |
+
|
| 627 |
+
return $valid;
|
| 628 |
+
}
|
| 629 |
+
|
| 630 |
+
/**
|
| 631 |
+
* @internal
|
| 632 |
+
* @param Mage_Sales_Model_Order $order
|
| 633 |
+
*/
|
| 634 |
+
protected function cancelOrder(Mage_Sales_Model_Order $order)
|
| 635 |
+
{
|
| 636 |
+
$order->cancel();
|
| 637 |
+
$order->save();
|
| 638 |
+
}
|
| 639 |
+
|
| 640 |
+
/**
|
| 641 |
+
* @internal
|
| 642 |
+
* @param Integer $length
|
| 643 |
+
* @return String
|
| 644 |
+
*/
|
| 645 |
+
protected function generatePassword($length)
|
| 646 |
+
{
|
| 647 |
+
$password = [];
|
| 648 |
+
|
| 649 |
+
$numberOfChars = strlen($this->passwordCharacters);
|
| 650 |
+
|
| 651 |
+
for ($i = 0; $i < $length; $i++) {
|
| 652 |
+
$password[] = $this->passwordCharacters[mt_rand(0, $numberOfChars - 1)];
|
| 653 |
+
}
|
| 654 |
+
|
| 655 |
+
return implode('', $password);
|
| 656 |
+
}
|
| 657 |
+
|
| 658 |
+
protected function isLogEnabled($store = null)
|
| 659 |
+
{
|
| 660 |
+
return !!Mage::getStoreConfig(
|
| 661 |
+
self::XML_PATH_ORDER_LOGGING,
|
| 662 |
+
$store
|
| 663 |
+
);
|
| 664 |
+
}
|
| 665 |
+
|
| 666 |
+
/**
|
| 667 |
+
* @internal
|
| 668 |
+
*/
|
| 669 |
+
protected function logException(Array $request, Exception $ex)
|
| 670 |
+
{
|
| 671 |
+
$id = isset($request['pricewaiter_id']) ? $request['pricewaiter_id'] : '';
|
| 672 |
+
|
| 673 |
+
$message = $ex->getMessage();
|
| 674 |
+
$code = isset($ex->errorCode) ? $ex->errorCode : null;
|
| 675 |
+
|
| 676 |
+
return $this->log(
|
| 677 |
+
'Error processing order callback for PriceWaiter offer #%s: %s (%s)',
|
| 678 |
+
$id,
|
| 679 |
+
$message,
|
| 680 |
+
$code
|
| 681 |
+
);
|
| 682 |
+
}
|
| 683 |
+
|
| 684 |
+
/**
|
| 685 |
+
* @internal
|
| 686 |
+
*/
|
| 687 |
+
protected function logIncomingRequest(Array $request)
|
| 688 |
+
{
|
| 689 |
+
$id = isset($request['pricewaiter_id']) ? $request['pricewaiter_id'] : '';
|
| 690 |
+
return $this->log('Received order callback for PriceWaiter offer %s', $id);
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
/**
|
| 694 |
+
* @internal
|
| 695 |
+
*/
|
| 696 |
+
protected function logOrderCreated(Array $request, Mage_Sales_Model_Order $order)
|
| 697 |
+
{
|
| 698 |
+
$id = isset($request['pricewaiter_id']) ? $request['pricewaiter_id'] : '';
|
| 699 |
+
$orderId = $order->getIncrementId();
|
| 700 |
+
return $this->log('Created order #%s for PriceWaiter offer %s', $orderId, $id);
|
| 701 |
+
}
|
| 702 |
+
|
| 703 |
+
|
| 704 |
+
/**
|
| 705 |
+
* Runs the arguments through sprintf and passes them to the order callback log.
|
| 706 |
+
* @return PriceWaiter_NYPWidget_Model_Callback $this
|
| 707 |
+
*/
|
| 708 |
+
protected function log()
|
| 709 |
+
{
|
| 710 |
+
if (!$this->isLogEnabled()) {
|
| 711 |
+
return $this;
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
$args = func_get_args();
|
| 715 |
+
$message = call_user_func_array('sprintf', $args);
|
| 716 |
+
|
| 717 |
+
Mage::log($message, null, self::LOGFILE);
|
| 718 |
+
return $this;
|
| 719 |
+
}
|
| 720 |
+
|
| 721 |
+
/**
|
| 722 |
+
* Stores a record in the db indicating we've processed $request into $order. This is used for
|
| 723 |
+
* duplicate order detection.
|
| 724 |
+
* @param Array $request
|
| 725 |
+
* @param Mage_Sales_Model_Order $order
|
| 726 |
+
*/
|
| 727 |
+
protected function recordOrderCreation(Array $request, Mage_Sales_Model_Order $order)
|
| 728 |
+
{
|
| 729 |
+
Mage::getModel('nypwidget/order')
|
| 730 |
+
->setStoreId($order->getStoreId())
|
| 731 |
+
->setPricewaiterId($request['pricewaiter_id'])
|
| 732 |
+
->setOrderId($order->getId())
|
| 733 |
+
->save();
|
| 734 |
+
}
|
| 735 |
+
|
| 736 |
+
/**
|
| 737 |
+
* @param Mage_Sales_Model_Order $order
|
| 738 |
+
*/
|
| 739 |
+
protected function saveAndPlaceOrder(Mage_Sales_Model_Order $order)
|
| 740 |
+
{
|
| 741 |
+
// NOTE: Magento's built-in inventory handling operates during the conversion
|
| 742 |
+
// of quotes -> orders. Since we write orders directly (without a quote),
|
| 743 |
+
// we have to handle inventory ourselves.
|
| 744 |
+
$inventory = Mage::getModel('nypwidget/callback_inventory', $order);
|
| 745 |
+
|
| 746 |
+
$transaction = Mage::getModel('core/resource_transaction');
|
| 747 |
+
$transaction->addObject($order);
|
| 748 |
+
$transaction->addCommitCallback(array($inventory, 'registerPricewaiterSale'));
|
| 749 |
+
$transaction->addCommitCallback(array($order, 'place'));
|
| 750 |
+
$transaction->addCommitCallback(array($order, 'save'));
|
| 751 |
+
$transaction->save();
|
| 752 |
+
}
|
| 753 |
+
|
| 754 |
+
/**
|
| 755 |
+
* @param Mage_Sales_Model_Order $order
|
| 756 |
+
* @param Mage_Core_Model_Store $store
|
| 757 |
+
* @return Boolean Whether email was sent.
|
| 758 |
+
*/
|
| 759 |
+
protected function sendNewOrderEmail(Mage_Sales_Model_Order $order, Mage_Core_Model_Store $store)
|
| 760 |
+
{
|
| 761 |
+
if (!$store->getConfig('pricewaiter/customer_interaction/send_new_order_email')) {
|
| 762 |
+
return false;
|
| 763 |
+
}
|
| 764 |
+
|
| 765 |
+
$order->sendNewOrderEmail();
|
| 766 |
+
return true;
|
| 767 |
+
}
|
| 768 |
+
|
| 769 |
+
/**
|
| 770 |
+
* @param Mage_Customer_Model_Customer $customer
|
| 771 |
+
* @return Boolean Whether email was sent.
|
| 772 |
+
*/
|
| 773 |
+
protected function sendWelcomeEmail(Mage_Customer_Model_Customer $customer, Mage_Core_Model_Store $store)
|
| 774 |
+
{
|
| 775 |
+
if (!$store->getConfig('pricewaiter/customer_interaction/send_welcome_email')) {
|
| 776 |
+
return false;
|
| 777 |
+
}
|
| 778 |
+
|
| 779 |
+
$customer->sendNewAccountEmail('registered', '', $store->getId());
|
| 780 |
+
|
| 781 |
+
return true;
|
| 782 |
+
}
|
| 783 |
+
|
| 784 |
+
/**
|
| 785 |
+
* @internal Translates an incoming PriceWaiter cc_type into a 2-character Magento credit card type.
|
| 786 |
+
* @param String $type A credit card type, e.g. "Visa".
|
| 787 |
+
* @return String|false A 2-character credit card type code or false if none can be resolved.
|
| 788 |
+
*/
|
| 789 |
+
public function translateCcType($type)
|
| 790 |
+
{
|
| 791 |
+
/**
|
| 792 |
+
* @var Mage_Payment_Model_Config
|
| 793 |
+
*/
|
| 794 |
+
$config = Mage::getSingleton('payment/config');
|
| 795 |
+
|
| 796 |
+
// $types is an array in the format:
|
| 797 |
+
// array(
|
| 798 |
+
// 'VI' => 'Visa',
|
| 799 |
+
// )
|
| 800 |
+
$types = $config->getCcTypes();
|
| 801 |
+
|
| 802 |
+
$magentoTypeCodes = array();
|
| 803 |
+
$normalizedNames = array();
|
| 804 |
+
|
| 805 |
+
foreach($types as $code => $name) {
|
| 806 |
+
$magentoTypeCodes[] = $code;
|
| 807 |
+
$normalizedNames[] = strtolower(preg_replace('/[^\w\d]/', '', $name));
|
| 808 |
+
}
|
| 809 |
+
|
| 810 |
+
$map = array_combine($normalizedNames, $magentoTypeCodes);
|
| 811 |
+
$normalizedType = strtolower(preg_replace('/[^\w\d]/', '', $type));
|
| 812 |
|
| 813 |
+
if (isset($map[$normalizedType])) {
|
| 814 |
+
return $map[$normalizedType];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 815 |
}
|
| 816 |
|
| 817 |
+
return false;
|
| 818 |
}
|
| 819 |
|
| 820 |
private function _log($message)
|
app/code/community/PriceWaiter/NYPWidget/Model/Callback/Inventory.php
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
|
| 3 |
+
/**
|
| 4 |
+
* Manages decrementing inventory for orders written via PriceWaiter order callback.
|
| 5 |
+
*/
|
| 6 |
+
class PriceWaiter_NYPWidget_Model_Callback_Inventory
|
| 7 |
+
{
|
| 8 |
+
protected $_order = null;
|
| 9 |
+
|
| 10 |
+
public function __construct(Mage_Sales_Model_Order $order)
|
| 11 |
+
{
|
| 12 |
+
$this->_order = $order;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
/**
|
| 16 |
+
* @return Array An array in the format [ "product_id" => [ "qty" => quantity_ordered ] ].
|
| 17 |
+
*/
|
| 18 |
+
public function getProductsAndQuantities()
|
| 19 |
+
{
|
| 20 |
+
$items = $this->_order->getAllItems();
|
| 21 |
+
$result = array();
|
| 22 |
+
|
| 23 |
+
foreach($items as $item) {
|
| 24 |
+
$productId = $item->getProductId();
|
| 25 |
+
$result[$productId] = array('qty' => $item->getQtyOrdered());
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
return $result;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
/**
|
| 32 |
+
* Decrements inventory for items sold via PriceWaiter.
|
| 33 |
+
* @throws Mage_Core_Exception If there's not enough inventory to fill the order.
|
| 34 |
+
*/
|
| 35 |
+
public function registerPriceWaiterSale()
|
| 36 |
+
{
|
| 37 |
+
// This is adapted from code in Mage_CatalogInventory_Observer.
|
| 38 |
+
// The issue is that Magento's inventory code is quote-based, but we (currently) create orders directly.
|
| 39 |
+
|
| 40 |
+
// 1. Tell Mage_CatalogInventory_Model_Stock to decrement inventory.
|
| 41 |
+
// This will throw if there's not enough inventory to fill the order.
|
| 42 |
+
$stock = Mage::getSingleton('cataloginventory/stock');
|
| 43 |
+
$productQtys = $this->getProductsAndQuantities();
|
| 44 |
+
|
| 45 |
+
try
|
| 46 |
+
{
|
| 47 |
+
$stockItemsNeedingSave = $stock->registerProductsSale($productQtys);
|
| 48 |
+
}
|
| 49 |
+
catch (Mage_Core_Exception $ex)
|
| 50 |
+
{
|
| 51 |
+
// There's not really a great way to be *sure* this is the "not enough inventory" error
|
| 52 |
+
// without examining the (localizable) error message.
|
| 53 |
+
throw new PriceWaiter_NYPWidget_Exception_OutOfStock(
|
| 54 |
+
$ex->getMessage(),
|
| 55 |
+
0,
|
| 56 |
+
$ex
|
| 57 |
+
);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
// 2. If that resulted in items going out of stock, they need to be saved + reindexed.
|
| 61 |
+
// Again, this is adapted from Mage_CatalogInventory_Observer
|
| 62 |
+
|
| 63 |
+
$productIdsToIndex = array();
|
| 64 |
+
|
| 65 |
+
foreach ($stockItemsNeedingSave as $stockItem) {
|
| 66 |
+
$stockItem->save();
|
| 67 |
+
$productIds[] = $stockItem->getProductId();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
if ($productIdsToIndex) {
|
| 71 |
+
Mage::getResourceSingleton('catalog/product_indexer_price')->reindexProductIds($productIdsToIndex);
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
}
|
app/code/community/PriceWaiter/NYPWidget/Model/Carrier/ShippingMethod.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Model_Carrier_ShippingMethod
|
| 21 |
extends Mage_Shipping_Model_Carrier_Abstract
|
| 22 |
implements Mage_Shipping_Model_Carrier_Interface
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Model_Carrier_ShippingMethod
|
| 4 |
extends Mage_Shipping_Model_Carrier_Abstract
|
| 5 |
implements Mage_Shipping_Model_Carrier_Interface
|
app/code/community/PriceWaiter/NYPWidget/Model/Category.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Model_Category extends Mage_Core_Model_Abstract
|
| 21 |
{
|
| 22 |
public function _construct()
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Model_Category extends Mage_Core_Model_Abstract
|
| 4 |
{
|
| 5 |
public function _construct()
|
app/code/community/PriceWaiter/NYPWidget/Model/Display/Phrase.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Model_Display_Phrase
|
| 21 |
{
|
| 22 |
public function toOptionArray()
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Model_Display_Phrase
|
| 4 |
{
|
| 5 |
public function toOptionArray()
|
app/code/community/PriceWaiter/NYPWidget/Model/Display/Size.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Model_Display_Size
|
| 21 |
{
|
| 22 |
public function toOptionArray()
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Model_Display_Size
|
| 4 |
{
|
| 5 |
public function toOptionArray()
|
app/code/community/PriceWaiter/NYPWidget/Model/Mysql4/Category.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Model_Mysql4_Category extends Mage_Core_Model_Mysql4_Abstract
|
| 21 |
{
|
| 22 |
public function _construct()
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Model_Mysql4_Category extends Mage_Core_Model_Mysql4_Abstract
|
| 4 |
{
|
| 5 |
public function _construct()
|
app/code/community/PriceWaiter/NYPWidget/Model/Mysql4/Category/Collection.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Model_Mysql4_Category_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 21 |
{
|
| 22 |
public function _construct()
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Model_Mysql4_Category_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 4 |
{
|
| 5 |
public function _construct()
|
app/code/community/PriceWaiter/NYPWidget/Model/Mysql4/Order.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Model_Mysql4_Order extends Mage_Core_Model_Mysql4_Abstract
|
| 21 |
{
|
| 22 |
public function _construct()
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Model_Mysql4_Order extends Mage_Core_Model_Mysql4_Abstract
|
| 4 |
{
|
| 5 |
public function _construct()
|
app/code/community/PriceWaiter/NYPWidget/Model/Mysql4/Order/Collection.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Model_Mysql4_Order_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 21 |
{
|
| 22 |
public function _construct()
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Model_Mysql4_Order_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|
| 4 |
{
|
| 5 |
public function _construct()
|
app/code/community/PriceWaiter/NYPWidget/Model/Observer.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Model_Observer
|
| 21 |
{
|
| 22 |
// Adds the "PriceWaiter" tab to the "Manage Categories" page
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Model_Observer
|
| 4 |
{
|
| 5 |
// Adds the "PriceWaiter" tab to the "Manage Categories" page
|
app/code/community/PriceWaiter/NYPWidget/Model/Order.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Model_Order extends Mage_Core_Model_Abstract
|
| 21 |
{
|
| 22 |
public function _construct()
|
|
@@ -24,6 +7,27 @@ class PriceWaiter_NYPWidget_Model_Order extends Mage_Core_Model_Abstract
|
|
| 24 |
$this->_init('nypwidget/order', 'entity_id');
|
| 25 |
}
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
public function loadByPriceWaiterId($pricewaiterId)
|
| 28 |
{
|
| 29 |
if (is_null($pricewaiterId)) {
|
|
@@ -40,5 +44,4 @@ class PriceWaiter_NYPWidget_Model_Order extends Mage_Core_Model_Abstract
|
|
| 40 |
|
| 41 |
return $this;
|
| 42 |
}
|
| 43 |
-
|
| 44 |
}
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Model_Order extends Mage_Core_Model_Abstract
|
| 4 |
{
|
| 5 |
public function _construct()
|
| 7 |
$this->_init('nypwidget/order', 'entity_id');
|
| 8 |
}
|
| 9 |
|
| 10 |
+
/**
|
| 11 |
+
* @param String $orderId
|
| 12 |
+
* @return PriceWaiter_NYPWidget_Model_Order $this
|
| 13 |
+
*/
|
| 14 |
+
public function loadByMagentoOrderId($orderId)
|
| 15 |
+
{
|
| 16 |
+
$collection = Mage::getModel('nypwidget/order')
|
| 17 |
+
->getCollection()
|
| 18 |
+
->addFieldToFilter('order_id', $orderId);
|
| 19 |
+
|
| 20 |
+
if (count($collection)) {
|
| 21 |
+
$this->load($collection->getFirstItem()->getEntityId());
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
return $this;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
/**
|
| 28 |
+
* @param String $pricewaiterId
|
| 29 |
+
* @return PriceWaiter_NYPWidget_Model_Order $this
|
| 30 |
+
*/
|
| 31 |
public function loadByPriceWaiterId($pricewaiterId)
|
| 32 |
{
|
| 33 |
if (is_null($pricewaiterId)) {
|
| 44 |
|
| 45 |
return $this;
|
| 46 |
}
|
|
|
|
| 47 |
}
|
app/code/community/PriceWaiter/NYPWidget/Model/PaymentMethod.php
CHANGED
|
@@ -1,30 +1,19 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
|
| 4 |
-
*
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Model_PaymentMethod extends Mage_Payment_Model_Method_Abstract
|
| 21 |
{
|
| 22 |
protected $_code = 'nypwidget';
|
| 23 |
|
|
|
|
|
|
|
|
|
|
| 24 |
protected $_isGateway = false;
|
| 25 |
protected $_canOrder = true;
|
| 26 |
-
protected $_canAuthorize =
|
| 27 |
-
protected $_canCapture =
|
| 28 |
protected $_canCapturePartial = false;
|
| 29 |
protected $_canRefund = false;
|
| 30 |
protected $_canVoid = true;
|
|
@@ -32,8 +21,13 @@ class PriceWaiter_NYPWidget_Model_PaymentMethod extends Mage_Payment_Model_Metho
|
|
| 32 |
protected $_canUseCheckout = false;
|
| 33 |
protected $_canUseForMultishipping = false;
|
| 34 |
|
|
|
|
|
|
|
| 35 |
public function authorize(Varien_Object $payment, $amount)
|
| 36 |
{
|
|
|
|
|
|
|
|
|
|
| 37 |
return $this;
|
| 38 |
}
|
| 39 |
|
|
@@ -51,4 +45,83 @@ class PriceWaiter_NYPWidget_Model_PaymentMethod extends Mage_Payment_Model_Metho
|
|
| 51 |
{
|
| 52 |
return false;
|
| 53 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
}
|
| 1 |
<?php
|
| 2 |
|
| 3 |
+
/**
|
| 4 |
+
* PriceWaiter Payment method.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
*/
|
|
|
|
| 6 |
class PriceWaiter_NYPWidget_Model_PaymentMethod extends Mage_Payment_Model_Method_Abstract
|
| 7 |
{
|
| 8 |
protected $_code = 'nypwidget';
|
| 9 |
|
| 10 |
+
// Custom info block to display payment details on order in admin.
|
| 11 |
+
protected $_infoBlockType = 'nypwidget/payment_info_pricewaiter';
|
| 12 |
+
|
| 13 |
protected $_isGateway = false;
|
| 14 |
protected $_canOrder = true;
|
| 15 |
+
protected $_canAuthorize = true;
|
| 16 |
+
protected $_canCapture = true;
|
| 17 |
protected $_canCapturePartial = false;
|
| 18 |
protected $_canRefund = false;
|
| 19 |
protected $_canVoid = true;
|
| 21 |
protected $_canUseCheckout = false;
|
| 22 |
protected $_canUseForMultishipping = false;
|
| 23 |
|
| 24 |
+
private static $_currentOrderCallbackRequest = [];
|
| 25 |
+
|
| 26 |
public function authorize(Varien_Object $payment, $amount)
|
| 27 |
{
|
| 28 |
+
// Don't close transactions for auth-only.
|
| 29 |
+
$payment->setIsTransactionClosed(0);
|
| 30 |
+
|
| 31 |
return $this;
|
| 32 |
}
|
| 33 |
|
| 45 |
{
|
| 46 |
return false;
|
| 47 |
}
|
| 48 |
+
|
| 49 |
+
public function getConfigData($field, $storeId = null)
|
| 50 |
+
{
|
| 51 |
+
if ($field !== 'order_status') {
|
| 52 |
+
return parent::getConfigData($field, $storeId);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
if ($storeId === null) {
|
| 56 |
+
$storeId = $this->getStore();
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
$status = Mage::helper('nypwidget')->getDefaultOrderStatus($storeId);
|
| 60 |
+
return $status;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
public function getConfigPaymentAction()
|
| 64 |
+
{
|
| 65 |
+
// For test orders (which will be immediately canceled) we don't
|
| 66 |
+
// want to "capture" payment, since that removes our ability to cancel.
|
| 67 |
+
if ($this->isCurrentRequestTest()) {
|
| 68 |
+
return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// Detect auth-only transactions and, uh, only auth them.
|
| 72 |
+
if ($this->isCurrentRequestAuthorizeOnly()) {
|
| 73 |
+
return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE;
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
return Mage_Payment_Model_Method_Abstract::ACTION_AUTHORIZE_CAPTURE;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/**
|
| 80 |
+
* @return boolean Whether the current order callback request being processed is authorize only (no capture).
|
| 81 |
+
*/
|
| 82 |
+
protected function isCurrentRequestAuthorizeOnly()
|
| 83 |
+
{
|
| 84 |
+
$request = $this->getCurrentOrderCallbackRequest();
|
| 85 |
+
|
| 86 |
+
return (
|
| 87 |
+
is_array($request) &&
|
| 88 |
+
isset($request['transaction_type']) &&
|
| 89 |
+
strcasecmp($request['transaction_type'], 'auth') === 0
|
| 90 |
+
);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/**
|
| 94 |
+
* @return boolean Whether the current order callback request being processed is a test.
|
| 95 |
+
*/
|
| 96 |
+
protected function isCurrentRequestTest()
|
| 97 |
+
{
|
| 98 |
+
$request = $this->getCurrentOrderCallbackRequest();
|
| 99 |
+
return is_array($request) && !empty($request['test']);
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
/**
|
| 103 |
+
* @internal
|
| 104 |
+
*/
|
| 105 |
+
public static function resetCurrentOrderCallbackRequest()
|
| 106 |
+
{
|
| 107 |
+
self::$_currentOrderCallbackRequest = array();
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
/**
|
| 111 |
+
* @internal Hack to allow payment method access to incoming order data.
|
| 112 |
+
* @param Array $request
|
| 113 |
+
*/
|
| 114 |
+
public static function setCurrentOrderCallbackRequest(Array $request)
|
| 115 |
+
{
|
| 116 |
+
self::$_currentOrderCallbackRequest = $request;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
/**
|
| 120 |
+
* @internal
|
| 121 |
+
* @return Array
|
| 122 |
+
*/
|
| 123 |
+
protected function getCurrentOrderCallbackRequest()
|
| 124 |
+
{
|
| 125 |
+
return self::$_currentOrderCallbackRequest;
|
| 126 |
+
}
|
| 127 |
}
|
app/code/community/PriceWaiter/NYPWidget/Model/Resource/Eav/Mysql4/Setup.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup
|
| 21 |
{
|
| 22 |
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup
|
| 4 |
{
|
| 5 |
|
app/code/community/PriceWaiter/NYPWidget/controllers/Adminhtml/PricewaiterController.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_Adminhtml_PriceWaiterController extends Mage_Adminhtml_Controller_Action
|
| 21 |
{
|
| 22 |
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_Adminhtml_PriceWaiterController extends Mage_Adminhtml_Controller_Action
|
| 4 |
{
|
| 5 |
|
app/code/community/PriceWaiter/NYPWidget/controllers/CallbackController.php
CHANGED
|
@@ -1,55 +1,69 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_CallbackController extends Mage_Core_Controller_Front_Action
|
| 21 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
public function indexAction()
|
| 24 |
{
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
return;
|
| 28 |
}
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
try
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
$
|
| 41 |
-
Mage::getModel('nypwidget/callback')->processRequest($request);
|
| 42 |
-
} catch (Exception $e) {
|
| 43 |
-
Mage::logException($e);
|
| 44 |
-
$this->_log($e);
|
| 45 |
}
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
}
|
| 53 |
}
|
| 54 |
-
|
| 55 |
}
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_CallbackController extends Mage_Core_Controller_Front_Action
|
| 4 |
{
|
| 5 |
+
/**
|
| 6 |
+
* Header used to pass error messages back to PriceWaiter.
|
| 7 |
+
*/
|
| 8 |
+
const ERROR_MESSAGE_HEADER = 'X-Platform-Error';
|
| 9 |
+
|
| 10 |
+
/**
|
| 11 |
+
* Header used to pass error codes back to PriceWaiter.
|
| 12 |
+
*/
|
| 13 |
+
const ERROR_CODE_HEADER = 'X-Platform-Error-Code';
|
| 14 |
+
|
| 15 |
+
/**
|
| 16 |
+
* Header used to pass the generated order id back to PriceWaiter.
|
| 17 |
+
*/
|
| 18 |
+
const ORDER_ID_HEADER = 'X-Platform-Order-Id';
|
| 19 |
|
| 20 |
public function indexAction()
|
| 21 |
{
|
| 22 |
+
$httpRequest = $this->getRequest();
|
| 23 |
+
$httpResponse = $this->getResponse();
|
| 24 |
+
|
| 25 |
+
if (!$httpRequest->isPost()) {
|
| 26 |
+
// Pretend like this page isn't even *here*
|
| 27 |
+
$this->norouteAction();
|
| 28 |
return;
|
| 29 |
}
|
| 30 |
|
| 31 |
+
// Add debugging headers
|
| 32 |
+
Mage::helper('nypwidget')->setHeaders($httpResponse);
|
| 33 |
+
$pricewaiterId = '';
|
| 34 |
|
| 35 |
+
try
|
| 36 |
+
{
|
| 37 |
+
$data = $httpRequest->getPost();
|
| 38 |
+
|
| 39 |
+
$order = Mage::getModel('nypwidget/callback')
|
| 40 |
+
->processRequest($data);
|
| 41 |
+
|
| 42 |
+
// Success!
|
| 43 |
+
$httpResponse->setHeader(self::ORDER_ID_HEADER, $order->getIncrementId(), true);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
}
|
| 45 |
+
catch (Exception $ex)
|
| 46 |
+
{
|
| 47 |
+
// Augment duplicate order errors with the existing order id.
|
| 48 |
+
if ($ex instanceof PriceWaiter_NYPWidget_Exception_DuplicateOrder) {
|
| 49 |
+
$httpResponse->setHeader(self::ORDER_ID_HEADER, $ex->getExistingOrderId(), true);
|
| 50 |
+
}
|
| 51 |
|
| 52 |
+
if ($ex instanceof PriceWaiter_NYPWidget_Exception_Abstract) {
|
| 53 |
+
// These are normal errors indicating problems we've previously thought of
|
| 54 |
+
// occurring during error processing.
|
| 55 |
+
$httpResponse->setHttpResponseCode($ex->httpStatusCode);
|
| 56 |
+
|
| 57 |
+
if (!empty($ex->errorCode)) {
|
| 58 |
+
$httpResponse->setHeader(self::ERROR_CODE_HEADER, $ex->errorCode, true);
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
} else {
|
| 62 |
+
// These are not.
|
| 63 |
+
$httpResponse->setHttpResponseCode(500);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
$httpResponse->setHeader(self::ERROR_MESSAGE_HEADER, $ex->getMessage(), true);
|
| 67 |
}
|
| 68 |
}
|
|
|
|
| 69 |
}
|
app/code/community/PriceWaiter/NYPWidget/controllers/ProductinfoController.php
CHANGED
|
@@ -1,22 +1,5 @@
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
-
/*
|
| 4 |
-
* Copyright 2013-2015 Price Waiter, LLC
|
| 5 |
-
*
|
| 6 |
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
-
* you may not use this file except in compliance with the License.
|
| 8 |
-
* You may obtain a copy of the License at
|
| 9 |
-
*
|
| 10 |
-
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
-
*
|
| 12 |
-
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
-
* See the License for the specific language governing permissions and
|
| 16 |
-
* limitations under the License.
|
| 17 |
-
*
|
| 18 |
-
*/
|
| 19 |
-
|
| 20 |
class PriceWaiter_NYPWidget_ProductinfoController extends Mage_Core_Controller_Front_Action
|
| 21 |
{
|
| 22 |
public function indexAction()
|
|
@@ -44,6 +27,12 @@ class PriceWaiter_NYPWidget_ProductinfoController extends Mage_Core_Controller_F
|
|
| 44 |
$productConfiguration = array();
|
| 45 |
parse_str(urldecode($postFields['_magento_product_configuration']), $productConfiguration);
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
// Create a cart and add the product to it
|
| 48 |
// This is necessary to make Magento calculate the cost of the item in the correct context.
|
| 49 |
try {
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
class PriceWaiter_NYPWidget_ProductinfoController extends Mage_Core_Controller_Front_Action
|
| 4 |
{
|
| 5 |
public function indexAction()
|
| 27 |
$productConfiguration = array();
|
| 28 |
parse_str(urldecode($postFields['_magento_product_configuration']), $productConfiguration);
|
| 29 |
|
| 30 |
+
// always lookup the product with a low quantity
|
| 31 |
+
// the below code will fail if the product is out of stock
|
| 32 |
+
if ($productConfiguration && isset($productConfiguration['qty'])) {
|
| 33 |
+
$productConfiguration['qty'] = 1;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
// Create a cart and add the product to it
|
| 37 |
// This is necessary to make Magento calculate the cost of the item in the correct context.
|
| 38 |
try {
|
app/code/community/PriceWaiter/NYPWidget/etc/adminhtml.xml
CHANGED
|
@@ -1,19 +1,4 @@
|
|
| 1 |
<?xml version="1.0" encoding="utf-8"?>
|
| 2 |
-
<!--
|
| 3 |
-
Copyright 2013-2015 Price Waiter, LLC
|
| 4 |
-
|
| 5 |
-
Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
-
you may not use this file except in compliance with the License.
|
| 7 |
-
You may obtain a copy of the License at
|
| 8 |
-
|
| 9 |
-
http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
-
|
| 11 |
-
Unless required by applicable law or agreed to in writing, software
|
| 12 |
-
distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
-
See the License for the specific language governing permissions and
|
| 15 |
-
limitations under the License.
|
| 16 |
-
-->
|
| 17 |
<config>
|
| 18 |
<acl>
|
| 19 |
<resources>
|
| 1 |
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
<config>
|
| 3 |
<acl>
|
| 4 |
<resources>
|
app/code/community/PriceWaiter/NYPWidget/etc/config.xml
CHANGED
|
@@ -1,24 +1,9 @@
|
|
| 1 |
<?xml version="1.0" encoding="utf-8"?>
|
| 2 |
-
<!--
|
| 3 |
-
Copyright 2013-2015 Price Waiter, LLC
|
| 4 |
-
|
| 5 |
-
Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
-
you may not use this file except in compliance with the License.
|
| 7 |
-
You may obtain a copy of the License at
|
| 8 |
-
|
| 9 |
-
http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
-
|
| 11 |
-
Unless required by applicable law or agreed to in writing, software
|
| 12 |
-
distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
-
See the License for the specific language governing permissions and
|
| 15 |
-
limitations under the License.
|
| 16 |
-
-->
|
| 17 |
<config>
|
| 18 |
|
| 19 |
<modules>
|
| 20 |
<PriceWaiter_NYPWidget>
|
| 21 |
-
<version>2.
|
| 22 |
</PriceWaiter_NYPWidget>
|
| 23 |
</modules>
|
| 24 |
|
|
@@ -147,8 +132,11 @@
|
|
| 147 |
<pricewaiter>
|
| 148 |
<configuration>
|
| 149 |
<enabled>0</enabled>
|
| 150 |
-
<log>1</log>
|
| 151 |
</configuration>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
<customer_groups>
|
| 153 |
<disable>0</disable>
|
| 154 |
<group_select>0</group_select>
|
|
@@ -177,7 +165,6 @@
|
|
| 177 |
<model>nypwidget/paymentMethod</model>
|
| 178 |
<order_status>pricewaiter_processing</order_status>
|
| 179 |
<title>PriceWaiter Payment</title>
|
| 180 |
-
<payment_action>authorize</payment_action>
|
| 181 |
<allowspecific>0</allowspecific>
|
| 182 |
</nypwidget>
|
| 183 |
</payment>
|
| 1 |
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
<config>
|
| 3 |
|
| 4 |
<modules>
|
| 5 |
<PriceWaiter_NYPWidget>
|
| 6 |
+
<version>2.5.0</version>
|
| 7 |
</PriceWaiter_NYPWidget>
|
| 8 |
</modules>
|
| 9 |
|
| 132 |
<pricewaiter>
|
| 133 |
<configuration>
|
| 134 |
<enabled>0</enabled>
|
|
|
|
| 135 |
</configuration>
|
| 136 |
+
<orders>
|
| 137 |
+
<default_status>processing</default_status>
|
| 138 |
+
<log>1</log>
|
| 139 |
+
</orders>
|
| 140 |
<customer_groups>
|
| 141 |
<disable>0</disable>
|
| 142 |
<group_select>0</group_select>
|
| 165 |
<model>nypwidget/paymentMethod</model>
|
| 166 |
<order_status>pricewaiter_processing</order_status>
|
| 167 |
<title>PriceWaiter Payment</title>
|
|
|
|
| 168 |
<allowspecific>0</allowspecific>
|
| 169 |
</nypwidget>
|
| 170 |
</payment>
|
app/code/community/PriceWaiter/NYPWidget/etc/system.xml
CHANGED
|
@@ -1,19 +1,4 @@
|
|
| 1 |
<?xml version="1.0" encoding="utf-8"?>
|
| 2 |
-
<!--
|
| 3 |
-
Copyright 2013-2015 Price Waiter, LLC
|
| 4 |
-
|
| 5 |
-
Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
-
you may not use this file except in compliance with the License.
|
| 7 |
-
You may obtain a copy of the License at
|
| 8 |
-
|
| 9 |
-
http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
-
|
| 11 |
-
Unless required by applicable law or agreed to in writing, software
|
| 12 |
-
distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
-
See the License for the specific language governing permissions and
|
| 15 |
-
limitations under the License.
|
| 16 |
-
-->
|
| 17 |
<config>
|
| 18 |
<sections>
|
| 19 |
<pricewaiter>
|
|
@@ -111,8 +96,31 @@
|
|
| 111 |
<show_in_website>1</show_in_website>
|
| 112 |
<show_in_store>1</show_in_store>
|
| 113 |
</api_secret>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
<log translate="label comment">
|
| 115 |
-
<label>Log
|
| 116 |
<comment>
|
| 117 |
<![CDATA[Log information about order
|
| 118 |
notifications from PriceWaiter. For
|
|
@@ -128,7 +136,7 @@
|
|
| 128 |
<show_in_store>1</show_in_store>
|
| 129 |
</log>
|
| 130 |
</fields>
|
| 131 |
-
</
|
| 132 |
<customer_groups translate="label">
|
| 133 |
<label>Disable button by Customer Groups</label>
|
| 134 |
<frontend_type>text</frontend_type>
|
| 1 |
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
<config>
|
| 3 |
<sections>
|
| 4 |
<pricewaiter>
|
| 96 |
<show_in_website>1</show_in_website>
|
| 97 |
<show_in_store>1</show_in_store>
|
| 98 |
</api_secret>
|
| 99 |
+
</fields>
|
| 100 |
+
</configuration>
|
| 101 |
+
<orders translate="label">
|
| 102 |
+
<label>Orders</label>
|
| 103 |
+
<frontend_type>text</frontend_type>
|
| 104 |
+
<sort_order>2</sort_order>
|
| 105 |
+
<show_in_default>1</show_in_default>
|
| 106 |
+
<show_in_website>1</show_in_website>
|
| 107 |
+
<show_in_store>1</show_in_store>
|
| 108 |
+
<expanded>1</expanded>
|
| 109 |
+
<fields>
|
| 110 |
+
<default_status translate="label comment">
|
| 111 |
+
<label>Status for Incoming Orders</label>
|
| 112 |
+
<comment>
|
| 113 |
+
<![CDATA[Orders from PriceWaiter will be given this status when they first enter the system.]]>
|
| 114 |
+
</comment>
|
| 115 |
+
<frontend_type>select</frontend_type>
|
| 116 |
+
<source_model>adminhtml/system_config_source_order_status</source_model>
|
| 117 |
+
<sort_order>10</sort_order>
|
| 118 |
+
<show_in_default>1</show_in_default>
|
| 119 |
+
<show_in_website>1</show_in_website>
|
| 120 |
+
<show_in_store>1</show_in_store>
|
| 121 |
+
</default_status>
|
| 122 |
<log translate="label comment">
|
| 123 |
+
<label>Log Incoming Orders</label>
|
| 124 |
<comment>
|
| 125 |
<