/** * @param string $email * @return bool|\Magento\Customer\Model\Customer */ public function getCustomerByEmail($email) { /** @var \Magento\Customer\Model\Customer $customer */ $customer = $this->customerFactory->create(); $customer->setWebsiteId($this->storeManager->getWebsiteId()); $customer->loadByEmail($email); if ($customer->getId()) { return $customer; } return false; }
/** * @return array */ protected function getDefaultCustomerProfile() { if (!$this->customerDataProfile) { $this->customerDataProfile = ['website_id' => $this->storeManager->getWebsiteId(), 'group_id' => $this->storeManager->getGroupId(), 'disable_auto_group_change' => '0', 'prefix', 'firstname' => '', 'middlename' => '', 'lastname' => '', 'suffix' => '', 'email' => '', 'dob' => '', 'taxvat' => '', 'gender' => '', 'confirmation' => false, 'sendemail' => false]; } return $this->customerDataProfile; }
/** * {@inheritdoc} */ public function run() { $this->logger->log("Installing {$this->productType} products:"); $product = $this->productFactory->create(); foreach ($this->fixtures as $file) { /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */ $fileName = $this->fixtureHelper->getPath($file); $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']); foreach ($csvReader as $row) { $attributeSetId = $this->catalogConfig->getAttributeSetId(4, $row['attribute_set']); $this->converter->setAttributeSetId($attributeSetId); $data = $this->converter->convertRow($row); $product->unsetData(); $product->setData($data); $product->setTypeId($this->productType)->setAttributeSetId($attributeSetId)->setWebsiteIds([$this->storeManager->getWebsiteId()])->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)->setStockData(['is_in_stock' => 1, 'manage_stock' => 0])->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID); if (empty($data['visibility'])) { $product->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH); } $this->prepareProduct($product, $data); $product->save(); $this->gallery->install($product); $this->logger->logInline('.'); } } }
/** * {@inheritdoc} */ public function run() { $this->logger->log('Installing Tablerate:'); /** @var \Magento\Framework\DB\Adapter\AdapterInterface $connection */ $connection = $this->resource->getConnection('core'); $fixtureFile = 'OfflineShipping/tablerate.csv'; $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile); $regions = $this->loadDirectoryRegions(); /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */ $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']); foreach ($csvReader as $data) { $regionId = $data['region'] != '*' ? $regions[$data['country']][$data['region']] : 0; try { $connection->insert($this->tablerate->getMainTable(), ['website_id' => $this->storeManager->getWebsiteId(), 'dest_country_id' => $data['country'], 'dest_region_id' => $regionId, 'dest_zip' => $data['zip'], 'condition_name' => 'package_value', 'condition_value' => $data['order_subtotal'], 'price' => $data['price'], 'cost' => 0]); } catch (\Zend_Db_Statement_Exception $e) { if ($e->getCode() == self::ERROR_CODE_DUPLICATE_ENTRY) { // In case if Sample data was already installed we just skip duplicated records installation continue; } else { throw $e; } } $this->logger->logInline('.'); } $this->configWriter->save('carriers/tablerate/active', 1); $this->configWriter->save('carriers/tablerate/condition_name', 'package_value'); $this->cacheTypeList->cleanType('config'); }
/** * @param array $giftRegistryData * @return array */ protected function generateData(array $giftRegistryData) { $giftRegistryData['sku'] = explode("\n", $giftRegistryData['sku']); $customer = $this->customerFactory->create(); $customer->setWebsiteId($this->storeManager->getWebsiteId())->loadByEmail($giftRegistryData['customer_email']); $address = $customer->getDefaultBillingAddress()->getData(); return ['customer_id' => $customer->getId(), 'type_id' => 1, 'title' => $giftRegistryData['title'], 'message' => $giftRegistryData['message'], 'is_public' => 1, 'is_active' => 1, 'event_country' => $address['country_id'], 'event_country_region' => $address['region_id'], 'event_country_region_text' => '', 'event_date' => date('Y-m-d'), 'address' => ['firstname' => $address['firstname'], 'lastname' => $address['lastname'], 'company' => '', 'street' => $address['street'], 'city' => $address['city'], 'region_id' => $address['region_id'], 'region' => $address['region'], 'postcode' => $address['postcode'], 'country_id' => $address['country_id'], 'telephone' => $address['telephone'], 'fax' => ''], 'items' => $this->productSkuToId($giftRegistryData['sku'])]; }
/** * {@inheritdoc} */ public function run() { $this->logger->log('Installing Tablerate:'); /** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter */ $adapter = $this->resource->getConnection('core_write'); $fixtureFile = 'OfflineShipping/tablerate.csv'; $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile); $regions = $this->loadDirectoryRegions(); /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */ $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']); foreach ($csvReader as $data) { $regionId = $data['region'] != '*' ? $regions[$data['country']][$data['region']] : 0; $adapter->insert($this->tablerate->getMainTable(), ['website_id' => $this->storeManager->getWebsiteId(), 'dest_country_id' => $data['country'], 'dest_region_id' => $regionId, 'dest_zip' => $data['zip'], 'condition_name' => 'package_value', 'condition_value' => $data['order_subtotal'], 'price' => $data['price'], 'cost' => 0]); $this->logger->logInline('.'); } $this->configWriter->save('carriers/tablerate/active', 1); $this->configWriter->save('carriers/tablerate/condition_name', 'package_value'); $this->cacheTypeList->cleanType('config'); }
/** * @param array $orderData * @return void */ public function createOrder($orderData) { $this->setPhraseRenderer(); if (!empty($orderData)) { $orderCreateModel = $this->processQuote($orderData); if (!empty($orderData['payment'])) { $orderCreateModel->setPaymentData($orderData['payment']); $orderCreateModel->getQuote()->getPayment()->addData($orderData['payment']); } $customer = $this->customerRepository->get($orderData['order']['account']['email'], $this->storeManager->getWebsiteId()); $orderCreateModel->getQuote()->setCustomer($customer); $orderCreateModel->getSession()->setCustomerId($customer->getId()); $order = $orderCreateModel->importPostData($orderData['order'])->createOrder(); $orderItem = $this->getOrderItemForTransaction($order); $this->invoiceOrder($orderItem); $this->shipOrder($orderItem); if ($orderData['refund'] === "yes") { $this->refundOrder($orderItem); } $registryItems = ['rule_data', 'currently_saved_addresses', 'current_invoice', 'current_shipment']; $this->unsetRegistryData($registryItems); } }