コード例 #1
0
 function testStoreKey()
 {
     $pref = FoxyCart::getKeyPrefix();
     $siteConf = SiteConfig::current_site_config();
     $this->assertTrue(ctype_alnum($siteConf->StoreKey));
     $this->assertEquals(strlen($siteConf->StoreKey), 60);
     $this->assertEquals(substr($siteConf->StoreKey, 0, 6), $pref);
 }
コード例 #2
0
 /**
  * FoxyStripePurchaseForm constructor.
  * @param Controller $controller
  * @param string $name
  * @param FieldList|null $fields
  * @param FieldList|null $actions
  * @param null $validator
  * @param null $product
  * @param null $siteConfig
  */
 public function __construct($controller, $name, FieldList $fields = null, FieldList $actions = null, $validator = null, $product = null, $siteConfig = null)
 {
     $this->setProduct($product);
     $this->setSiteConfig($siteConfig);
     $fields = $fields != null && $fields->exists() ? $this->getProductFields($fields) : $this->getProductFields(FieldList::create());
     $actions = $actions != null && $actions->exists() ? $this->getProductActions($actions) : $this->getProductActions(FieldList::create());
     $validator = !empty($validator) || $validator != null ? $validator : RequiredFields::create();
     parent::__construct($controller, $name, $fields, $actions, $validator);
     //have to call after parent::__construct()
     $this->setAttribute('action', FoxyCart::FormActionURL());
     $this->disableSecurityToken();
 }
コード例 #3
0
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $siteConfig = SiteConfig::current_site_config();
     if (!$siteConfig->StoreKey) {
         $key = FoxyCart::setStoreKey();
         while (!ctype_alnum($key)) {
             $key = FoxyCart::setStoreKey();
         }
         $siteConfig->StoreKey = $key;
         $siteConfig->write();
         DB::alteration_message($siteConfig->ClassName . ": created FoxyCart Store Key " . $key, 'created');
     }
 }
コード例 #4
0
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     // if Member data was imported from FoxyCart, PasswordEncryption will be set to 'none'.
     // Change to sh1_v2.4 to ensure SilverStripe is using the same hash as FoxyCart API 1.1
     $this->owner->PasswordEncryption = 'sha1_v2.4';
     // Send updated customer data to Foxy Cart via API
     $response = FoxyCart::putCustomer($this->owner);
     // Grab customer_id record from FoxyCart response, store in Member
     if ($response) {
         $foxyResponse = new SimpleXMLElement($response);
         $this->owner->Customer_ID = (int) $foxyResponse->customer_id;
     }
 }
コード例 #5
0
 private static function getAPIRequest($foxyData = array())
 {
     $foxy_domain = FoxyCart::getFoxyCartStoreName() . '.foxycart.com';
     $foxyData["api_token"] = FoxyCart::getStoreKey();
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, "https://" . $foxy_domain . "/api");
     curl_setopt($ch, CURLOPT_POSTFIELDS, $foxyData);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
     curl_setopt($ch, CURLOPT_TIMEOUT, 15);
     // If you get SSL errors, you can uncomment the following, or ask your host to add the appropriate CA bundle
     // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     $response = trim(curl_exec($ch));
     // The following if block will print any CURL errors you might have
     if ($response == false) {
         //trigger_error("Could not connect to FoxyCart API", E_USER_ERROR);
         SS_Log::log("Could not connect to FoxyCart API: " . $response, SS_Log::ERR);
     }
     curl_close($ch);
     return $response;
 }
コード例 #6
0
 public static function getSecret()
 {
     return FoxyCart::getStoreKey();
 }
コード例 #7
0
 public function sso()
 {
     // GET variables from FoxyCart Request
     $fcsid = $this->request->getVar('fcsid');
     $timestampNew = strtotime('+30 days');
     // get current member if logged in. If not, create a 'fake' user with Customer_ID = 0
     // fake user will redirect to FC checkout, ask customer to log in
     // to do: consider a login/registration form here if not logged in
     if ($Member = Member::currentUser()) {
         $Member = Member::currentUser();
     } else {
         $Member = new Member();
         $Member->Customer_ID = 0;
     }
     $auth_token = sha1($Member->Customer_ID . '|' . $timestampNew . '|' . FoxyCart::getStoreKey());
     $redirect_complete = 'https://' . FoxyCart::getFoxyCartStoreName() . '.foxycart.com/checkout?fc_auth_token=' . $auth_token . '&fcsid=' . $fcsid . '&fc_customer_id=' . $Member->Customer_ID . '&timestamp=' . $timestampNew;
     $this->redirect($redirect_complete);
 }
コード例 #8
0
ファイル: ProductPage.php プロジェクト: dynamic/foxystripe
 public function getCartScript()
 {
     return '<script src="https://cdn.foxycart.com/' . FoxyCart::getFoxyCartStoreName() . '/loader.js" async defer></script>';
 }
コード例 #9
0
 public function PurchaseForm()
 {
     $config = SiteConfig::current_site_config();
     $assignAvailable = function ($self) {
         $self->Available = $self->getAvailability() ? true : false;
     };
     $fields = FieldList::create();
     $data = $this->data();
     $hiddenTitle = $data->ReceiptTitle ? htmlspecialchars($data->ReceiptTitle) : htmlspecialchars($data->Title);
     $code = $data->Code;
     if ($data->Available) {
         $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'name', $hiddenTitle))->setValue($hiddenTitle));
         $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'category', $data->Category()->Code))->setValue($data->Category()->Code));
         $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'code', $data->Code))->setValue($data->Code));
         $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'product_id', $data->ID))->setValue($data->ID));
         $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'price', $data->Price))->setValue($data->Price));
         //can't override id
         $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'weight', $data->Weight))->setValue($data->Weight));
         if ($this->DiscountTitle && $this->ProductDiscountTiers()->exists()) {
             $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'discount_quantity_percentage', $data->getDiscountFieldValue()))->setValue($data->getDiscountFieldValue()));
         }
         if ($this->PreviewImage()->Exists()) {
             $fields->push(HiddenField::create(ProductPage::getGeneratedValue($code, 'image', $data->PreviewImage()->PaddedImage(80, 80)->absoluteURL))->setValue($data->PreviewImage()->PaddedImage(80, 80)->absoluteURL));
         }
         $options = $data->ProductOptions();
         $groupedOptions = new GroupedList($options);
         $groupedBy = $groupedOptions->groupBy('ProductOptionGroupID');
         $optionsSet = CompositeField::create();
         foreach ($groupedBy as $id => $set) {
             $group = OptionGroup::get()->byID($id);
             $title = $group->Title;
             $name = preg_replace('/\\s/', '_', $title);
             $set->each($assignAvailable);
             $disabled = array();
             $fullOptions = array();
             foreach ($set as $item) {
                 $fullOptions[ProductPage::getGeneratedValue($data->Code, $group->Title, $item->getGeneratedValue(), 'value')] = $item->getGeneratedTitle();
                 if (!$item->Availability) {
                     array_push($disabled, ProductPage::getGeneratedValue($data->Code, $group->Title, $item->getGeneratedValue(), 'value'));
                 }
             }
             $optionsSet->push($dropdown = DropdownField::create($name, $title, $fullOptions)->setTitle($title));
             $dropdown->setDisabledItems($disabled);
         }
         $optionsSet->addExtraClass('foxycartOptionsContainer');
         $fields->push($optionsSet);
         $quantityMax = $config->MaxQuantity ? $config->MaxQuantity : 10;
         $count = 1;
         $quantity = array();
         while ($count <= $quantityMax) {
             $countVal = ProductPage::getGeneratedValue($data->Code, 'quantity', $count, 'value');
             $quantity[$countVal] = $count;
             $count++;
         }
         $fields->push(DropdownField::create('quantity', 'Quantity', $quantity));
         $fields->push(HeaderField::create('submitPrice', '$' . $data->Price, 4));
         $actions = FieldList::create($submit = FormAction::create('', _t('ProductForm.AddToCart', 'Add to Cart')));
         $submit->setAttribute('name', ProductPage::getGeneratedValue($code, 'Submit', _t('ProductForm.AddToCart', 'Add to Cart')));
         if (!$config->StoreName || $config->StoreName == '' || !isset($config->StoreName)) {
             $submit->setAttribute('Disabled', true);
         }
         $this->extend('updatePurchaseFormFields', $fields);
     } else {
         $fields->push(HeaderField::create('submitPrice', 'Currently Out of Stock'), 4);
         $actions = FieldList::create();
     }
     $form = Form::create($this, 'PurchaseForm', $fields, $actions);
     $form->setAttribute('action', FoxyCart::FormActionURL());
     $form->disableSecurityToken();
     $this->extend('updatePurchaseForm', $form);
     return $form;
 }