From 7808d2e2e1f6ead9461c7bfc536161ee2ad186aa Mon Sep 17 00:00:00 2001 From: Mathias Arlaud Date: Wed, 13 Mar 2019 17:45:01 +0100 Subject: [PATCH 01/14] WIP --- .../Mapper/AbstractMapper.php | 65 +++++++++++++++ .../Mapper/AddressMapper.php | 83 +++++++++++++++++++ .../Mapper/CustomerMapper.php | 61 ++++++++++++++ .../Mapper/OrderItemMapper.php | 46 ++++++++++ .../Mapper/OrderMapper.php | 75 +++++++++++++++++ .../Mapper/PaymentMapper.php | 46 ++++++++++ .../Mapper/StockMapper.php | 50 +++++++++++ .../controllers/AbstractController.php | 3 +- .../controllers/StockController.php | 8 +- .../controllers/UserController.php | 79 ++++-------------- 10 files changed, 447 insertions(+), 69 deletions(-) create mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/AbstractMapper.php create mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/AddressMapper.php create mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/CustomerMapper.php create mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/OrderItemMapper.php create mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/OrderMapper.php create mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/PaymentMapper.php create mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/StockMapper.php diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/AbstractMapper.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/AbstractMapper.php new file mode 100644 index 0000000..b7e4932 --- /dev/null +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/AbstractMapper.php @@ -0,0 +1,65 @@ + + * @copyright Copyright (C) 2019 + * @license MIT License + */ +abstract class AbstractMapper +{ + /** + * Get and process Dto from entity + * + * @param Varien_Object $entity + * + * @return array + */ + final public function toDto($entity) + { + $dto = $this->getDto($entity); + $blacklist = $this->getBlacklist(); + $toIntList = $this->getAttributesToCastInt(); + + foreach ($dto as $key => $value) { + if ($blacklist && in_array($key, $blacklist)) { + unset ($dto[$key]); + } else { + if (strstr($key, 'is_') || strstr($key, 'has_') || strstr($key, 'use_') || strstr($key, 'enable_')) { + $dto[$key] = boolval($value); + } + } + + if ($toIntList && in_array($key, $toIntList)) { + $dto[$key] = $dto[$key] != null ? intval($dto[$key]) : null; + } + } + + return $dto; + } + + /** + * Get Dto from entity + * + * @param Varien_Object $entity + * + * @return array + */ + abstract protected function getDto($entity); + + /** + * Get Dto attribute blacklist + * + * @return array + */ + abstract protected function getBlacklist(); + + /** + * Get attribute list to cast to integer + * + * @return array + */ + abstract protected function getAttributesToCastInt(); +} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/AddressMapper.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/AddressMapper.php new file mode 100644 index 0000000..8f72273 --- /dev/null +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/AddressMapper.php @@ -0,0 +1,83 @@ + + * @copyright Copyright (C) 2019 + * @license MIT License + */ +class AddressMapper extends AbstractMapper +{ + /** + * Get AddressDto from Address + * + * @param Mage_Customer_Model_Address $address + * @return array + */ + protected function getDto($address) + { + $addressDto = $address->getData(); + + $addressDto['id'] = $addressDto['entity_id']; + + $region = null; + if (isset($addressDto['region'])) { + $region = $addressDto['region']; + } + + $addressDto['region'] = ['region' => $region]; + + $streetDto = explode("\n", $addressDto['street']); + if(count($streetDto) < 2) + $streetDto[]=''; + + $addressDto['street'] = $streetDto; + if(!$addressDto['firstname']) + $addressDto['firstname'] = $customerDto['firstname']; + + if(!$addressDto['lastname']) + $addressDto['lastname'] = $customerDto['lastname']; + + if(!$addressDto['city']) + $addressDto['city'] = ''; + + if(!$addressDto['country_id']) + $addressDto['country_id'] = 'US'; + + if(!$addressDto['postcode']) + $addressDto['postcode'] = ''; + + if(!$addressDto['telephone']) + $addressDto['telephone'] = ''; + + return $addressDto; + } + + /** + * @inheritdoc + */ + protected function getBlacklist() + { + return []; + } + + /** + * @inheritdoc + */ + protected function getAttributesToCastInt() + { + return [ + 'id', + 'entity_id', + 'entity_type_id', + 'attribute_set_id', + 'increment_id', + 'parent_id', + 'customer_id' + ]; + } +} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/CustomerMapper.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/CustomerMapper.php new file mode 100644 index 0000000..e975789 --- /dev/null +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/CustomerMapper.php @@ -0,0 +1,61 @@ + + * @copyright Copyright (C) 2019 + * @license MIT License + */ +class CustomerMapper extends AbstractMapper +{ + /** + * Get CustomerDto from Customer + * + * @param Mage_Customer_Model_Customer $customer + * @return array + */ + protected function getDto($customer) + { + $customerDto = $customer->getData(); + + $customerDto['disable_auto_group_change'] = boolval($customerDto['disable_auto_group_change']); + $customerDto['id'] = $customerDto['entity_id']; + + return $customerDto; + } + + /** + * @inheritdoc + */ + protected function getBlacklist() + { + return [ + 'password', + 'password_hash', + 'password_confirmation', + 'password_created_at', + 'confirmation', + 'entity_type_id' + ]; + } + + /** + * @inheritdoc + */ + protected function getAttributesToCastInt() + { + return [ + 'id', + 'entity_id', + 'attribute_set_id', + 'website_id', + 'group_id', + 'increment_id', + 'store_id', + ]; + } +} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/OrderItemMapper.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/OrderItemMapper.php new file mode 100644 index 0000000..cad986b --- /dev/null +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/OrderItemMapper.php @@ -0,0 +1,46 @@ + + * @copyright Copyright (C) 2019 + * @license MIT License + */ +class OrderItemMapper extends AbstractMapper +{ + /** + * Get OrderItemDto from OrderItem + * + * @param Mage_Sales_Model_Order_Item $orderItem + * @return array + */ + protected function getDto($orderItem) + { + $orderItemDto = $orderItem->getData(); + $orderItemDto['id'] = $orderItemDto['item_id']; + + return $orderItemDto; + } + + /** + * @inheritdoc + */ + protected function getBlacklist() + { + return []; + } + + /** + * @inheritdoc + */ + protected function getAttributesToCastInt() + { + return [ + 'entity_id' + ]; + } +} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/OrderMapper.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/OrderMapper.php new file mode 100644 index 0000000..8a8ee11 --- /dev/null +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/OrderMapper.php @@ -0,0 +1,75 @@ + + * @copyright Copyright (C) 2019 + * @license MIT License + */ +class OrderMapper extends AbstractMapper +{ + /** + * Get OrderDto from Order + * + * @param Mage_Sales_Model_Order $order + * @return array + */ + protected function getDto($order) + { + $orderDto = $order->getData(); + $orderDto['id'] = $orderDto['entity_id']; + $orderDto['items'] = []; + + /** @var Mage_Catalog_Model_Resource_Product $resourceModel */ + $resourceModel = Mage::getResourceModel('catalog/product'); + + $orderItemMapper = new OrderItemMapper(); + foreach($order->getAllVisibleItems() as $item) { + $itemDto = $orderItemMapper->toDto($item); + $itemDto['thumbnail'] = null; + + $image = $resourceModel->getAttributeRawValue( + $item->getProductId(), + 'thumbnail', + $order->getStoreId() + ); + + if ($image) { + $itemDto['thumbnail'] = $image; + } + + $orderDto['items'][] = $itemDto; + } + + $paymentMapper = new PaymentMapper(); + $payment = $order->getPayment(); + $paymentDto = $paymentMapper->toDto($payment); + $orderDto['payment'] = $paymentDto; + + return $orderDto; + } + + /** + * @inheritdoc + */ + protected function getBlacklist() + { + return []; + } + + /** + * @inheritdoc + */ + protected function getAttributesToCastInt() + { + return [ + 'entity_id' + ]; + } +} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/PaymentMapper.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/PaymentMapper.php new file mode 100644 index 0000000..9da2c71 --- /dev/null +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/PaymentMapper.php @@ -0,0 +1,46 @@ + + * @copyright Copyright (C) 2019 + * @license MIT License + */ +class PaymentMapper extends AbstractMapper +{ + /** + * Get PaymentDto from Payment + * + * @param Mage_Sales_Model_Order_Payment $payment + * @return array + */ + protected function getDto($payment) + { + $paymentDto = $payment->getData(); + $paymentDto['method_title'] = $payment->getMethodInstance()->getTitle(); + + return $paymentDto; + } + + /** + * @inheritdoc + */ + protected function getBlacklist() + { + return []; + } + + /** + * @inheritdoc + */ + protected function getAttributesToCastInt() + { + return [ + 'entity_id' + ]; + } +} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/StockMapper.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/StockMapper.php new file mode 100644 index 0000000..4897095 --- /dev/null +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/StockMapper.php @@ -0,0 +1,50 @@ + + * @copyright Copyright (C) 2019 + * @license MIT License + */ +class StockMapper extends AbstractMapper +{ + /** + * Get StockDto from StockItem + * + * @param Mage_CatalogInventory_Model_Stock_Item $stock + * + * @return array + */ + protected function getDto($stock) + { + $stockDto = $stock->getData(); + + $stockDto['stock_status_changed_auto'] = boolval($stockDto['stock_status_changed_auto']); + $stockDto['stock_status_changed_automatically'] = boolval($stockDto['stock_status_changed_automatically']); + $stockDto['notify_stock_qty'] = $stock->getNotifyStockQty(); + + return $stockDto; + } + + /** + * @inheritdoc + */ + protected function getBlacklist() + { + return []; + } + + /** + * @inheritdoc + */ + protected function getAttributesToCastInt() + { + return [ + 'entity_id' + ]; + } +} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/AbstractController.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/AbstractController.php index ee7872f..6b5e374 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/AbstractController.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/AbstractController.php @@ -258,8 +258,7 @@ protected function _result($code, $result) [ 'code' => $code, 'result' => $result, - ], - JSON_NUMERIC_CHECK + ] ) )->setHttpResponseCode($code)->setHeader('Content-Type', 'application/json'); } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/StockController.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/StockController.php index a333005..bcfad4b 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/StockController.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/StockController.php @@ -1,6 +1,7 @@ getIdBySku($sku); $product = Mage::getModel('catalog/product')->load($product_id); $stock = $product->getStockItem(); - $stockDTO = $stock->getData(); - $stockDTO['is_in_stock'] = boolval($stockDTO['is_in_stock']); - $stockDTO['notify_stock_qty'] = $stock->getNotifyStockQty(); + $stockMapper = new StockMapper(); + $stockDto = $stockMapper->toDto($product->getStockItem()); - return $this->_result(200, $stockDTO); + return $this->_result(200, $stockDto); } catch (Exception $err) { return $this->_result(500, $err->getMessage()); } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php index 5c0790d..1c834a8 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php @@ -1,6 +1,9 @@ setOrder('created_at', 'desc'); $ordersDTO = []; - /** @var Mage_Catalog_Model_Resource_Product $resourceModel */ - $resourceModel = Mage::getResourceModel('catalog/product'); - + $orderMapper = new OrderMapper(); + /** @var Mage_Sales_Model_Order $order */ foreach ($orderCollection as $order) { - $orderDTO = $order->getData(); - $orderDTO['id'] = $orderDTO['entity_id']; - $orderDTO['items'] = []; - - foreach($order->getAllVisibleItems() as $item) { - $itemDTO = $item->getData(); - $itemDTO['id'] = $itemDTO['item_id']; - $itemDTO['thumbnail'] = null; - - $image = $resourceModel->getAttributeRawValue( - $item->getProductId(), - 'thumbnail', - $order->getStoreId() - ); - - if ($image) { - $itemDTO['thumbnail'] = $image; - } - - $orderDTO['items'][] = $itemDTO; - } - - $payment = $order->getPayment(); - $orderDTO['payment'] = $payment->toArray(); - $orderDTO['payment']['method_title'] = $payment->getMethodInstance()->getTitle(); + $orderDTO = $orderMapper->toDto($order); $ordersDTO[] = $orderDTO; } @@ -266,9 +244,10 @@ public function createAction() try{ $customer->save(); - $filteredCustomerData = $this->_filterDTO($customer->getData(), array('password', 'password_hash', 'password_confirmation', 'confirmation', 'entity_type_id')); + $customerMapper = new CustomerMapper(); + $customerDto = $customerMapper->toDto($customer); - return $this->_result(200, $filteredCustomerData); // TODO: add support for 'Refresh-token' + return $this->_result(200, $customerDto); // TODO: add support for 'Refresh-token' } catch (Exception $e) { return $this->_result(500, $e->getMessage()); } @@ -336,7 +315,9 @@ public function meAction(){ } } $customer->load($customer->getId()); - $customerDTO = $customer->getData(); + $customerMapper = new CustomerMapper(); + $customerDTO = $customerMapper->toDto($customer); + $subscription = Mage::getModel('newsletter/subscriber')->loadByCustomer($customer); $customerDTO['is_subscribed'] = $subscription->isSubscribed(); @@ -344,36 +325,10 @@ public function meAction(){ $defaultBilling = $customer->getDefaultBilling(); $defaultShipping = $customer->getDefaultShipping(); $customerDTO['addresses'] = array(); + $addressMapper = new AddressMapper(); foreach ($allAddress as $address) { - $addressDTO = $address->getData(); - $addressDTO['id'] = $addressDTO['entity_id']; - - $region = null; - - if (isset($addressDTO['region'])) { - $region = $addressDTO['region']; - } - - $addressDTO['region'] = ['region' => $region]; - - $streetDTO = explode("\n", $addressDTO['street']); - if(count($streetDTO) < 2) - $streetDTO[]=''; - - $addressDTO['street'] = $streetDTO; - if(!$addressDTO['firstname']) - $addressDTO['firstname'] = $customerDTO['firstname']; - if(!$addressDTO['lastname']) - $addressDTO['lastname'] = $customerDTO['lastname']; - if(!$addressDTO['city']) - $addressDTO['city'] = ''; - if(!$addressDTO['country_id']) - $addressDTO['country_id'] = 'US'; - if(!$addressDTO['postcode']) - $addressDTO['postcode'] = ''; - if(!$addressDTO['telephone']) - $addressDTO['telephone'] = ''; + $addressDTO = $addressMapper->toDto($address); if($defaultBilling == $address->getId() || $address->getId() == $updatedBillingId) { // TODO: Street + Region fields (region_code should be) @@ -388,11 +343,9 @@ public function meAction(){ $customerDTO['default_shipping'] = $address->getId(); $customerDTO['addresses'][] = $addressDTO; } - $customerDTO['id'] = $customerDTO['entity_id']; } - - $filteredCustomerData = $this->_filterDTO($customerDTO, array('password', 'password_hash', 'password_confirmation', 'confirmation', 'entity_type_id')); - return $this->_result(200, $filteredCustomerData); + + return $this->_result(200, $customerDTO); } catch (Exception $err) { return $this->_result(500, $err->getMessage()); } From 6f7b15689790abe8dcd684e0a2dfb26e06642eac Mon Sep 17 00:00:00 2001 From: Mathias Arlaud Date: Tue, 23 Apr 2019 11:14:31 +0200 Subject: [PATCH 02/14] Set mappers as helpers --- .../Mapper/Abstract.php} | 2 +- .../Mapper/Address.php} | 24 ++++++---- .../Mapper/Customer.php} | 3 +- .../Mapper/Order.php} | 14 ++---- .../Mapper/OrderItem.php} | 3 +- .../Helper/Mapper/Payment.php | 45 +++++++++++++++++++ .../{ => Helper}/Mapper/PaymentMapper.php | 3 +- .../Mapper/Stock.php} | 3 +- .../controllers/StockController.php | 6 +-- .../controllers/UserController.php | 25 ++++------- .../VueStorefrontBridge/etc/config.xml | 3 ++ 11 files changed, 82 insertions(+), 49 deletions(-) rename magento1-module/app/code/local/Divante/VueStorefrontBridge/{Mapper/AbstractMapper.php => Helper/Mapper/Abstract.php} (93%) rename magento1-module/app/code/local/Divante/VueStorefrontBridge/{Mapper/AddressMapper.php => Helper/Mapper/Address.php} (77%) rename magento1-module/app/code/local/Divante/VueStorefrontBridge/{Mapper/CustomerMapper.php => Helper/Mapper/Customer.php} (91%) rename magento1-module/app/code/local/Divante/VueStorefrontBridge/{Mapper/OrderMapper.php => Helper/Mapper/Order.php} (75%) rename magento1-module/app/code/local/Divante/VueStorefrontBridge/{Mapper/OrderItemMapper.php => Helper/Mapper/OrderItem.php} (87%) create mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Payment.php rename magento1-module/app/code/local/Divante/VueStorefrontBridge/{ => Helper}/Mapper/PaymentMapper.php (87%) rename magento1-module/app/code/local/Divante/VueStorefrontBridge/{Mapper/StockMapper.php => Helper/Mapper/Stock.php} (90%) diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/AbstractMapper.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php similarity index 93% rename from magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/AbstractMapper.php rename to magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php index b7e4932..064ce4f 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/AbstractMapper.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php @@ -8,7 +8,7 @@ * @copyright Copyright (C) 2019 * @license MIT License */ -abstract class AbstractMapper +abstract class Divante_VueStorefrontBridge_Helper_Mapper_Abstract extends Mage_Core_Helper_Abstract { /** * Get and process Dto from entity diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/AddressMapper.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php similarity index 77% rename from magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/AddressMapper.php rename to magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php index 8f72273..9fef2b9 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/AddressMapper.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php @@ -1,5 +1,4 @@ $region]; $streetDto = explode("\n", $addressDto['street']); - if(count($streetDto) < 2) + if (count($streetDto) < 2) { $streetDto[]=''; + } $addressDto['street'] = $streetDto; - if(!$addressDto['firstname']) + if (!$addressDto['firstname']) { $addressDto['firstname'] = $customerDto['firstname']; + } - if(!$addressDto['lastname']) + if (!$addressDto['lastname']) { $addressDto['lastname'] = $customerDto['lastname']; + } - if(!$addressDto['city']) + if (!$addressDto['city']) { $addressDto['city'] = ''; + } - if(!$addressDto['country_id']) + if (!$addressDto['country_id']) { $addressDto['country_id'] = 'US'; + } - if(!$addressDto['postcode']) + if (!$addressDto['postcode']) { $addressDto['postcode'] = ''; + } - if(!$addressDto['telephone']) + if (!$addressDto['telephone']) { $addressDto['telephone'] = ''; + } return $addressDto; } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/CustomerMapper.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Customer.php similarity index 91% rename from magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/CustomerMapper.php rename to magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Customer.php index e975789..733cf7e 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/CustomerMapper.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Customer.php @@ -1,5 +1,4 @@ getAllVisibleItems() as $item) { - $itemDto = $orderItemMapper->toDto($item); + foreach ($order->getAllVisibleItems() as $item) { + $itemDto = Mage::helper('vsbridge_mapper/orderitem')->toDto($item); $itemDto['thumbnail'] = null; $image = $resourceModel->getAttributeRawValue( @@ -47,9 +43,7 @@ protected function getDto($order) $orderDto['items'][] = $itemDto; } - $paymentMapper = new PaymentMapper(); - $payment = $order->getPayment(); - $paymentDto = $paymentMapper->toDto($payment); + $paymentDto = Mage::helper('vsbridge_mapper/payment')->toDto($order->getPayment()); $orderDto['payment'] = $paymentDto; return $orderDto; diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/OrderItemMapper.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php similarity index 87% rename from magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/OrderItemMapper.php rename to magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php index cad986b..6363a78 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/OrderItemMapper.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php @@ -1,5 +1,4 @@ + * @copyright Copyright (C) 2019 + * @license MIT License + */ +class Divante_VueStorefrontBridge_Helper_Mapper_Payment extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract +{ + /** + * Get PaymentDto from Payment + * + * @param Mage_Sales_Model_Order_Payment $payment + * @return array + */ + protected function getDto($payment) + { + $paymentDto = $payment->getData(); + $paymentDto['method_title'] = $payment->getMethodInstance()->getTitle(); + + return $paymentDto; + } + + /** + * @inheritdoc + */ + protected function getBlacklist() + { + return []; + } + + /** + * @inheritdoc + */ + protected function getAttributesToCastInt() + { + return [ + 'entity_id' + ]; + } +} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/PaymentMapper.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/PaymentMapper.php similarity index 87% rename from magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/PaymentMapper.php rename to magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/PaymentMapper.php index 9da2c71..e634bba 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Mapper/PaymentMapper.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/PaymentMapper.php @@ -1,5 +1,4 @@ getIdBySku($sku); $product = Mage::getModel('catalog/product')->load($product_id); $stock = $product->getStockItem(); - $stockMapper = new StockMapper(); - $stockDto = $stockMapper->toDto($product->getStockItem()); + $stockDto = Mage::helper('vsbridge_mapper/stock')->toDto($product->getStockItem()); return $this->_result(200, $stockDto); } catch (Exception $err) { diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php index 1c834a8..05b959a 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php @@ -1,9 +1,6 @@ setWebsiteId(Mage::app()->getStore()->getWebsiteId()) - ->loadByEmail($request->email); + ->setWebsiteId(Mage::app()->getStore()->getWebsiteId()) + ->loadByEmail($request->email); if ($customer->getId()) { $customer->sendPasswordResetConfirmationEmail(); @@ -197,11 +194,10 @@ public function orderHistoryAction() ->setOrder('created_at', 'desc'); $ordersDTO = []; - $orderMapper = new OrderMapper(); /** @var Mage_Sales_Model_Order $order */ foreach ($orderCollection as $order) { - $orderDTO = $orderMapper->toDto($order); + $orderDTO = Mage::helper('vsbridge_mapper/order')->toDto($order); $ordersDTO[] = $orderDTO; } @@ -242,10 +238,9 @@ public function createAction() ->setEmail($request->customer->email) ->setPassword($request->password); - try{ + try { $customer->save(); - $customerMapper = new CustomerMapper(); - $customerDto = $customerMapper->toDto($customer); + $customerDto = Mage::helper('vsbridge_mapper/customer')->toDto($customer); return $this->_result(200, $customerDto); // TODO: add support for 'Refresh-token' } catch (Exception $e) { @@ -274,8 +269,8 @@ public function meAction(){ $updatedCustomer['entity_id'] = $customer->getId(); $customer->setData('firstname', $updatedCustomer['firstname']) - ->setData('lastname', $updatedCustomer['lastname']) - ->setData('email', $updatedCustomer['email']); + ->setData('lastname', $updatedCustomer['lastname']) + ->setData('email', $updatedCustomer['email']); if (isset($updatedCustomer['dob'])) { $customer->setData('dob', $updatedCustomer['dob']); @@ -315,8 +310,7 @@ public function meAction(){ } } $customer->load($customer->getId()); - $customerMapper = new CustomerMapper(); - $customerDTO = $customerMapper->toDto($customer); + $customerDTO = Mage::helper('vsbridge_mapper/customer')->toDto($customer); $subscription = Mage::getModel('newsletter/subscriber')->loadByCustomer($customer); $customerDTO['is_subscribed'] = $subscription->isSubscribed(); @@ -325,10 +319,9 @@ public function meAction(){ $defaultBilling = $customer->getDefaultBilling(); $defaultShipping = $customer->getDefaultShipping(); $customerDTO['addresses'] = array(); - $addressMapper = new AddressMapper(); foreach ($allAddress as $address) { - $addressDTO = $addressMapper->toDto($address); + $addressDTO = Mage::helper('vsbridge_mapper/address')->toDto($address); if($defaultBilling == $address->getId() || $address->getId() == $updatedBillingId) { // TODO: Street + Region fields (region_code should be) diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/etc/config.xml b/magento1-module/app/code/local/Divante/VueStorefrontBridge/etc/config.xml index 5fbb7bb..3d84656 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/etc/config.xml +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/etc/config.xml @@ -26,6 +26,9 @@ Divante_VueStorefrontBridge_Helper + + Divante_VueStorefrontBridge_Helper_Mapper + From 84fc746fb79ef058e50eb6b79d1a6217d65e990d Mon Sep 17 00:00:00 2001 From: Mathias Arlaud Date: Tue, 23 Apr 2019 14:49:33 +0200 Subject: [PATCH 03/14] Update user controller --- .../Helper/Mapper/Abstract.php | 70 ++++++++-- .../Helper/Mapper/Address.php | 71 +--------- .../Helper/Mapper/Customer.php | 25 +--- .../Helper/Mapper/Order.php | 50 ++----- .../Helper/Mapper/OrderItem.php | 31 ----- .../Helper/Mapper/Payment.php | 31 ----- .../Helper/Mapper/PaymentMapper.php | 45 ------- .../Helper/Mapper/Stock.php | 31 +---- .../controllers/UserController.php | 123 ++++++++++++++---- 9 files changed, 168 insertions(+), 309 deletions(-) delete mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/PaymentMapper.php diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php index 064ce4f..7d13142 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php @@ -13,53 +13,95 @@ abstract class Divante_VueStorefrontBridge_Helper_Mapper_Abstract extends Mage_C /** * Get and process Dto from entity * - * @param Varien_Object $entity + * @param array $initialDto * * @return array */ - final public function toDto($entity) + final public function filterDto($initialDto) { - $dto = $this->getDto($entity); - $blacklist = $this->getBlacklist(); - $toIntList = $this->getAttributesToCastInt(); + $dto = $this->customDtoFiltering($initialDto); + $blacklist = $this->getBlacklist(); foreach ($dto as $key => $value) { if ($blacklist && in_array($key, $blacklist)) { - unset ($dto[$key]); + unset($dto[$key]); } else { - if (strstr($key, 'is_') || strstr($key, 'has_') || strstr($key, 'use_') || strstr($key, 'enable_')) { - $dto[$key] = boolval($value); + // If beginning by "use", "has", ... , then must be a boolean (can be overriden using cast array) + if (preg_match('#^(use|has|is|enable|disable)_.*$#', $key)) { + $dto[$key] = $dto[$key] != null ? boolval($value) : null; + } + + // If ending by "id", then must be an integer (can be overriden using cast array) + if (preg_match('#^.*_?id$#', $key)) { + $dto[$key] = $dto[$key] != null ? intval($value) : null; } } - if ($toIntList && in_array($key, $toIntList)) { + if (in_array($key, $this->getAttributesToCastInt())) { $dto[$key] = $dto[$key] != null ? intval($dto[$key]) : null; } + + if (in_array($key, $this->getAttributesToCastBool())) { + $dto[$key] = $dto[$key] != null ? boolval($dto[$key]) : null; + } + + if (in_array($key, $this->getAttributesToCastStr())) { + $dto[$key] = $dto[$key] != null ? strval($dto[$key]) : null; + } } return $dto; } /** - * Get Dto from entity + * Apply custom dto filtering * - * @param Varien_Object $entity + * @param array $dto * * @return array */ - abstract protected function getDto($entity); + protected function customDtoFiltering($dto) + { + return $dto; + } /** * Get Dto attribute blacklist * * @return array */ - abstract protected function getBlacklist(); + protected function getBlacklist() + { + return []; + } /** * Get attribute list to cast to integer * * @return array */ - abstract protected function getAttributesToCastInt(); + protected function getAttributesToCastInt() + { + return []; + } + + /** + * Get attribute list to cast to boolean + * + * @return array + */ + protected function getAttributesToCastBool() + { + return []; + } + + /** + * Get attribute list to cast to string + * + * @return array + */ + protected function getAttributesToCastStr() + { + return []; + } } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php index 9fef2b9..16edd85 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php @@ -11,79 +11,14 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_Address extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { - /** - * Get AddressDto from Address - * - * @param Mage_Customer_Model_Address $address - * @return array - */ - protected function getDto($address) - { - $addressDto = $address->getData(); - - $addressDto['id'] = $addressDto['entity_id']; - - $region = null; - if (isset($addressDto['region'])) { - $region = $addressDto['region']; - } - - $addressDto['region'] = ['region' => $region]; - - $streetDto = explode("\n", $addressDto['street']); - if (count($streetDto) < 2) { - $streetDto[]=''; - } - - $addressDto['street'] = $streetDto; - if (!$addressDto['firstname']) { - $addressDto['firstname'] = $customerDto['firstname']; - } - - if (!$addressDto['lastname']) { - $addressDto['lastname'] = $customerDto['lastname']; - } - - if (!$addressDto['city']) { - $addressDto['city'] = ''; - } - - if (!$addressDto['country_id']) { - $addressDto['country_id'] = 'US'; - } - - if (!$addressDto['postcode']) { - $addressDto['postcode'] = ''; - } - - if (!$addressDto['telephone']) { - $addressDto['telephone'] = ''; - } - - return $addressDto; - } - - /** - * @inheritdoc - */ - protected function getBlacklist() - { - return []; - } - /** * @inheritdoc */ - protected function getAttributesToCastInt() + protected function getAttributesToCastBool() { return [ - 'id', - 'entity_id', - 'entity_type_id', - 'attribute_set_id', - 'increment_id', - 'parent_id', - 'customer_id' + 'default_billing', + 'default_shipping' ]; } } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Customer.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Customer.php index 733cf7e..07911fb 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Customer.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Customer.php @@ -11,22 +11,6 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_Customer extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { - /** - * Get CustomerDto from Customer - * - * @param Mage_Customer_Model_Customer $customer - * @return array - */ - protected function getDto($customer) - { - $customerDto = $customer->getData(); - - $customerDto['disable_auto_group_change'] = boolval($customerDto['disable_auto_group_change']); - $customerDto['id'] = $customerDto['entity_id']; - - return $customerDto; - } - /** * @inheritdoc */ @@ -48,13 +32,8 @@ protected function getBlacklist() protected function getAttributesToCastInt() { return [ - 'id', - 'entity_id', - 'attribute_set_id', - 'website_id', - 'group_id', - 'increment_id', - 'store_id', + 'default_billing', + 'default_shipping' ]; } } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Order.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Order.php index 1848a27..2720e6c 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Order.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Order.php @@ -11,59 +11,25 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_Order extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { - /** - * Get OrderDto from Order - * - * @param Mage_Sales_Model_Order $order - * @return array - */ - protected function getDto($order) - { - $orderDto = $order->getData(); - $orderDto['id'] = $orderDto['entity_id']; - $orderDto['items'] = []; - - /** @var Mage_Catalog_Model_Resource_Product $resourceModel */ - $resourceModel = Mage::getResourceModel('catalog/product'); - - foreach ($order->getAllVisibleItems() as $item) { - $itemDto = Mage::helper('vsbridge_mapper/orderitem')->toDto($item); - $itemDto['thumbnail'] = null; - - $image = $resourceModel->getAttributeRawValue( - $item->getProductId(), - 'thumbnail', - $order->getStoreId() - ); - - if ($image) { - $itemDto['thumbnail'] = $image; - } - - $orderDto['items'][] = $itemDto; - } - - $paymentDto = Mage::helper('vsbridge_mapper/payment')->toDto($order->getPayment()); - $orderDto['payment'] = $paymentDto; - - return $orderDto; - } - /** * @inheritdoc */ - protected function getBlacklist() + protected function getAttributesToCastInt() { - return []; + return [ + 'total_item_count' + ]; } /** * @inheritdoc */ - protected function getAttributesToCastInt() + protected function getAttributesToCastBool() { return [ - 'entity_id' + 'customer_is_guest', + 'email_sent', + 'paypal_ipn_customer_notified' ]; } } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php index 6363a78..e8aac3c 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php @@ -11,35 +11,4 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_OrderItem extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { - /** - * Get OrderItemDto from OrderItem - * - * @param Mage_Sales_Model_Order_Item $orderItem - * @return array - */ - protected function getDto($orderItem) - { - $orderItemDto = $orderItem->getData(); - $orderItemDto['id'] = $orderItemDto['item_id']; - - return $orderItemDto; - } - - /** - * @inheritdoc - */ - protected function getBlacklist() - { - return []; - } - - /** - * @inheritdoc - */ - protected function getAttributesToCastInt() - { - return [ - 'entity_id' - ]; - } } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Payment.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Payment.php index e634bba..48f52ed 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Payment.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Payment.php @@ -11,35 +11,4 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_Payment extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { - /** - * Get PaymentDto from Payment - * - * @param Mage_Sales_Model_Order_Payment $payment - * @return array - */ - protected function getDto($payment) - { - $paymentDto = $payment->getData(); - $paymentDto['method_title'] = $payment->getMethodInstance()->getTitle(); - - return $paymentDto; - } - - /** - * @inheritdoc - */ - protected function getBlacklist() - { - return []; - } - - /** - * @inheritdoc - */ - protected function getAttributesToCastInt() - { - return [ - 'entity_id' - ]; - } } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/PaymentMapper.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/PaymentMapper.php deleted file mode 100644 index e634bba..0000000 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/PaymentMapper.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @copyright Copyright (C) 2019 - * @license MIT License - */ -class Divante_VueStorefrontBridge_Helper_Mapper_Payment extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract -{ - /** - * Get PaymentDto from Payment - * - * @param Mage_Sales_Model_Order_Payment $payment - * @return array - */ - protected function getDto($payment) - { - $paymentDto = $payment->getData(); - $paymentDto['method_title'] = $payment->getMethodInstance()->getTitle(); - - return $paymentDto; - } - - /** - * @inheritdoc - */ - protected function getBlacklist() - { - return []; - } - - /** - * @inheritdoc - */ - protected function getAttributesToCastInt() - { - return [ - 'entity_id' - ]; - } -} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Stock.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Stock.php index a8b3101..34b5bef 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Stock.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Stock.php @@ -11,39 +11,14 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_Stock extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { - /** - * Get StockDto from StockItem - * - * @param Mage_CatalogInventory_Model_Stock_Item $stock - * - * @return array - */ - protected function getDto($stock) - { - $stockDto = $stock->getData(); - - $stockDto['stock_status_changed_auto'] = boolval($stockDto['stock_status_changed_auto']); - $stockDto['stock_status_changed_automatically'] = boolval($stockDto['stock_status_changed_automatically']); - $stockDto['notify_stock_qty'] = $stock->getNotifyStockQty(); - - return $stockDto; - } - - /** - * @inheritdoc - */ - protected function getBlacklist() - { - return []; - } - /** * @inheritdoc */ - protected function getAttributesToCastInt() + protected function getAttributesToCastBool() { return [ - 'entity_id' + 'stock_status_changed_auto', + 'stock_status_changed_automatically' ]; } } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php index 05b959a..ef109ff 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php @@ -78,8 +78,8 @@ public function resetPasswordAction() try { $customer = Mage::getModel('customer/customer') - ->setWebsiteId(Mage::app()->getStore()->getWebsiteId()) - ->loadByEmail($request->email); + ->setWebsiteId(Mage::app()->getStore()->getWebsiteId()) + ->loadByEmail($request->email); if ($customer->getId()) { $customer->sendPasswordResetConfirmationEmail(); @@ -194,11 +194,43 @@ public function orderHistoryAction() ->setOrder('created_at', 'desc'); $ordersDTO = []; + /** @var Mage_Catalog_Model_Resource_Product $resourceModel */ + $resourceModel = Mage::getResourceModel('catalog/product'); /** @var Mage_Sales_Model_Order $order */ foreach ($orderCollection as $order) { - $orderDTO = Mage::helper('vsbridge_mapper/order')->toDto($order); - $ordersDTO[] = $orderDTO; + $orderDTO = $order->getData(); + $orderDTO['id'] = $orderDTO['entity_id']; + + // Order items + $orderDTO['items'] = []; + foreach ($order->getAllVisibleItems() as $item) { + $itemDTO = $item->getData(); + $itemDTO['id'] = $itemDTO['item_id']; + $itemDTO['thumbnail'] = null; + + $image = $resourceModel->getAttributeRawValue( + $item->getProductId(), + 'thumbnail', + $order->getStoreId() + ); + + if ($image) { + $itemDTO['thumbnail'] = $image; + } + + $itemDTO = Mage::helper('vsbridge_mapper/orderItem')->filterDto($itemDTO); + $orderDTO['items'][] = $itemDTO; + } + + // Order payment + $paymentDTO = $order->getPayment()->toArray(); + $paymentDTO['method_title'] = $order->getPayment()->getMethodInstance()->getTitle(); + $paymentDTO = Mage::helper('vsbridge_mapper/payment')->filterDto($paymentDTO); + $orderDTO['payment'] = $paymentDTO; + + // Order + $ordersDTO[] = Mage::helper('vsbridge_mapper/order')->filterDto($orderDTO); } return $this->_result(200, array('items' => $ordersDTO)); @@ -231,7 +263,7 @@ public function createAction() $store = Mage::app()->getStore(); $customer = Mage::getModel("customer/customer"); - $customer ->setWebsiteId($websiteId) + $customer->setWebsiteId($websiteId) ->setStore($store) ->setFirstname($request->customer->firstname) ->setLastname($request->customer->lastname) @@ -240,18 +272,21 @@ public function createAction() try { $customer->save(); - $customerDto = Mage::helper('vsbridge_mapper/customer')->toDto($customer); - return $this->_result(200, $customerDto); // TODO: add support for 'Refresh-token' + $customerDTO = $customer->getData(); + $customerDTO = Mage::helper('vsbridge_mapper/customer')->filterDto($customerDTO); + + return $this->_result(200, $customerDTO); // TODO: add support for 'Refresh-token' } catch (Exception $e) { return $this->_result(500, $e->getMessage()); } } - public function meAction(){ + public function meAction() + { $customer = $this->_currentCustomer($this->getRequest()); - if(!$customer) { + if (!$customer) { return $this->_result(500, 'User is not authroized to access self'); } else { $updatedShippingId = 0; @@ -260,17 +295,16 @@ public function meAction(){ try { if ($this->_checkHttpMethod(array('POST'))) { // modify user data $request = _object_to_array($this->_getJsonBody()); - if(!$request['customer']) { + if (!$request['customer']) { return $this->_result(500, 'No customer data provided!'); } - //die(print_r($customer->getData(), true)); $updatedCustomer = $request['customer']; $updatedCustomer['entity_id'] = $customer->getId(); - + $customer->setData('firstname', $updatedCustomer['firstname']) - ->setData('lastname', $updatedCustomer['lastname']) - ->setData('email', $updatedCustomer['email']); + ->setData('lastname', $updatedCustomer['lastname']) + ->setData('email', $updatedCustomer['email']); if (isset($updatedCustomer['dob'])) { $customer->setData('dob', $updatedCustomer['dob']); @@ -279,15 +313,16 @@ public function meAction(){ $customer->save(); if ($updatedCustomer['addresses']) { - foreach($updatedCustomer['addresses'] as $updatedAdress) { + foreach ($updatedCustomer['addresses'] as $updatedAdress) { $updatedAdress['region'] = $updatedAdress['region']['region']; - if($updatedAdress['default_billing']) { + if ($updatedAdress['default_billing']) { $bAddressId = $customer->getDefaultBilling(); $bAddress = Mage::getModel('customer/address'); - - if($bAddressId) + + if ($bAddressId) { $bAddress->load($bAddressId); + } $updatedAdress['parent_id'] = $customer->getId(); @@ -295,23 +330,23 @@ public function meAction(){ $bAddress->setData($updatedAdress)->setIsDefaultBilling(1)->save(); $updatedBillingId = $bAddress->getId(); } - if($updatedAdress['default_shipping']) { + if ($updatedAdress['default_shipping']) { $sAddressId = $customer->getDefaultShipping(); $sAddress = Mage::getModel('customer/address'); - - if($sAddressId) + + if ($sAddressId) { $sAddress->load($sAddressId); + } - $updatedAdress['parent_id'] = $customer->getId(); + $updatedAdress['parent_id'] = $customer->getId(); $sAddress->setData($updatedAdress)->setIsDefaultShipping(1)->save(); $updatedShippingId = $sAddress->getId(); - } + } } } } $customer->load($customer->getId()); - $customerDTO = Mage::helper('vsbridge_mapper/customer')->toDto($customer); - + $customerDTO = $customer->getData(); $subscription = Mage::getModel('newsletter/subscriber')->loadByCustomer($customer); $customerDTO['is_subscribed'] = $subscription->isSubscribed(); @@ -321,21 +356,55 @@ public function meAction(){ $customerDTO['addresses'] = array(); foreach ($allAddress as $address) { - $addressDTO = Mage::helper('vsbridge_mapper/address')->toDto($address); + $addressDTO = $address->getData(); + $addressDTO['id'] = $addressDTO['entity_id']; + + $region = null; + + if (isset($addressDTO['region'])) { + $region = $addressDTO['region']; + } + + $addressDTO['region'] = ['region' => $region]; + + $streetDTO = explode("\n", $addressDTO['street']); + if(count($streetDTO) < 2) + $streetDTO[]=''; + + $addressDTO['street'] = $streetDTO; + if(!$addressDTO['firstname']) + $addressDTO['firstname'] = $customerDTO['firstname']; + if(!$addressDTO['lastname']) + $addressDTO['lastname'] = $customerDTO['lastname']; + if(!$addressDTO['city']) + $addressDTO['city'] = ''; + if(!$addressDTO['country_id']) + $addressDTO['country_id'] = 'US'; + if(!$addressDTO['postcode']) + $addressDTO['postcode'] = ''; + if(!$addressDTO['telephone']) + $addressDTO['telephone'] = ''; if($defaultBilling == $address->getId() || $address->getId() == $updatedBillingId) { // TODO: Street + Region fields (region_code should be) // its customer default billing address $addressDTO['default_billing'] = true; + $addressDTO = Mage::helper('vsbridge_mapper/address')->filterDto($addressDTO); + $customerDTO['default_billing'] = $address->getId(); $customerDTO['addresses'][] = $addressDTO; - } else if($defaultShipping == $address->getId()|| $address->getId() == $updatedShippingId) { + } elseif ($defaultShipping == $address->getId()|| $address->getId() == $updatedShippingId) { // its customer default shipping address $addressDTO['default_shipping'] = true; + $addressDTO = Mage::helper('vsbridge_mapper/address')->filterDto($addressDTO); + $customerDTO['default_shipping'] = $address->getId(); $customerDTO['addresses'][] = $addressDTO; } + + $customerDTO['id'] = $customerDTO['entity_id']; + $customerDTO = Mage::helper('vsbridge_mapper/customer')->filterDto($customerDTO); } return $this->_result(200, $customerDTO); From 6eaec47be573dd27efc0a02536d8e9ed9dda9135 Mon Sep 17 00:00:00 2001 From: Mathias Arlaud Date: Tue, 23 Apr 2019 14:51:36 +0200 Subject: [PATCH 04/14] Update stock controller --- .../VueStorefrontBridge/controllers/StockController.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/StockController.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/StockController.php index 2fd6c0a..1242c2d 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/StockController.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/StockController.php @@ -1,5 +1,6 @@ getIdBySku($sku); $product = Mage::getModel('catalog/product')->load($product_id); $stock = $product->getStockItem(); - $stockDto = Mage::helper('vsbridge_mapper/stock')->toDto($product->getStockItem()); - return $this->_result(200, $stockDto); + $stockDTO = $stock->getData(); + $stockDTO['notify_stock_qty'] = $stock->getNotifyStockQty(); + $stockDTO = Mage::helper('vsbridge_mapper/stock')->filterDto($stockDTO); + + return $this->_result(200, $stockDTO); } catch (Exception $err) { return $this->_result(500, $err->getMessage()); } From eb274cac9be423817cc4481ddc097541f08a7e8e Mon Sep 17 00:00:00 2001 From: Mathias Arlaud Date: Tue, 23 Apr 2019 15:33:28 +0200 Subject: [PATCH 05/14] Update other controllers --- .../Helper/Mapper/Abstract.php | 19 ++++++-- .../Helper/Mapper/Category.php | 46 +++++++++++++++++++ .../Helper/Mapper/Product.php | 14 ++++++ .../Helper/Mapper/ProductAttribute.php | 35 ++++++++++++++ .../Helper/Mapper/ProductChild.php | 40 ++++++++++++++++ .../Helper/Mapper/Taxrule.php | 37 +++++++++++++++ .../Helper/Mapper/TaxruleRate.php | 23 ++++++++++ .../controllers/AbstractController.php | 22 +-------- .../controllers/AttributesController.php | 9 ++-- .../controllers/CategoriesController.php | 29 +++--------- .../controllers/ProductsController.php | 29 +++--------- .../controllers/TaxrulesController.php | 17 +++---- 12 files changed, 238 insertions(+), 82 deletions(-) create mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Category.php create mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Product.php create mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductAttribute.php create mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductChild.php create mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Taxrule.php create mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/TaxruleRate.php diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php index 7d13142..f6276f1 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php @@ -19,11 +19,10 @@ abstract class Divante_VueStorefrontBridge_Helper_Mapper_Abstract extends Mage_C */ final public function filterDto($initialDto) { - $dto = $this->customDtoFiltering($initialDto); - $blacklist = $this->getBlacklist(); + $dto = $this->customDtoFiltering($initialDto); foreach ($dto as $key => $value) { - if ($blacklist && in_array($key, $blacklist)) { + if (in_array($key, $this->getBlacklist())) { unset($dto[$key]); } else { // If beginning by "use", "has", ... , then must be a boolean (can be overriden using cast array) @@ -48,6 +47,10 @@ final public function filterDto($initialDto) if (in_array($key, $this->getAttributesToCastStr())) { $dto[$key] = $dto[$key] != null ? strval($dto[$key]) : null; } + + if (in_array($key, $this->getAttributesToCastFloat())) { + $dto[$key] = $dto[$key] != null ? floatval($dto[$key]) : null; + } } return $dto; @@ -104,4 +107,14 @@ protected function getAttributesToCastStr() { return []; } + + /** + * Get attribute list to cast to float + * + * @return array + */ + protected function getAttributesToCastFloat() + { + return []; + } } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Category.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Category.php new file mode 100644 index 0000000..cbbb949 --- /dev/null +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Category.php @@ -0,0 +1,46 @@ + + * @copyright Copyright (C) 2019 + * @license MIT License + */ +class Divante_VueStorefrontBridge_Helper_Mapper_Category extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract +{ + /** + * @inheritdoc + */ + protected function getBlacklist() + { + return [ + 'entity_id', + 'path' + ]; + } + + /** + * @inheritdoc + */ + protected function getAttributesToCastInt() + { + return [ + 'position', + 'level', + 'children_count' + ]; + } + + /** + * @inheritdoc + */ + protected function getAttributesToCastBool() + { + return [ + 'include_in_menu' + ]; + } +} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Product.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Product.php new file mode 100644 index 0000000..dbea6a9 --- /dev/null +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Product.php @@ -0,0 +1,14 @@ + + * @copyright Copyright (C) 2019 + * @license MIT License + */ +class Divante_VueStorefrontBridge_Helper_Mapper_Product extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract +{ +} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductAttribute.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductAttribute.php new file mode 100644 index 0000000..13bf60d --- /dev/null +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductAttribute.php @@ -0,0 +1,35 @@ + + * @copyright Copyright (C) 2019 + * @license MIT License + */ +class Divante_VueStorefrontBridge_Helper_Mapper_ProductAttribute extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract +{ + /** + * @inheritdoc + */ + protected function getAttributesToCastInt() + { + return [ + 'default_value', + 'position' + ]; + } + + /** + * @inheritdoc + */ + protected function getAttributesToCastBool() + { + return [ + 'used_in_product_listing', + 'used_for_sort_by' + ]; + } +} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductChild.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductChild.php new file mode 100644 index 0000000..4cbd48b --- /dev/null +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductChild.php @@ -0,0 +1,40 @@ + + * @copyright Copyright (C) 2019 + * @license MIT License + */ +class Divante_VueStorefrontBridge_Helper_Mapper_ProductChild extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract +{ + /** + * @inheritdoc + */ + protected function getBlacklist() + { + return [ + 'entity_id', + 'id', + 'type_id', + 'updated_at', + 'created_at', + 'stock_item', + 'short_description', + 'page_layout', + 'news_from_date', + 'news_to_date', + 'meta_description', + 'meta_keyword', + 'meta_title', + 'description', + 'attribute_set_id', + 'entity_type_id', + 'has_options', + 'required_options' + ]; + } +} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Taxrule.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Taxrule.php new file mode 100644 index 0000000..e62c42c --- /dev/null +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Taxrule.php @@ -0,0 +1,37 @@ + + * @copyright Copyright (C) 2019 + * @license MIT License + */ +class Divante_VueStorefrontBridge_Helper_Mapper_Taxrule extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract +{ + /** + * @inheritdoc + */ + protected function getBlacklist() + { + return [ + 'tax_calculation_rule_id', + 'tax_rates', + 'product_tax_classes', + 'customer_tax_classes' + ]; + } + + /** + * @inheritdoc + */ + protected function getAttributesToCastInt() + { + return [ + 'position', + 'priority' + ]; + } +} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/TaxruleRate.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/TaxruleRate.php new file mode 100644 index 0000000..5dc3261 --- /dev/null +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/TaxruleRate.php @@ -0,0 +1,23 @@ + + * @copyright Copyright (C) 2019 + * @license MIT License + */ +class Divante_VueStorefrontBridge_Helper_Mapper_TaxruleRate extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract +{ + /** + * @inheritdoc + */ + protected function getBlacklist() + { + return [ + 'tax_calculation_rate_id' + ]; + } +} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/AbstractController.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/AbstractController.php index 6b5e374..933d101 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/AbstractController.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/AbstractController.php @@ -224,27 +224,7 @@ protected function _processParams(Mage_Core_Controller_Request_Http $request) return $paramsDTO; } - /** - * Filters parameters map removing blacklisted - * - * @param array $dtoToFilter - * @param array|null $blackList - * - * @return mixed - */ - protected function _filterDTO(array $dtoToFilter, array $blackList = null) - { - foreach ($dtoToFilter as $key => $val) { - if ($blackList && in_array($key, $blackList)) { - unset ($dtoToFilter[$key]); - } else { - if (strstr($key, 'is_') || strstr($key, 'has_')) { - $dtoToFilter[$key] = boolval($val); - } - } - } - return $dtoToFilter; - } + /** * Sends back code and result of performed operation * diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/AttributesController.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/AttributesController.php index c8dc043..2fbacea 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/AttributesController.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/AttributesController.php @@ -50,7 +50,8 @@ public function indexAction() /** @var Mage_Catalog_Model_Resource_Eav_Attribute $productAttr */ $attribute = Mage::getSingleton('eav/config') ->getAttribute(Mage_Catalog_Model_Product::ENTITY, $productAttr->getAttributeCode()); - $options = []; + + $options = []; if ($attribute->usesSource()) { $options = $attribute->getSource()->getAllOptions(false); } @@ -61,11 +62,11 @@ public function indexAction() continue; } // exception - this attribute has string typed values; this is not acceptable by VS - $productAttrDTO['id'] = intval($productAttr->getAttributeId()); + $productAttrDTO['id'] = $productAttr->getAttributeId(); $productAttrDTO['options'] = $options; $productAttrDTO['default_value'] = (int)$productAttrDTO['default_value']; - $productAttrDTO = $this->_filterDTO($productAttrDTO); - $attrList[] = $productAttrDTO; + + $attrList[] = Mage::helper('vsbridge_mapper/productAttribute')->filterDto($productAttrDTO); } $this->_result(200, $attrList); } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/CategoriesController.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/CategoriesController.php index 20f04b6..268d6b9 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/CategoriesController.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/CategoriesController.php @@ -36,23 +36,6 @@ public function indexAction() } } - /** - * Prepares category entity data - * - * @param Mage_Catalog_Model_Category $category - * - * @return mixed - */ - protected function _prepareDTO(Mage_Catalog_Model_Category $category) - { - $categoryDTO = $category->getData(); - $categoryDTO['id'] = intval($categoryDTO['entity_id']); - unset($categoryDTO['entity_id']); - unset($categoryDTO['path']); - - return $categoryDTO; - } - /** * Processes category data * @@ -63,16 +46,16 @@ protected function _prepareDTO(Mage_Catalog_Model_Category $category) */ protected function _processCategory(Mage_Catalog_Model_Category $category, $level = 0) { - $childCats = $category->getChildrenCategories(); - $catDTO = $this->_prepareDTO($category); + $catDTO = $category->getData(); + $catDTO['id'] = $catDTO['entity_id']; $catDTO['children_data'] = []; - foreach ($childCats as $childCategory) { + + foreach ($category->getChildrenCategories() as $childCategory) { $catDTO['children_data'][] = $this->_processCategory($childCategory, $level + 1); } + // $catDTO['level'] = $level; $catDTO['children_count'] = count($catDTO['children_data']); - $catDTO = $this->_filterDTO($catDTO); - - return $catDTO; + return Mage::helper('vsbridge_mapper/category')->filterDto($catDTO); } } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/ProductsController.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/ProductsController.php index 1c8e005..b1c86d0 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/ProductsController.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/ProductsController.php @@ -17,26 +17,6 @@ public function indexAction() { if ($this->_authorizeAdminUser($this->getRequest())) { $params = $this->_processParams($this->getRequest()); - $confChildBlacklist = [ - 'entity_id', - 'id', - 'type_id', - 'updated_at', - 'created_at', - 'stock_item', - 'short_description', - 'page_layout', - 'news_from_date', - 'news_to_date', - 'meta_description', - 'meta_keyword', - 'meta_title', - 'description', - 'attribute_set_id', - 'entity_type_id', - 'has_options', - 'required_options', - ]; $result = []; $productCollection = Mage::getModel('catalog/product') @@ -91,7 +71,7 @@ public function indexAction() $productDTO[$productAttribute['attribute_code'] . '_options'] = $availableOptions; } - $childDTO = $this->_filterDTO($childDTO, $confChildBlacklist); + $childDTO = Mage::helper('vsbridge_mapper/productChild')->filterDto($childDTO); $productDTO['configurable_children'][] = $childDTO; } } @@ -101,14 +81,17 @@ public function indexAction() $productDTO['category_ids'] = []; foreach ($cats as $category_id) { $cat = Mage::getModel('catalog/category')->load($category_id); - $productDTO['category'][] = [ + $categoryDTO = [ 'category_id' => $cat->getId(), 'name' => $cat->getName() ]; + $categoryDTO = Mage::helper('vsbridge_mapper/category')->filterDto($categoryDTO); + + $productDTO['category'][] = $categoryDTO; $productDTO['category_ids'][] = $category_id; } - $productDTO = $this->_filterDTO($productDTO); + $productDTO = Mage::helper('vsbridge_mapper/product')->filterDto($productDTO); $result[] = $productDTO; } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/TaxrulesController.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/TaxrulesController.php index 0195863..77755a1 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/TaxrulesController.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/TaxrulesController.php @@ -32,23 +32,24 @@ public function indexAction() $taxRules = array(); if ($collection->getSize()) { foreach ($collection as $rule) { - $taxRuleDTO = $rule->getData(); - $taxRuleDTO['id'] = intval($taxRuleDTO['tax_calculation_rule_id']); - unset($taxRuleDTO['tax_calculation_rule_id']); + $taxRuleDTO = $rule->getData(); + + $taxRuleDTO['id'] = $taxRuleDTO['tax_calculation_rule_id']; $taxRuleDTO['tax_rates_ids'] = $taxRuleDTO['tax_rates']; - unset($taxRuleDTO['tax_rates']); $taxRuleDTO['product_tax_class_ids'] = $taxRuleDTO['product_tax_classes']; - unset($taxRuleDTO['product_tax_classes']); $taxRuleDTO['customer_tax_class_ids'] = $taxRuleDTO['customer_tax_classes']; - unset($taxRuleDTO['customer_tax_classes']); $taxRuleDTO['rates'] = []; + foreach ($taxRuleDTO['tax_rates_ids'] as $rateId) { $rate->load($rateId); $rateDTO = $rate->getData(); - $rateDTO['id'] = intval($rateDTO['tax_calculation_rate_id']); - unset($rateDTO['tax_calculation_rate_id']); + $rateDTO['id'] = $rateDTO['tax_calculation_rate_id']; + $rateDTO = Mage::helper('vsbridge_mapper/taxruleRate')->filterDto($rateDTO); + $taxRuleDTO['rates'][] = $rateDTO; } + + $taxRuleDTO = Mage::helper('vsbridge_mapper/taxrule')->filterDto($taxRuleDTO); $taxRules[] = $taxRuleDTO; } } From 8be86bfb5c12d478e7c5dc989ead963a76097b5e Mon Sep 17 00:00:00 2001 From: Mathias Arlaud Date: Tue, 23 Apr 2019 15:54:45 +0200 Subject: [PATCH 06/14] Add float conversion --- .../Helper/Mapper/Order.php | 150 ++++++++++++++++++ .../Helper/Mapper/OrderItem.php | 72 +++++++++ 2 files changed, 222 insertions(+) diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Order.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Order.php index 2720e6c..55399b7 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Order.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Order.php @@ -32,4 +32,154 @@ protected function getAttributesToCastBool() 'paypal_ipn_customer_notified' ]; } + + /** + * @inheritdoc + */ + protected function getAttributesToCastFloat() + { + return [ + 'base_discount_amount', + 'base_discount_canceled', + 'base_discount_invoiced', + 'base_discount_refunded', + 'base_grand_total', + 'base_shipping_amount', + 'base_shipping_canceled', + 'base_shipping_invoiced', + 'base_shipping_refunded', + 'base_shipping_tax_amount', + 'base_shipping_tax_refunded', + 'base_subtotal', + 'base_subtotal_canceled', + 'base_subtotal_invoiced', + 'base_subtotal_refunded', + 'base_tax_amount', + 'base_tax_canceled', + 'base_tax_invoiced', + 'base_tax_refunded', + 'base_to_global_rate', + 'base_to_order_rate', + 'base_total_canceled', + 'base_total_invoiced', + 'base_total_invoiced_cost', + 'base_total_offline_refunded', + 'base_total_online_refunded', + 'base_total_paid', + 'base_total_qty_ordered', + 'base_total_refunded', + 'discount_amount', + 'discount_canceled', + 'discount_invoiced', + 'discount_refunded', + 'grand_total', + 'shipping_amount', + 'shipping_canceled', + 'shipping_invoiced', + 'shipping_refunded', + 'shipping_tax_amount', + 'shipping_tax_refunded', + 'store_to_base_rate', + 'store_to_order_rate', + 'subtotal', + 'subtotal_canceled', + 'subtotal_invoiced', + 'subtotal_refunded', + 'tax_amount', + 'tax_canceled', + 'tax_invoiced', + 'tax_refunded', + 'total_canceled', + 'total_invoiced', + 'total_offline_refunded', + 'total_online_refunded', + 'total_paid', + 'total_qty_ordered', + 'total_refunded', + // "can_ship_partially": null, + // "can_ship_partially_item": null, + 'adjustment_negative', + 'adjustment_positive', + 'base_adjustment_negative', + 'base_adjustment_positive', + 'base_shipping_discount_amount', + 'base_subtotal_incl_tax', + 'base_total_due', + 'payment_authorization_amount', + 'shipping_discount_amount', + 'subtotal_incl_tax', + 'total_due', + 'weight', + 'hidden_tax_amount', + 'base_hidden_tax_amount', + 'shipping_hidden_tax_amount', + 'base_shipping_hidden_tax_amnt', + 'base_shipping_hidden_tax_amount', + 'hidden_tax_invoiced', + 'base_hidden_tax_invoiced', + 'hidden_tax_refunded', + 'base_hidden_tax_refunded', + 'shipping_incl_tax', + 'base_shipping_incl_tax', + 'base_customer_balance_amount', + 'customer_balance_amount', + 'base_customer_balance_invoiced', + 'customer_balance_invoiced', + 'base_customer_balance_refunded', + 'customer_balance_refunded', + 'bs_customer_bal_total_refunded', + 'customer_bal_total_refunded', + 'base_gift_cards_amount', + 'gift_cards_amount', + 'base_gift_cards_invoiced', + 'gift_cards_invoiced', + 'base_gift_cards_refunded', + 'gift_cards_refunded', + 'gw_base_price', + 'gw_price', + 'gw_items_base_price', + 'gw_items_price', + 'gw_card_base_price', + 'gw_card_price', + 'gw_base_tax_amount', + 'gw_tax_amount', + 'gw_items_base_tax_amount', + 'gw_items_tax_amount', + 'gw_card_base_tax_amount', + 'gw_card_tax_amount', + 'gw_base_price_invoiced', + 'gw_price_invoiced', + 'gw_items_base_price_invoiced', + 'gw_items_price_invoiced', + 'gw_card_base_price_invoiced', + 'gw_card_price_invoiced', + 'gw_base_tax_amount_invoiced', + 'gw_tax_amount_invoiced', + 'gw_items_base_tax_invoiced', + 'gw_items_tax_invoiced', + 'gw_card_base_tax_invoiced', + 'gw_card_tax_invoiced', + 'gw_base_price_refunded', + 'gw_price_refunded', + 'gw_items_base_price_refunded', + 'gw_items_price_refunded', + 'gw_card_base_price_refunded', + 'gw_card_price_refunded', + 'gw_base_tax_amount_refunded', + 'gw_tax_amount_refunded', + 'gw_items_base_tax_refunded', + 'gw_items_tax_refunded', + 'gw_card_base_tax_refunded', + 'gw_card_tax_refunded', + 'reward_points_balance', + 'base_reward_currency_amount', + 'reward_currency_amount', + 'base_rwrd_crrncy_amt_invoiced', + 'rwrd_currency_amount_invoiced', + 'base_rwrd_crrncy_amnt_refnded', + 'rwrd_crrncy_amnt_refunded', + 'reward_points_balance_refund', + 'reward_points_balance_refunded' + ]; + } } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php index e8aac3c..52d0a7e 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php @@ -11,4 +11,76 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_OrderItem extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { + /** + * @inheritdoc + */ + protected function getAttributesToCastFloat() + { + return [ + 'weight', + 'base_cost', + 'price', + 'base_price', + 'original_price', + 'base_original_price', + 'tax_percent', + 'tax_amount', + 'base_tax_amount', + 'tax_invoiced', + 'base_tax_invoiced', + 'discount_percent', + 'discount_amount', + 'base_discount_amount', + 'discount_invoiced', + 'base_discount_invoiced', + 'amount_refunded', + 'base_amount_refunded', + 'row_total', + 'base_row_total', + 'row_invoiced', + 'base_row_invoiced', + 'row_weight', + 'base_tax_before_discount', + 'tax_before_discount', + 'price_incl_tax', + 'base_price_incl_tax', + 'row_total_incl_tax', + 'base_row_total_incl_tax', + 'hidden_tax_amount', + 'base_hidden_tax_amount', + 'hidden_tax_invoiced', + 'base_hidden_tax_invoiced', + 'hidden_tax_refunded', + 'base_hidden_tax_refunded', + 'tax_canceled', + 'hidden_tax_canceled', + 'tax_refunded', + 'base_tax_refunded', + 'discount_refunded', + 'base_discount_refunded', + 'base_weee_tax_applied_amount', + 'base_weee_tax_applied_row_amnt', + 'base_weee_tax_applied_row_amount', + 'weee_tax_applied_amount', + 'weee_tax_applied_row_amount', + 'weee_tax_applied', + 'weee_tax_disposition', + 'weee_tax_row_disposition', + 'base_weee_tax_disposition', + 'base_weee_tax_row_disposition', + 'gw_base_price', + 'gw_price', + 'gw_base_tax_amount', + 'gw_tax_amount', + 'gw_base_price_invoiced', + 'gw_price_invoiced', + 'gw_base_tax_amount_invoiced', + 'gw_tax_amount_invoiced', + 'gw_base_price_refunded', + 'gw_price_refunded', + 'gw_base_tax_amount_refunded', + 'gw_tax_amount_refunded', + 'qty_returned' + ]; + } } From bcc11a1ef913652682ec57ec74bb50e44600b8e5 Mon Sep 17 00:00:00 2001 From: Mathias Arlaud Date: Tue, 23 Apr 2019 15:55:00 +0200 Subject: [PATCH 07/14] Update whishlist --- .../Helper/Mapper/WhishListItem.php | 14 ++++++++++++++ .../controllers/WishlistController.php | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/WhishListItem.php diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/WhishListItem.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/WhishListItem.php new file mode 100644 index 0000000..348eec1 --- /dev/null +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/WhishListItem.php @@ -0,0 +1,14 @@ + + * @copyright Copyright (C) 2019 + * @license MIT License + */ +class Divante_VueStorefrontBridge_Helper_Mapper_WhishListItem extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract +{ +} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/WishlistController.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/WishlistController.php index 1defd6b..ddb30a2 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/WishlistController.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/WishlistController.php @@ -226,7 +226,7 @@ private function prepareWishListItem(Mage_Wishlist_Model_Item $item) 'wishlist_item_id' => $item->getId(), ]; - return $wishListDTO; + return Mage::helper('vsbridge_mapper/whishListItem')->filterDto($wishListDTO); } /** From 99e2f48120eb1b068fd168dcaa4f8b197de43118 Mon Sep 17 00:00:00 2001 From: Mathias Arlaud Date: Tue, 23 Apr 2019 16:18:19 +0200 Subject: [PATCH 08/14] Fix address country id that should be string --- .../Helper/Mapper/Abstract.php | 29 ++++++++++++------- .../Helper/Mapper/Address.php | 10 +++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php index f6276f1..46e8ed6 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php @@ -22,34 +22,43 @@ final public function filterDto($initialDto) $dto = $this->customDtoFiltering($initialDto); foreach ($dto as $key => $value) { + $isCustom = false; + if (in_array($key, $this->getBlacklist())) { unset($dto[$key]); - } else { - // If beginning by "use", "has", ... , then must be a boolean (can be overriden using cast array) - if (preg_match('#^(use|has|is|enable|disable)_.*$#', $key)) { - $dto[$key] = $dto[$key] != null ? boolval($value) : null; - } - - // If ending by "id", then must be an integer (can be overriden using cast array) - if (preg_match('#^.*_?id$#', $key)) { - $dto[$key] = $dto[$key] != null ? intval($value) : null; - } + continue; } if (in_array($key, $this->getAttributesToCastInt())) { $dto[$key] = $dto[$key] != null ? intval($dto[$key]) : null; + $isCustom = true; } if (in_array($key, $this->getAttributesToCastBool())) { $dto[$key] = $dto[$key] != null ? boolval($dto[$key]) : null; + $isCustom = true; } if (in_array($key, $this->getAttributesToCastStr())) { $dto[$key] = $dto[$key] != null ? strval($dto[$key]) : null; + $isCustom = true; } if (in_array($key, $this->getAttributesToCastFloat())) { $dto[$key] = $dto[$key] != null ? floatval($dto[$key]) : null; + $isCustom = true; + } + + if (!$isCustom) { + // If beginning by "use", "has", ... , then must be a boolean (can be overriden using cast array) + if (preg_match('#^(use|has|is|enable|disable)_.*$#', $key)) { + $dto[$key] = $dto[$key] != null ? boolval($value) : null; + } + + // If ending by "id", then must be an integer (can be overriden using cast array) + if (preg_match('#^.*_?id$#', $key)) { + $dto[$key] = $dto[$key] != null ? intval($value) : null; + } } } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php index 16edd85..1442737 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php @@ -11,6 +11,16 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_Address extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { + /** + * @inheritdoc + */ + protected function getAttributesToCastStr() + { + return [ + 'country_id' + ]; + } + /** * @inheritdoc */ From 305d3265af46c2b787aa47973db065a306778972 Mon Sep 17 00:00:00 2001 From: Mathias Arlaud Date: Wed, 24 Apr 2019 14:38:55 +0200 Subject: [PATCH 09/14] Fix user id missing --- .../VueStorefrontBridge/controllers/UserController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php index ef109ff..cdd776c 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php @@ -402,11 +402,11 @@ public function meAction() $customerDTO['default_shipping'] = $address->getId(); $customerDTO['addresses'][] = $addressDTO; } - - $customerDTO['id'] = $customerDTO['entity_id']; - $customerDTO = Mage::helper('vsbridge_mapper/customer')->filterDto($customerDTO); } + $customerDTO['id'] = $customerDTO['entity_id']; + $customerDTO = Mage::helper('vsbridge_mapper/customer')->filterDto($customerDTO); + return $this->_result(200, $customerDTO); } catch (Exception $err) { return $this->_result(500, $err->getMessage()); From d2b289b63627939329bcdc94df2bd0f467f91bde Mon Sep 17 00:00:00 2001 From: Mathias Arlaud Date: Wed, 24 Apr 2019 17:42:03 +0200 Subject: [PATCH 10/14] Fix: Set quote id as string --- .../Helper/Mapper/QuoteItem.php | 23 +++++++++++++++++++ .../controllers/CartController.php | 5 +++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/QuoteItem.php diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/QuoteItem.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/QuoteItem.php new file mode 100644 index 0000000..67f7fff --- /dev/null +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/QuoteItem.php @@ -0,0 +1,23 @@ + + * @copyright Copyright (C) 2019 + * @license MIT License + */ +class Divante_VueStorefrontBridge_Helper_Mapper_QuoteItem extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract +{ + /** + * @inheritdoc + */ + protected function getAttributesToCastStr() + { + return [ + 'quote_id' + ]; + } +} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/CartController.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/CartController.php index 0766d4b..13283b8 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/CartController.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/CartController.php @@ -112,7 +112,10 @@ public function pullAction() $items = []; foreach ($quoteObj->getAllVisibleItems() as $item) { - $items[] = $this->cartModel->getItemAsArray($item); + $quoteItemDTO = $this->cartModel->getItemAsArray($item); + $quoteItemDTO = Mage::helper('vsbridge_mapper/quoteItem')->filterDto($quoteItemDTO); + + $items[] = $quoteItemDTO; } return $this->_result(200, $items); From 9bc3388527febd22ae5d866c8b93638ff57b0df0 Mon Sep 17 00:00:00 2001 From: Mathias Arlaud Date: Thu, 25 Apr 2019 09:31:22 +0200 Subject: [PATCH 11/14] Use mapper for order addresses --- .../VueStorefrontBridge/Helper/Mapper/Address.php | 12 ++++++++++++ .../controllers/UserController.php | 11 ++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php index 1442737..36c64c4 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php @@ -11,6 +11,18 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_Address extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { + /** + * @inheritdoc + */ + protected function customDtoFiltering($dto) + { + if (!is_array($dto['street'])) { + $dto['street'] = explode("\n", $dto['street']); + } + + return $dto; + } + /** * @inheritdoc */ diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php index cdd776c..fe20a6a 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/controllers/UserController.php @@ -225,10 +225,19 @@ public function orderHistoryAction() // Order payment $paymentDTO = $order->getPayment()->toArray(); - $paymentDTO['method_title'] = $order->getPayment()->getMethodInstance()->getTitle(); + $paymentDTO['additional_information'][0] = $order->getPayment()->getMethodInstance()->getTitle(); $paymentDTO = Mage::helper('vsbridge_mapper/payment')->filterDto($paymentDTO); $orderDTO['payment'] = $paymentDTO; + // Order addresses + $shippingAddressDTO = $order->getShippingAddress()->getData(); + $shippingAddressDTO = Mage::helper('vsbridge_mapper/address')->filterDto($shippingAddressDTO); + $orderDTO['extension_attributes']['shipping_assignments'][0]['shipping']['address'] = $shippingAddressDTO; + + $billingAddressDTO = $order->getBillingAddress()->getData(); + $billingAddressDTO = Mage::helper('vsbridge_mapper/address')->filterDto($billingAddressDTO); + $orderDTO['billing_address'] = $billingAddressDTO; + // Order $ordersDTO[] = Mage::helper('vsbridge_mapper/order')->filterDto($orderDTO); } From 2c466788727a070a924cb9e63de38eae2116dd6b Mon Sep 17 00:00:00 2001 From: cewald Date: Thu, 14 Nov 2019 18:32:28 +0100 Subject: [PATCH 12/14] Make mapping more flexible (based on #25) --- .../Helper/Mapper/Abstract.php | 15 ++++++ .../Helper/Mapper/Address.php | 5 ++ .../Helper/Mapper/Category.php | 5 ++ .../Helper/Mapper/Customer.php | 5 ++ .../Helper/Mapper/Order.php | 5 ++ .../Helper/Mapper/OrderItem.php | 5 ++ .../Helper/Mapper/Payment.php | 4 ++ .../Helper/Mapper/Product.php | 4 ++ .../Helper/Mapper/ProductAttribute.php | 5 ++ .../Helper/Mapper/ProductChild.php | 5 ++ .../Helper/Mapper/QuoteItem.php | 5 ++ .../Helper/Mapper/Stock.php | 5 ++ .../Helper/Mapper/Taxrule.php | 5 ++ .../Helper/Mapper/TaxruleRate.php | 5 ++ .../Helper/Mapper/WhishListItem.php | 4 ++ .../Model/Config/Mapper.php | 53 +++++++++++++++++++ .../VueStorefrontBridge/etc/config.xml | 12 +++++ 17 files changed, 147 insertions(+) create mode 100644 magento1-module/app/code/local/Divante/VueStorefrontBridge/Model/Config/Mapper.php diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php index 46e8ed6..67f8a49 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php @@ -62,9 +62,24 @@ final public function filterDto($initialDto) } } + $this->callMapperExtensions($dto); + return $dto; } + /** + * Allow to extend the mappers using config.xml + * + * @param array $dto + * @return array + */ + protected function callMapperExtensions(&$dto) + { + /** @var Divante_VueStorefrontBridge_Model_Config_Mapper $model */ + $model = Mage::getModel('vsbridge/config_mapper'); + return $model->applyExtendedMapping(self::MAPPER_IDENTIFIER, $dto); + } + /** * Apply custom dto filtering * diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php index 36c64c4..c0a48a0 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php @@ -11,6 +11,11 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_Address extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { + /** + * Name to address custom mappers via config.xml + */ + const MAPPER_IDENTIFIER = 'address'; + /** * @inheritdoc */ diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Category.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Category.php index cbbb949..1e10354 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Category.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Category.php @@ -11,6 +11,11 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_Category extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { + /** + * Name to address custom mappers via config.xml + */ + const MAPPER_IDENTIFIER = 'category'; + /** * @inheritdoc */ diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Customer.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Customer.php index 07911fb..4b9204c 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Customer.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Customer.php @@ -11,6 +11,11 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_Customer extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { + /** + * Name to address custom mappers via config.xml + */ + const MAPPER_IDENTIFIER = 'customer'; + /** * @inheritdoc */ diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Order.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Order.php index 55399b7..cbc6222 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Order.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Order.php @@ -11,6 +11,11 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_Order extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { + /** + * Name to address custom mappers via config.xml + */ + const MAPPER_IDENTIFIER = 'order'; + /** * @inheritdoc */ diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php index 52d0a7e..3424f35 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php @@ -11,6 +11,11 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_OrderItem extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { + /** + * Name to address custom mappers via config.xml + */ + const MAPPER_IDENTIFIER = 'order_item'; + /** * @inheritdoc */ diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Payment.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Payment.php index 48f52ed..2e80909 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Payment.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Payment.php @@ -11,4 +11,8 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_Payment extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { + /** + * Name to address custom mappers via config.xml + */ + const MAPPER_IDENTIFIER = 'payment'; } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Product.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Product.php index dbea6a9..69d5d94 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Product.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Product.php @@ -11,4 +11,8 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_Product extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { + /** + * Name to address custom mappers via config.xml + */ + const MAPPER_IDENTIFIER = 'product'; } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductAttribute.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductAttribute.php index 13bf60d..8fd787a 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductAttribute.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductAttribute.php @@ -11,6 +11,11 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_ProductAttribute extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { + /** + * Name to address custom mappers via config.xml + */ + const MAPPER_IDENTIFIER = 'product_attribute'; + /** * @inheritdoc */ diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductChild.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductChild.php index 4cbd48b..80c8b51 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductChild.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductChild.php @@ -11,6 +11,11 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_ProductChild extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { + /** + * Name to address custom mappers via config.xml + */ + const MAPPER_IDENTIFIER = 'product_child'; + /** * @inheritdoc */ diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/QuoteItem.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/QuoteItem.php index 67f7fff..77da588 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/QuoteItem.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/QuoteItem.php @@ -11,6 +11,11 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_QuoteItem extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { + /** + * Name to address custom mappers via config.xml + */ + const MAPPER_IDENTIFIER = 'quote_item'; + /** * @inheritdoc */ diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Stock.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Stock.php index 34b5bef..993c910 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Stock.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Stock.php @@ -11,6 +11,11 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_Stock extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { + /** + * Name to address custom mappers via config.xml + */ + const MAPPER_IDENTIFIER = 'stock'; + /** * @inheritdoc */ diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Taxrule.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Taxrule.php index e62c42c..dae03e4 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Taxrule.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Taxrule.php @@ -11,6 +11,11 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_Taxrule extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { + /** + * Name to address custom mappers via config.xml + */ + const MAPPER_IDENTIFIER = 'taxrule'; + /** * @inheritdoc */ diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/TaxruleRate.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/TaxruleRate.php index 5dc3261..6c57b1a 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/TaxruleRate.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/TaxruleRate.php @@ -11,6 +11,11 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_TaxruleRate extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { + /** + * Name to address custom mappers via config.xml + */ + const MAPPER_IDENTIFIER = 'taxrule_rate'; + /** * @inheritdoc */ diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/WhishListItem.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/WhishListItem.php index 348eec1..131c286 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/WhishListItem.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/WhishListItem.php @@ -11,4 +11,8 @@ */ class Divante_VueStorefrontBridge_Helper_Mapper_WhishListItem extends Divante_VueStorefrontBridge_Helper_Mapper_Abstract { + /** + * Name to address custom mappers via config.xml + */ + const MAPPER_IDENTIFIER = 'whishlist_item'; } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Model/Config/Mapper.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Model/Config/Mapper.php new file mode 100644 index 0000000..942ffb5 --- /dev/null +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Model/Config/Mapper.php @@ -0,0 +1,53 @@ +getNode(self::MAPPER_CONFIG_ROOT_NODE)->asArray(); + foreach ($mappingConfigTypes as $mappingIdentifier => $mapper) { + $this->config[$mappingIdentifier] = $mapper['mapper']; + } + + return $this->config; + } + + /** + * @param string $type + * @param array $initialDto + * @return array + */ + public function applyExtendedMapping($type, &$initialDto) + { + if ($this->config[$type] && !empty($this->config[$type])) { + foreach ($this->config[$type] as $name => $className) { + $model = Mage::getModel($className); + if (!$model || !$model instanceof Divante_VueStorefrontBridge_Helper_Mapper_Abstract) { + $error = 'Class "%s" is not an instance on "Divante_VueStorefrontBridge_Helper_Mapper_Abstract".'; + Mage::log(sprintf($error, $className), 'system.log', true); + continue; + } + + $initialDto = $model->filterDto($initialDto); + } + } + + return $initialDto; + } +} diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/etc/config.xml b/magento1-module/app/code/local/Divante/VueStorefrontBridge/etc/config.xml index 3d84656..a87e230 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/etc/config.xml +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/etc/config.xml @@ -30,6 +30,18 @@ Divante_VueStorefrontBridge_Helper_Mapper + + + + + + + From 52e0466314fa9f8844c40a71355fc9e86fd4ddbd Mon Sep 17 00:00:00 2001 From: cewald Date: Thu, 14 Nov 2019 19:26:31 +0100 Subject: [PATCH 13/14] Fix typos and infinite loop --- .../Helper/Mapper/Abstract.php | 15 ++++++++++++--- .../VueStorefrontBridge/Helper/Mapper/Address.php | 3 ++- .../Helper/Mapper/Category.php | 3 ++- .../Helper/Mapper/Customer.php | 3 ++- .../VueStorefrontBridge/Helper/Mapper/Order.php | 3 ++- .../Helper/Mapper/OrderItem.php | 3 ++- .../VueStorefrontBridge/Helper/Mapper/Payment.php | 3 ++- .../VueStorefrontBridge/Helper/Mapper/Product.php | 3 ++- .../Helper/Mapper/ProductAttribute.php | 3 ++- .../Helper/Mapper/ProductChild.php | 3 ++- .../Helper/Mapper/QuoteItem.php | 3 ++- .../VueStorefrontBridge/Helper/Mapper/Stock.php | 3 ++- .../VueStorefrontBridge/Helper/Mapper/Taxrule.php | 3 ++- .../Helper/Mapper/TaxruleRate.php | 3 ++- .../Helper/Mapper/WhishListItem.php | 3 ++- .../VueStorefrontBridge/Model/Config/Mapper.php | 2 +- .../Divante/VueStorefrontBridge/etc/config.xml | 6 +++--- 17 files changed, 44 insertions(+), 21 deletions(-) diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php index 67f8a49..e363798 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php @@ -10,14 +10,21 @@ */ abstract class Divante_VueStorefrontBridge_Helper_Mapper_Abstract extends Mage_Core_Helper_Abstract { + /** + * Name to address custom mappers via config.xml + * @var string $_mapperIdentifier + */ + protected $_mapperIdentifier = ''; + /** * Get and process Dto from entity * * @param array $initialDto + * @param bool $callMapperExtensions * * @return array */ - final public function filterDto($initialDto) + final public function filterDto($initialDto, $callMapperExtensions = true) { $dto = $this->customDtoFiltering($initialDto); @@ -62,7 +69,9 @@ final public function filterDto($initialDto) } } - $this->callMapperExtensions($dto); + if ($callMapperExtensions) { + $this->callMapperExtensions($dto); + } return $dto; } @@ -77,7 +86,7 @@ protected function callMapperExtensions(&$dto) { /** @var Divante_VueStorefrontBridge_Model_Config_Mapper $model */ $model = Mage::getModel('vsbridge/config_mapper'); - return $model->applyExtendedMapping(self::MAPPER_IDENTIFIER, $dto); + return $model->applyExtendedMapping($this->_mapperIdentifier, $dto); } /** diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php index c0a48a0..2a63454 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Address.php @@ -13,8 +13,9 @@ class Divante_VueStorefrontBridge_Helper_Mapper_Address extends Divante_VueStore { /** * Name to address custom mappers via config.xml + * @var string $_mapperIdentifier */ - const MAPPER_IDENTIFIER = 'address'; + protected $_mapperIdentifier = 'address'; /** * @inheritdoc diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Category.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Category.php index 1e10354..3177806 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Category.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Category.php @@ -13,8 +13,9 @@ class Divante_VueStorefrontBridge_Helper_Mapper_Category extends Divante_VueStor { /** * Name to address custom mappers via config.xml + * @var string $_mapperIdentifier */ - const MAPPER_IDENTIFIER = 'category'; + protected $_mapperIdentifier = 'category'; /** * @inheritdoc diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Customer.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Customer.php index 4b9204c..66c3afc 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Customer.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Customer.php @@ -13,8 +13,9 @@ class Divante_VueStorefrontBridge_Helper_Mapper_Customer extends Divante_VueStor { /** * Name to address custom mappers via config.xml + * @var string $_mapperIdentifier */ - const MAPPER_IDENTIFIER = 'customer'; + protected $_mapperIdentifier = 'customer'; /** * @inheritdoc diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Order.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Order.php index cbc6222..1c755a2 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Order.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Order.php @@ -13,8 +13,9 @@ class Divante_VueStorefrontBridge_Helper_Mapper_Order extends Divante_VueStorefr { /** * Name to address custom mappers via config.xml + * @var string $_mapperIdentifier */ - const MAPPER_IDENTIFIER = 'order'; + protected $_mapperIdentifier = 'order'; /** * @inheritdoc diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php index 3424f35..e0b9739 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/OrderItem.php @@ -13,8 +13,9 @@ class Divante_VueStorefrontBridge_Helper_Mapper_OrderItem extends Divante_VueSto { /** * Name to address custom mappers via config.xml + * @var string $_mapperIdentifier */ - const MAPPER_IDENTIFIER = 'order_item'; + protected $_mapperIdentifier = 'order_item'; /** * @inheritdoc diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Payment.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Payment.php index 2e80909..956381a 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Payment.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Payment.php @@ -13,6 +13,7 @@ class Divante_VueStorefrontBridge_Helper_Mapper_Payment extends Divante_VueStore { /** * Name to address custom mappers via config.xml + * @var string $_mapperIdentifier */ - const MAPPER_IDENTIFIER = 'payment'; + protected $_mapperIdentifier = 'payment'; } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Product.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Product.php index 69d5d94..5b36d34 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Product.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Product.php @@ -13,6 +13,7 @@ class Divante_VueStorefrontBridge_Helper_Mapper_Product extends Divante_VueStore { /** * Name to address custom mappers via config.xml + * @var string $_mapperIdentifier */ - const MAPPER_IDENTIFIER = 'product'; + protected $_mapperIdentifier = 'product'; } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductAttribute.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductAttribute.php index 8fd787a..e7b11ae 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductAttribute.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductAttribute.php @@ -13,8 +13,9 @@ class Divante_VueStorefrontBridge_Helper_Mapper_ProductAttribute extends Divante { /** * Name to address custom mappers via config.xml + * @var string $_mapperIdentifier */ - const MAPPER_IDENTIFIER = 'product_attribute'; + protected $_mapperIdentifier = 'product_attribute'; /** * @inheritdoc diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductChild.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductChild.php index 80c8b51..5b71949 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductChild.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/ProductChild.php @@ -13,8 +13,9 @@ class Divante_VueStorefrontBridge_Helper_Mapper_ProductChild extends Divante_Vue { /** * Name to address custom mappers via config.xml + * @var string $_mapperIdentifier */ - const MAPPER_IDENTIFIER = 'product_child'; + protected $_mapperIdentifier = 'product_child'; /** * @inheritdoc diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/QuoteItem.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/QuoteItem.php index 77da588..8b6108d 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/QuoteItem.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/QuoteItem.php @@ -13,8 +13,9 @@ class Divante_VueStorefrontBridge_Helper_Mapper_QuoteItem extends Divante_VueSto { /** * Name to address custom mappers via config.xml + * @var string $_mapperIdentifier */ - const MAPPER_IDENTIFIER = 'quote_item'; + protected $_mapperIdentifier = 'quote_item'; /** * @inheritdoc diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Stock.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Stock.php index 993c910..6137da5 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Stock.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Stock.php @@ -13,8 +13,9 @@ class Divante_VueStorefrontBridge_Helper_Mapper_Stock extends Divante_VueStorefr { /** * Name to address custom mappers via config.xml + * @var string $_mapperIdentifier */ - const MAPPER_IDENTIFIER = 'stock'; + protected $_mapperIdentifier = 'stock'; /** * @inheritdoc diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Taxrule.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Taxrule.php index dae03e4..13f4ca2 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Taxrule.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Taxrule.php @@ -13,8 +13,9 @@ class Divante_VueStorefrontBridge_Helper_Mapper_Taxrule extends Divante_VueStore { /** * Name to address custom mappers via config.xml + * @var string $_mapperIdentifier */ - const MAPPER_IDENTIFIER = 'taxrule'; + protected $_mapperIdentifier = 'taxrule'; /** * @inheritdoc diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/TaxruleRate.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/TaxruleRate.php index 6c57b1a..ace4eb0 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/TaxruleRate.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/TaxruleRate.php @@ -13,8 +13,9 @@ class Divante_VueStorefrontBridge_Helper_Mapper_TaxruleRate extends Divante_VueS { /** * Name to address custom mappers via config.xml + * @var string $_mapperIdentifier */ - const MAPPER_IDENTIFIER = 'taxrule_rate'; + protected $_mapperIdentifier = 'taxrule_rate'; /** * @inheritdoc diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/WhishListItem.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/WhishListItem.php index 131c286..7720ab6 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/WhishListItem.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/WhishListItem.php @@ -13,6 +13,7 @@ class Divante_VueStorefrontBridge_Helper_Mapper_WhishListItem extends Divante_Vu { /** * Name to address custom mappers via config.xml + * @var string $_mapperIdentifier */ - const MAPPER_IDENTIFIER = 'whishlist_item'; + protected $_mapperIdentifier = 'whishlist_item'; } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Model/Config/Mapper.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Model/Config/Mapper.php index 942ffb5..c220df6 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Model/Config/Mapper.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Model/Config/Mapper.php @@ -44,7 +44,7 @@ public function applyExtendedMapping($type, &$initialDto) continue; } - $initialDto = $model->filterDto($initialDto); + $initialDto = $model->filterDto($initialDto, false); } } diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/etc/config.xml b/magento1-module/app/code/local/Divante/VueStorefrontBridge/etc/config.xml index a87e230..5b3b459 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/etc/config.xml +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/etc/config.xml @@ -35,11 +35,11 @@ - + From d990e5e0966ee5febefb7620ee66adc48d748b29 Mon Sep 17 00:00:00 2001 From: cewald Date: Thu, 14 Nov 2019 20:38:18 +0100 Subject: [PATCH 14/14] Make filterDto type-proof against null --- .../VueStorefrontBridge/Helper/Mapper/Abstract.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php index e363798..08c687c 100644 --- a/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php +++ b/magento1-module/app/code/local/Divante/VueStorefrontBridge/Helper/Mapper/Abstract.php @@ -37,34 +37,34 @@ final public function filterDto($initialDto, $callMapperExtensions = true) } if (in_array($key, $this->getAttributesToCastInt())) { - $dto[$key] = $dto[$key] != null ? intval($dto[$key]) : null; + $dto[$key] = $dto[$key] !== null ? intval($dto[$key]) : null; $isCustom = true; } if (in_array($key, $this->getAttributesToCastBool())) { - $dto[$key] = $dto[$key] != null ? boolval($dto[$key]) : null; + $dto[$key] = $dto[$key] !== null ? boolval($dto[$key]) : null; $isCustom = true; } if (in_array($key, $this->getAttributesToCastStr())) { - $dto[$key] = $dto[$key] != null ? strval($dto[$key]) : null; + $dto[$key] = $dto[$key] !== null ? strval($dto[$key]) : null; $isCustom = true; } if (in_array($key, $this->getAttributesToCastFloat())) { - $dto[$key] = $dto[$key] != null ? floatval($dto[$key]) : null; + $dto[$key] = $dto[$key] !== null ? floatval($dto[$key]) : null; $isCustom = true; } if (!$isCustom) { // If beginning by "use", "has", ... , then must be a boolean (can be overriden using cast array) if (preg_match('#^(use|has|is|enable|disable)_.*$#', $key)) { - $dto[$key] = $dto[$key] != null ? boolval($value) : null; + $dto[$key] = $dto[$key] !== null ? boolval($value) : null; } // If ending by "id", then must be an integer (can be overriden using cast array) if (preg_match('#^.*_?id$#', $key)) { - $dto[$key] = $dto[$key] != null ? intval($value) : null; + $dto[$key] = $dto[$key] !== null ? intval($value) : null; } } }