Exemple #1
0
 /**
  * Update Customer from visitor (Customer logged in)
  *
  * @param \Magento\Reports\Model\Product\Index\AbstractIndex $object
  * @return $this
  */
 public function updateCustomerFromVisitor(\Magento\Reports\Model\Product\Index\AbstractIndex $object)
 {
     /**
      * Do nothing if customer not logged in
      */
     if (!$object->getCustomerId() || !$object->getVisitorId()) {
         return $this;
     }
     $adapter = $this->_getWriteAdapter();
     $select = $adapter->select()->from($this->getMainTable())->where('visitor_id = ?', $object->getVisitorId());
     $rowSet = $select->query()->fetchAll();
     foreach ($rowSet as $row) {
         /* We need to determine if there are rows with known
            customer for current product.
            */
         $select = $adapter->select()->from($this->getMainTable())->where('customer_id = ?', $object->getCustomerId())->where('product_id = ?', $row['product_id']);
         $idx = $adapter->fetchRow($select);
         if ($idx) {
             /**
              * If we are here it means that we have two rows: one with known customer, but second just visitor is set
              * One row should be updated with customer_id, second should be deleted
              */
             $adapter->delete($this->getMainTable(), array('index_id = ?' => $row['index_id']));
             $where = array('index_id = ?' => $idx['index_id']);
             $data = array('visitor_id' => $object->getVisitorId(), 'store_id' => $object->getStoreId(), 'added_at' => $this->dateTime->now());
         } else {
             $where = array('index_id = ?' => $row['index_id']);
             $data = array('customer_id' => $object->getCustomerId(), 'store_id' => $object->getStoreId(), 'added_at' => $this->dateTime->now());
         }
         $adapter->update($this->getMainTable(), $data, $where);
     }
     return $this;
 }
Exemple #2
0
 /**
  * Set created date
  *
  * @param \Magento\Core\Model\Object $object
  * @return $this
  */
 public function beforeSave($object)
 {
     $attributeCode = $this->getAttribute()->getAttributeCode();
     if ($object->isObjectNew() && is_null($object->getData($attributeCode))) {
         $object->setData($attributeCode, $this->dateTime->now());
     }
     return $this;
 }
Exemple #3
0
 /**
  * Prepare data for save
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return array
  */
 protected function _prepareDataForSave(\Magento\Framework\Model\AbstractModel $object)
 {
     $currentTime = $this->dateTime->now();
     if ((!$object->getId() || $object->isObjectNew()) && !$object->getCreatedAt()) {
         $object->setCreatedAt($currentTime);
     }
     $object->setUpdatedAt($currentTime);
     $data = parent::_prepareDataForSave($object);
     return $data;
 }
Exemple #4
0
 /**
  * Authenticate user by $username and $password
  *
  * @param ModelUser $user
  * @return $this
  */
 public function recordLogin(ModelUser $user)
 {
     $adapter = $this->_getWriteAdapter();
     $data = array('logdate' => $this->dateTime->now(), 'lognum' => $user->getLognum() + 1);
     $condition = array('user_id = ?' => (int) $user->getUserId());
     $adapter->update($this->getMainTable(), $data, $condition);
     return $this;
 }
Exemple #5
0
 /**
  * @return string
  */
 public function getCurrentStatus()
 {
     $log = $this->getCustomerLog();
     $interval = $this->_modelVisitor->getOnlineMinutesInterval();
     if ($log->getLogoutAt() || strtotime($this->dateTime->now()) - strtotime($log->getLastVisitAt()) > $interval * 60) {
         return __('Offline');
     }
     return __('Online');
 }
Exemple #6
0
 /**
  * Update tax percents for WEEE based on products condition
  *
  * @param Product|ConditionInterface|int $productCondition
  * @return $this
  */
 protected function _updateDiscountPercents($productCondition = null)
 {
     $now = $this->dateTime->toTimestamp($this->dateTime->now());
     $adapter = $this->_getWriteAdapter();
     $select = $this->_getReadAdapter()->select();
     $select->from(array('data' => $this->getTable('catalogrule_product')));
     $deleteCondition = '';
     if ($productCondition) {
         if ($productCondition instanceof Product) {
             $select->where('product_id = ?', (int) $productCondition->getId());
             $deleteCondition = $adapter->quoteInto('entity_id=?', (int) $productCondition->getId());
         } elseif ($productCondition instanceof ConditionInterface) {
             $productCondition = $productCondition->getIdsSelect($adapter)->__toString();
             $select->where("product_id IN ({$productCondition})");
             $deleteCondition = "entity_id IN ({$productCondition})";
         } else {
             $select->where('product_id = ?', (int) $productCondition);
             $deleteCondition = $adapter->quoteInto('entity_id = ?', (int) $productCondition);
         }
     } else {
         $select->where('(from_time <= ? OR from_time = 0)', $now)->where('(to_time >= ? OR to_time = 0)', $now);
     }
     $adapter->delete($this->getTable('weee_discount'), $deleteCondition);
     $select->order(array('data.website_id', 'data.customer_group_id', 'data.product_id', 'data.sort_order'));
     $data = $this->_getReadAdapter()->query($select);
     $productData = array();
     $stops = array();
     $prevKey = false;
     while ($row = $data->fetch()) {
         $key = "{$row['product_id']}-{$row['website_id']}-{$row['customer_group_id']}";
         if (isset($stops[$key]) && $stops[$key]) {
             continue;
         }
         if ($prevKey && $prevKey != $key) {
             foreach ($productData as $product) {
                 $adapter->insert($this->getTable('weee_discount'), $product);
             }
             $productData = array();
         }
         if ($row['action_operator'] == 'by_percent') {
             if (isset($productData[$key])) {
                 $productData[$key]['value'] -= $productData[$key]['value'] / 100 * $row['action_amount'];
             } else {
                 $productData[$key] = array('entity_id' => $row['product_id'], 'customer_group_id' => $row['customer_group_id'], 'website_id' => $row['website_id'], 'value' => 100 - max(0, min(100, $row['action_amount'])));
             }
         }
         if ($row['action_stop']) {
             $stops[$key] = true;
         }
         $prevKey = $key;
     }
     foreach ($productData as $product) {
         $adapter->insert($this->getTable('weee_discount'), $product);
     }
     return $this;
 }
Exemple #7
0
 /**
  * Change reset password link token
  *
  * Stores new reset password link token and its creation time
  *
  * @param \Magento\Customer\Model\Customer $customer
  * @param string $passwordLinkToken
  * @return $this
  */
 public function changeResetPasswordLinkToken(\Magento\Customer\Model\Customer $customer, $passwordLinkToken)
 {
     if (is_string($passwordLinkToken) && !empty($passwordLinkToken)) {
         $customer->setRpToken($passwordLinkToken);
         $customer->setRpTokenCreatedAt($this->dateTime->now());
         $this->saveAttribute($customer, 'rp_token');
         $this->saveAttribute($customer, 'rp_token_created_at');
     }
     return $this;
 }
Exemple #8
0
 /**
  * Saving visitor information by request
  *
  * Used in event "controller_action_postdispatch"
  *
  * @param   \Magento\Framework\Event\Observer $observer
  * @return  \Magento\Log\Model\Visitor
  */
 public function logVisitorActivity($observer)
 {
     $visitor = $observer->getEvent()->getVisitor();
     try {
         $this->setData($visitor->getData());
         if ($this->getId() && $this->getVisitorId()) {
             $this->initServerData();
             $this->setLastVisitAt($this->dateTime->now());
             $this->save();
             $visitor->setData($this->getData());
         }
     } catch (\Exception $e) {
         $this->_logger->logException($e);
     }
     return $this;
 }
 /**
  * Prepare customer/visitor, store data before save
  *
  * @return $this
  */
 protected function _beforeSave()
 {
     parent::_beforeSave();
     if (!$this->hasVisitorId()) {
         $this->setVisitorId($this->getVisitorId());
     }
     if (!$this->hasCustomerId()) {
         $this->setCustomerId($this->getCustomerId());
     }
     if (!$this->hasStoreId()) {
         $this->setStoreId($this->getStoreId());
     }
     if (!$this->hasAddedAt()) {
         $this->setAddedAt($this->dateTime->now());
     }
     return $this;
 }
Exemple #10
0
 /**
  * Set modified date
  *
  * @param \Magento\Framework\Object $object
  * @return $this
  */
 public function beforeSave($object)
 {
     $object->setData($this->getAttribute()->getAttributeCode(), $this->dateTime->now());
     return $this;
 }
Exemple #11
0
 /**
  * Add catalog product object data to wishlist
  *
  * @param   \Magento\Catalog\Model\Product $product
  * @param   int $qty
  * @param   bool $forciblySetQty
  *
  * @return  Item
  */
 protected function _addCatalogProduct(\Magento\Catalog\Model\Product $product, $qty = 1, $forciblySetQty = false)
 {
     $item = null;
     foreach ($this->getItemCollection() as $_item) {
         if ($_item->representProduct($product)) {
             $item = $_item;
             break;
         }
     }
     if ($item === null) {
         $storeId = $product->hasWishlistStoreId() ? $product->getWishlistStoreId() : $this->getStore()->getId();
         $item = $this->_wishlistItemFactory->create();
         $item->setProductId($product->getId());
         $item->setWishlistId($this->getId());
         $item->setAddedAt($this->dateTime->now());
         $item->setStoreId($storeId);
         $item->setOptions($product->getCustomOptions());
         $item->setProduct($product);
         $item->setQty($qty);
         $item->save();
         if ($item->getId()) {
             $this->getItemCollection()->addItem($item);
         }
     } else {
         $qty = $forciblySetQty ? $qty : $item->getQty() + $qty;
         $item->setQty($qty)->save();
     }
     $this->addItem($item);
     return $item;
 }
Exemple #12
0
 /**
  * Saving visitor information by request
  *
  * Used in event "controller_action_postdispatch"
  *
  * @param   \Magento\Framework\Event\Observer $observer
  * @return  \Magento\Log\Model\Visitor
  */
 public function saveByRequest($observer)
 {
     if ($this->_skipRequestLogging || $this->isModuleIgnored($observer)) {
         return $this;
     }
     try {
         $this->setLastVisitAt($this->dateTime->now());
         $this->save();
         $this->_getSession()->setVisitorData($this->getData());
     } catch (\Exception $e) {
         $this->_logger->logException($e);
     }
     return $this;
 }
Exemple #13
0
 /**
  * Before save actions
  *
  * @return $this
  */
 protected function _beforeSave()
 {
     if ($this->isObjectNew() && null === $this->getCreatedAt()) {
         $this->setCreatedAt($this->_dateTime->now());
     }
     parent::_beforeSave();
     return $this;
 }
Exemple #14
0
 /**
  * Check if current reset password link token is expired
  *
  * @return bool
  */
 public function isResetPasswordLinkTokenExpired()
 {
     $linkToken = $this->getRpToken();
     $linkTokenCreatedAt = $this->getRpTokenCreatedAt();
     if (empty($linkToken) || empty($linkTokenCreatedAt)) {
         return true;
     }
     $expirationPeriod = $this->_userData->getResetPasswordLinkExpirationPeriod();
     $currentTimestamp = $this->dateTime->toTimestamp($this->dateTime->now());
     $tokenTimestamp = $this->dateTime->toTimestamp($linkTokenCreatedAt);
     if ($tokenTimestamp > $currentTimestamp) {
         return true;
     }
     $dayDifference = floor(($currentTimestamp - $tokenTimestamp) / (24 * 60 * 60));
     if ($dayDifference >= $expirationPeriod) {
         return true;
     }
     return false;
 }
Exemple #15
0
 /**
  * Retrieve product data for future update
  *
  * @param array $rowData
  * @param int $productId
  * @return array
  */
 protected function _getProductData(array $rowData, $productId)
 {
     $productData = array('entity_id' => $productId, 'has_options' => 1, 'required_options' => 0, 'updated_at' => $this->dateTime->now());
     if (!empty($rowData[self::COLUMN_IS_REQUIRED])) {
         $productData['required_options'] = 1;
     }
     return $productData;
 }
Exemple #16
0
 /**
  * Gather and save information about product entities.
  *
  * @return $this
  */
 protected function _saveProducts()
 {
     /** @var $resource \Magento\CatalogImportExport\Model\Import\Proxy\Product\Resource */
     $resource = $this->_resourceFactory->create();
     $priceIsGlobal = $this->_catalogData->isPriceGlobal();
     $productLimit = null;
     $productsQty = null;
     while ($bunch = $this->_dataSourceModel->getNextBunch()) {
         $entityRowsIn = array();
         $entityRowsUp = array();
         $attributes = array();
         $websites = array();
         $categories = array();
         $tierPrices = array();
         $groupPrices = array();
         $mediaGallery = array();
         $uploadedGalleryFiles = array();
         $previousType = null;
         $prevAttributeSet = null;
         foreach ($bunch as $rowNum => $rowData) {
             if (!$this->validateRow($rowData, $rowNum)) {
                 continue;
             }
             $rowScope = $this->getRowScope($rowData);
             if (self::SCOPE_DEFAULT == $rowScope) {
                 $rowSku = $rowData[self::COL_SKU];
                 // 1. Entity phase
                 if (isset($this->_oldSku[$rowSku])) {
                     // existing row
                     $entityRowsUp[] = array('updated_at' => $this->dateTime->now(), 'entity_id' => $this->_oldSku[$rowSku]['entity_id']);
                 } else {
                     // new row
                     if (!$productLimit || $productsQty < $productLimit) {
                         $entityRowsIn[$rowSku] = array('entity_type_id' => $this->_entityTypeId, 'attribute_set_id' => $this->_newSku[$rowSku]['attr_set_id'], 'type_id' => $this->_newSku[$rowSku]['type_id'], 'sku' => $rowSku, 'has_options' => isset($rowData['has_options']) ? $rowData['has_options'] : 0, 'created_at' => $this->dateTime->now(), 'updated_at' => $this->dateTime->now());
                         $productsQty++;
                     } else {
                         $rowSku = null;
                         // sign for child rows to be skipped
                         $this->_rowsToSkip[$rowNum] = true;
                         continue;
                     }
                 }
             } elseif (null === $rowSku) {
                 $this->_rowsToSkip[$rowNum] = true;
                 // skip rows when SKU is NULL
                 continue;
             } elseif (self::SCOPE_STORE == $rowScope) {
                 // set necessary data from SCOPE_DEFAULT row
                 $rowData[self::COL_TYPE] = $this->_newSku[$rowSku]['type_id'];
                 $rowData['attribute_set_id'] = $this->_newSku[$rowSku]['attr_set_id'];
                 $rowData[self::COL_ATTR_SET] = $this->_newSku[$rowSku]['attr_set_code'];
             }
             // 2. Product-to-Website phase
             if (!empty($rowData['_product_websites'])) {
                 $websites[$rowSku][$this->_websiteCodeToId[$rowData['_product_websites']]] = true;
             }
             // 3. Categories phase
             $categoryPath = empty($rowData[self::COL_CATEGORY]) ? '' : $rowData[self::COL_CATEGORY];
             if (!empty($rowData[self::COL_ROOT_CATEGORY])) {
                 $categoryId = $this->_categoriesWithRoots[$rowData[self::COL_ROOT_CATEGORY]][$categoryPath];
                 $categories[$rowSku][$categoryId] = true;
             } elseif (!empty($categoryPath)) {
                 $categories[$rowSku][$this->_categories[$categoryPath]] = true;
             }
             // 4.1. Tier prices phase
             if (!empty($rowData['_tier_price_website'])) {
                 $tierPrices[$rowSku][] = array('all_groups' => $rowData['_tier_price_customer_group'] == self::VALUE_ALL, 'customer_group_id' => $rowData['_tier_price_customer_group'] == self::VALUE_ALL ? 0 : $rowData['_tier_price_customer_group'], 'qty' => $rowData['_tier_price_qty'], 'value' => $rowData['_tier_price_price'], 'website_id' => self::VALUE_ALL == $rowData['_tier_price_website'] || $priceIsGlobal ? 0 : $this->_websiteCodeToId[$rowData['_tier_price_website']]);
             }
             // 4.2. Group prices phase
             if (!empty($rowData['_group_price_website'])) {
                 $groupPrices[$rowSku][] = array('all_groups' => $rowData['_group_price_customer_group'] == self::VALUE_ALL, 'customer_group_id' => $rowData['_group_price_customer_group'] == self::VALUE_ALL ? 0 : $rowData['_group_price_customer_group'], 'value' => $rowData['_group_price_price'], 'website_id' => self::VALUE_ALL == $rowData['_group_price_website'] || $priceIsGlobal ? 0 : $this->_websiteCodeToId[$rowData['_group_price_website']]);
             }
             // 5. Media gallery phase
             foreach ($this->_imagesArrayKeys as $imageCol) {
                 if (!empty($rowData[$imageCol])) {
                     if (!array_key_exists($rowData[$imageCol], $uploadedGalleryFiles)) {
                         $uploadedGalleryFiles[$rowData[$imageCol]] = $this->_uploadMediaFiles($rowData[$imageCol]);
                     }
                     $rowData[$imageCol] = $uploadedGalleryFiles[$rowData[$imageCol]];
                 }
             }
             if (!empty($rowData['_media_image'])) {
                 $mediaGallery[$rowSku][] = array('attribute_id' => $rowData['_media_attribute_id'], 'label' => $rowData['_media_label'], 'position' => $rowData['_media_position'], 'disabled' => $rowData['_media_is_disabled'], 'value' => $rowData['_media_image']);
             }
             // 6. Attributes phase
             $rowStore = self::SCOPE_STORE == $rowScope ? $this->_storeCodeToId[$rowData[self::COL_STORE]] : 0;
             $productType = isset($rowData[self::COL_TYPE]) ? $rowData[self::COL_TYPE] : null;
             if (!is_null($productType)) {
                 $previousType = $productType;
             }
             if (isset($rowData[self::COL_ATTR_SET])) {
                 $prevAttributeSet = $rowData[self::COL_ATTR_SET];
             }
             if (self::SCOPE_NULL == $rowScope) {
                 // for multiselect attributes only
                 if (!is_null($prevAttributeSet)) {
                     $rowData[self::COL_ATTR_SET] = $prevAttributeSet;
                 }
                 if (is_null($productType) && !is_null($previousType)) {
                     $productType = $previousType;
                 }
                 if (is_null($productType)) {
                     continue;
                 }
             }
             if ($this->getBehavior() == \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND || empty($rowData[self::COL_SKU])) {
                 $rowData = $this->_productTypeModels[$productType]->clearEmptyData($rowData);
             }
             $rowData = $this->_productTypeModels[$productType]->prepareAttributesWithDefaultValueForSave($rowData, !isset($this->_oldSku[$rowSku]));
             $product = $this->_proxyProdFactory->create(array('data' => $rowData));
             foreach ($rowData as $attrCode => $attrValue) {
                 $attribute = $resource->getAttribute($attrCode);
                 if ('multiselect' != $attribute->getFrontendInput() && self::SCOPE_NULL == $rowScope) {
                     // skip attribute processing for SCOPE_NULL rows
                     continue;
                 }
                 $attrId = $attribute->getId();
                 $backModel = $attribute->getBackendModel();
                 $attrTable = $attribute->getBackend()->getTable();
                 $storeIds = array(0);
                 if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) {
                     $attrValue = new \DateTime('@' . strtotime($attrValue));
                     $attrValue = $attrValue->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
                 } elseif ($backModel) {
                     $attribute->getBackend()->beforeSave($product);
                     $attrValue = $product->getData($attribute->getAttributeCode());
                 }
                 if (self::SCOPE_STORE == $rowScope) {
                     if (self::SCOPE_WEBSITE == $attribute->getIsGlobal()) {
                         // check website defaults already set
                         if (!isset($attributes[$attrTable][$rowSku][$attrId][$rowStore])) {
                             $storeIds = $this->_storeIdToWebsiteStoreIds[$rowStore];
                         }
                     } elseif (self::SCOPE_STORE == $attribute->getIsGlobal()) {
                         $storeIds = array($rowStore);
                     }
                 }
                 foreach ($storeIds as $storeId) {
                     if ('multiselect' == $attribute->getFrontendInput()) {
                         if (!isset($attributes[$attrTable][$rowSku][$attrId][$storeId])) {
                             $attributes[$attrTable][$rowSku][$attrId][$storeId] = '';
                         } else {
                             $attributes[$attrTable][$rowSku][$attrId][$storeId] .= ',';
                         }
                         $attributes[$attrTable][$rowSku][$attrId][$storeId] .= $attrValue;
                     } else {
                         $attributes[$attrTable][$rowSku][$attrId][$storeId] = $attrValue;
                     }
                 }
                 // restore 'backend_model' to avoid 'default' setting
                 $attribute->setBackendModel($backModel);
             }
         }
         $this->_saveProductEntity($entityRowsIn, $entityRowsUp)->_saveProductWebsites($websites)->_saveProductCategories($categories)->_saveProductTierPrices($tierPrices)->_saveProductGroupPrices($groupPrices)->_saveMediaGallery($mediaGallery)->_saveProductAttributes($attributes);
     }
     return $this;
 }
Exemple #17
0
 /**
  * Get current date time
  *
  * @return string
  */
 protected function _getCurrentDateTime()
 {
     return $this->dateTime->now();
 }
Exemple #18
0
 /**
  * Retrieve current date for current rule
  *
  * @return string
  */
 public function getNow()
 {
     if (!$this->_now) {
         return $this->dateTime->now();
     }
     return $this->_now;
 }
Exemple #19
0
 public function testNow()
 {
     $this->assertEquals(date(\Magento\Framework\Stdlib\DateTime::DATE_PHP_FORMAT), $this->_dateTime->now(true));
     $this->assertEquals(date(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT), $this->_dateTime->now(false));
 }
Exemple #20
0
 /**
  * Build qoutes request XML object
  *
  * @return \SimpleXMLElement
  */
 protected function _buildQuotesRequestXml()
 {
     $rawRequest = $this->_rawRequest;
     $xmlStr = '<?xml version = "1.0" encoding = "UTF-8"?>' . '<p:DCTRequest xmlns:p="http://www.dhl.com" xmlns:p1="http://www.dhl.com/datatypes" ' . 'xmlns:p2="http://www.dhl.com/DCTRequestdatatypes" ' . 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' . 'xsi:schemaLocation="http://www.dhl.com DCT-req.xsd "/>';
     $xml = $this->_xmlElFactory->create(array('data' => $xmlStr));
     $nodeGetQuote = $xml->addChild('GetQuote', '', '');
     $nodeRequest = $nodeGetQuote->addChild('Request');
     $nodeServiceHeader = $nodeRequest->addChild('ServiceHeader');
     $nodeServiceHeader->addChild('SiteID', (string) $this->getConfigData('id'));
     $nodeServiceHeader->addChild('Password', (string) $this->getConfigData('password'));
     $nodeFrom = $nodeGetQuote->addChild('From');
     $nodeFrom->addChild('CountryCode', $rawRequest->getOrigCountryId());
     $nodeFrom->addChild('Postalcode', $rawRequest->getOrigPostal());
     $nodeFrom->addChild('City', $rawRequest->getOrigCity());
     $nodeBkgDetails = $nodeGetQuote->addChild('BkgDetails');
     $nodeBkgDetails->addChild('PaymentCountryCode', $rawRequest->getOrigCountryId());
     $nodeBkgDetails->addChild('Date', $this->_dateTime->now(true));
     $nodeBkgDetails->addChild('ReadyTime', 'PT' . (int) (string) $this->getConfigData('ready_time') . 'H00M');
     $nodeBkgDetails->addChild('DimensionUnit', $this->_getDimensionUnit());
     $nodeBkgDetails->addChild('WeightUnit', $this->_getWeightUnit());
     $this->_makePieces($nodeBkgDetails);
     $nodeBkgDetails->addChild('PaymentAccountNumber', (string) $this->getConfigData('account'));
     $nodeTo = $nodeGetQuote->addChild('To');
     $nodeTo->addChild('CountryCode', $rawRequest->getDestCountryId());
     $nodeTo->addChild('Postalcode', $rawRequest->getDestPostal());
     $nodeTo->addChild('City', $rawRequest->getDestCity());
     $this->_checkDomesticStatus($rawRequest->getOrigCountryId(), $rawRequest->getDestCountryId());
     if ($this->getConfigData('content_type') == self::DHL_CONTENT_TYPE_NON_DOC && !$this->_isDomestic) {
         // IsDutiable flag and Dutiable node indicates that cargo is not a documentation
         $nodeBkgDetails->addChild('IsDutiable', 'Y');
         $nodeDutiable = $nodeGetQuote->addChild('Dutiable');
         $baseCurrencyCode = $this->_storeManager->getWebsite($this->_request->getWebsiteId())->getBaseCurrencyCode();
         $nodeDutiable->addChild('DeclaredCurrency', $baseCurrencyCode);
         $nodeDutiable->addChild('DeclaredValue', sprintf("%.2F", $rawRequest->getValue()));
     }
     return $xml;
 }
Exemple #21
0
 /**
  * Prepare data for add/update action
  *
  * @param array $rowData
  * @return array
  */
 protected function _prepareDataForUpdate(array $rowData)
 {
     $email = strtolower($rowData[self::COLUMN_EMAIL]);
     $customerId = $this->_getCustomerId($email, $rowData[self::COLUMN_WEBSITE]);
     $regionParameters = $this->_getRegionParameters();
     $regionIdTable = $regionParameters['table'];
     $regionIdAttributeId = $regionParameters['attribute_id'];
     // get address attributes
     $addressAttributes = array();
     foreach ($this->_attributes as $attributeAlias => $attributeParams) {
         if (isset($rowData[$attributeAlias]) && strlen($rowData[$attributeAlias])) {
             if ('select' == $attributeParams['type']) {
                 $value = $attributeParams['options'][strtolower($rowData[$attributeAlias])];
             } elseif ('datetime' == $attributeParams['type']) {
                 $value = new \DateTime('@' . strtotime($rowData[$attributeAlias]));
                 $value = $value->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
             } else {
                 $value = $rowData[$attributeAlias];
             }
             $addressAttributes[$attributeParams['id']] = $value;
         }
     }
     // get address id
     if (isset($this->_addresses[$customerId]) && in_array($rowData[self::COLUMN_ADDRESS_ID], $this->_addresses[$customerId])) {
         $addressId = $rowData[self::COLUMN_ADDRESS_ID];
     } else {
         $addressId = $this->_getNextEntityId();
     }
     // entity table data
     $entityRow = array('entity_id' => $addressId, 'entity_type_id' => $this->getEntityTypeId(), 'parent_id' => $customerId, 'created_at' => $this->dateTime->now(), 'updated_at' => $this->dateTime->now());
     // attribute values
     $attributes = array();
     foreach ($this->_attributes as $attributeParams) {
         if (isset($addressAttributes[$attributeParams['id']])) {
             $attributes[$attributeParams['table']][$addressId][$attributeParams['id']] = $addressAttributes[$attributeParams['id']];
         }
     }
     // customer default addresses
     $defaults = array();
     foreach (self::getDefaultAddressAttributeMapping() as $columnName => $attributeCode) {
         if (!empty($rowData[$columnName])) {
             /** @var $attribute \Magento\Eav\Model\Entity\Attribute\AbstractAttribute */
             $attribute = $this->_getCustomerEntity()->getAttribute($attributeCode);
             $defaults[$attribute->getBackend()->getTable()][$customerId][$attribute->getId()] = $addressId;
         }
     }
     // let's try to find region ID
     if (!empty($rowData[self::COLUMN_REGION])) {
         $countryNormalized = strtolower($rowData[self::COLUMN_COUNTRY_ID]);
         $regionNormalized = strtolower($rowData[self::COLUMN_REGION]);
         if (isset($this->_countryRegions[$countryNormalized][$regionNormalized])) {
             $regionId = $this->_countryRegions[$countryNormalized][$regionNormalized];
             $attributes[$regionIdTable][$addressId][$regionIdAttributeId] = $regionId;
             $tableName = $this->_attributes[self::COLUMN_REGION]['table'];
             $regionColumnNameId = $this->_attributes[self::COLUMN_REGION]['id'];
             $attributes[$tableName][$addressId][$regionColumnNameId] = $this->_regions[$regionId];
         }
     }
     return array('entity_row' => $entityRow, 'attributes' => $attributes, 'defaults' => $defaults);
 }