示例#1
0
 protected function getInstance($record, CsvImportProfile $profile)
 {
     $fields = $profile->getSortedFields();
     if (isset($fields['ProductReview']['ID'])) {
         $instance = ActiveRecordModel::getInstanceByID('ProductReview', $record[$fields['ProductReview']['ID']], true);
     } else {
         if (isset($fields['Product']['ID'])) {
             $parent = ActiveRecordModel::getInstanceByID('Product', $record[$fields['Product']['ID']], true);
         } else {
             if (isset($fields['Product']['sku'])) {
                 $parent = Product::getInstanceBySku($record[$fields['Product']['sku']]);
             } else {
                 return;
             }
         }
     }
     if (empty($instance) && empty($parent)) {
         return;
     }
     if (empty($instance)) {
         $instance = ProductReview::getNewInstance($parent, User::getNewInstance(''));
         $instance->isEnabled->set(true);
     }
     return $instance;
 }
示例#2
0
 protected function getInstance($record, CsvImportProfile $profile)
 {
     CustomerOrder::allowEmpty(true);
     $fields = $profile->getSortedFields();
     if (isset($fields['CustomerOrder']['ID'])) {
         $id = $record[$fields['CustomerOrder']['ID']];
         $this->setLastImportedRecordName($id);
         $order = CustomerOrder::getInstanceByID($id, true);
     } else {
         if (isset($fields['CustomerOrder']['invoiceNumber'])) {
             $id = $record[$fields['CustomerOrder']['invoiceNumber']];
             if (!$id) {
                 return null;
             }
             $this->setLastImportedRecordName($id);
             $order = CustomerOrder::getInstanceByInvoiceNumber($id);
             if (!$order) {
                 $order = CustomerOrder::getNewInstance(User::getNewInstance('*****@*****.**'));
                 $order->invoiceNumber->set($id);
                 $order->save();
                 $order->finalize();
             }
         } else {
             return null;
         }
     }
     if ($order) {
         $order->loadAll();
         return $order;
     }
 }
示例#3
0
 public function getSortedFields(CsvImportProfile $profile)
 {
     $fields = $profile->getSortedFields();
     if (isset($fields['Category'])) {
         ksort($fields['Category']);
     }
     return $fields;
 }
示例#4
0
 protected function getInstance($record, CsvImportProfile $profile)
 {
     $fields = $profile->getSortedFields();
     if (isset($fields['NewsPost']['ID'])) {
         try {
             $instance = ActiveRecordModel::getInstanceByID('NewsPost', $record[$fields['NewsPost']['ID']], true);
         } catch (ARNotFoundException $e) {
         }
     }
     if (empty($instance)) {
         $instance = ActiveRecordModel::getNewInstance('NewsPost');
     }
     //$this->setLastImportedRecordName($instance->getID());
     return $instance;
 }
示例#5
0
 protected function getInstance($record, CsvImportProfile $profile)
 {
     $fields = $profile->getSortedFields();
     if (isset($fields['User']['ID'])) {
         $instance = User::getInstanceByID($record[$fields['User']['ID']], true);
     } else {
         if (isset($fields['User']['email'])) {
             $instance = User::getInstanceByEmail($record[$fields['User']['email']]);
         }
     }
     if (empty($instance)) {
         $instance = User::getNewInstance('');
         $instance->isEnabled->set(true);
     }
     $this->setLastImportedRecordName($instance->email->get());
     return $instance;
 }
示例#6
0
 protected function getInstance($record, CsvImportProfile $profile)
 {
     $fields = $profile->getSortedFields();
     if (isset($fields['Currency']['ID'])) {
         try {
             $instance = Currency::getInstanceByID($record[$fields['Currency']['ID']], true);
         } catch (ARNotFoundException $e) {
         }
     } else {
         return;
     }
     if (empty($instance)) {
         $instance = Currency::getNewInstance($record[$fields['Currency']['ID']]);
     }
     $this->setLastImportedRecordName($instance->getID());
     return $instance;
 }
示例#7
0
 protected function getInstance($record, CsvImportProfile $profile)
 {
     pp('User address import get instance');
     $fields = $profile->getSortedFields();
     if (isset($fields['UserAddress']['ID'])) {
         $instance = ActiveRecordModel::getInstanceByID('UserAddress', $record[$fields['UserAddress']['ID']], true);
     } else {
         if (isset($fields['AddressUser']['ID'])) {
             $owner = User::getInstanceByID($record[$fields['AddressUser']['ID']], true);
         } else {
             if (isset($fields['AddressUser']['email'])) {
                 $owner = User::getInstanceByEmail($record[$fields['AddressUser']['email']]);
             }
         }
     }
     if (isset($owner)) {
         if ($profile->isColumnSet('AddressUser.isShipping')) {
             $type = $this->evalBool(strtolower($record[$profile->getColumnIndex('AddressUser.isShipping')])) ? 'ShippingAddress' : 'BillingAddress';
         } else {
             $type = 'BillingAddress';
         }
         $owner->loadAddresses();
     }
     if (empty($instance)) {
         if (empty($owner)) {
             return;
         }
         $isDefault = $profile->isColumnSet('AddressUser.isDefault') && $this->evalBool(strtolower($record[$profile->getColumnIndex('AddressUser.isDefault')]));
         if ($isDefault) {
             $field = 'default' . $type;
             $addressType = $owner->{$field}->get();
             $instance = $addressType->userAddress->get();
         }
         if (empty($addressType)) {
             $instance = UserAddress::getNewInstance();
             $addressType = call_user_func_array(array($type, 'getNewInstance'), array($owner, $instance));
             if ($isDefault) {
                 $owner->{$field}->set($addressType);
             }
         }
         $addressType->userAddress->set($instance);
         $instance->addressType = $addressType;
     }
     return $instance;
 }
 protected function getInstance($record, CsvImportProfile $profile)
 {
     $fields = $profile->getSortedFields();
     if (isset($fields['NewsletterSubscriber']['ID'])) {
         $instance = ActiveRecordModel::getInstanceByID('NewsletterSubscriber', $record[$fields['NewsletterSubscriber']['ID']], true);
     } else {
         if (isset($fields['NewsletterSubscriber']['email'])) {
             $instance = NewsletterSubscriber::getInstanceByEmail($record[$fields['NewsletterSubscriber']['email']]);
         } else {
             return;
         }
     }
     if (empty($instance)) {
         $instance = NewsletterSubscriber::getNewInstanceByEmail($record[$fields['NewsletterSubscriber']['email']]);
     }
     $this->setLastImportedRecordName($instance->email->get());
     return $instance;
 }
示例#9
0
 protected function getInstance($record, CsvImportProfile $profile)
 {
     $fields = $profile->getSortedFields();
     // get delivery zone
     if (isset($fields['DeliveryZone']['ID'])) {
         try {
             $zone = DeliveryZone::getInstanceByID($record[$fields['DeliveryZone']['ID']], true);
         } catch (ARNotFoundException $e) {
             $zone = DeliveryZone::getDefaultZoneInstance();
         }
     } else {
         $zone = DeliveryZone::getDefaultZoneInstance();
     }
     // get shipping service
     $f = select(new EqualsCond(MultiLingualObject::getLangSearchHandle(new ARFieldHandle('ShippingService', 'name'), $this->application->getDefaultLanguageCode()), $record[$fields['ShippingService']['name']]));
     if ($zone->isDefault()) {
         $f->mergeCondition(new IsNullCond(f('ShippingService.deliveryZoneID')));
     } else {
         $f->mergeCondition(eq(f('ShippingService.deliveryZoneID'), $zone->getID()));
     }
     $services = ActiveRecordModel::getRecordSet('ShippingService', $f);
     if ($services->get(0)) {
         $service = $services->get(0);
         // temporary
         $service->deleteRelatedRecordSet('ShippingRate');
     } else {
         $service = ShippingService::getNewInstance($zone, '', 0);
         $service->rangeType->set(ShippingService::SUBTOTAL_BASED);
     }
     $this->importInstance($record, $profile, $service);
     $this->setLastImportedRecordName($service->getValueByLang('name'));
     // get rate instance
     $rate = ShippingRate::getNewInstance($service, 0, 1000000);
     $rate->subtotalRangeStart->set(0);
     $rate->subtotalRangeEnd->set(1000000);
     return $rate;
 }