/**
  * This is called from /ecommerce/code/Product
  * returning NULL is like returning TRUE, i.e. ignore this.
  * @param Member $member
  * @return FALSE | NULL
  */
 function canPurchaseByCountry(Member $member = null, $checkPrice = true)
 {
     if ($this->owner->AllCountries) {
         return null;
     }
     $countryCode = EcommerceCountry::get_country();
     if ($countryCode) {
         $included = $this->owner->getManyManyComponents('IncludedCountries', "\"Code\" = '{$countryCode}'")->Count();
         if ($included) {
             return null;
         }
         $excluded = $this->owner->getManyManyComponents('ExcludedCountries', "\"Code\" = '{$countryCode}'")->Count();
         if ($excluded) {
             return false;
         }
     }
     return null;
 }
Beispiel #2
0
 public function getExpectedCountryName()
 {
     return EcommerceCountry::find_title(EcommerceCountry::get_country());
 }
 /**
  * standard SS method
  * sets the country to the best known country {@link EcommerceCountry}
  **/
 function populateDefaults()
 {
     parent::populateDefaults();
     $this->ShippingCountry = EcommerceCountry::get_country();
 }
 /**
  * Checks if we are allowed to sell to the current country.
  * @return Boolean
  */
 public static function allow_sales()
 {
     if (self::$allow_sales_cache === null) {
         self::$allow_sales_cache = true;
         $countryCode = EcommerceCountry::get_country();
         if ($countryCode) {
             $countries = EcommerceCountry::get()->filter(array("DoNotAllowSales" => 1, "Code" => $countryCode));
             if ($countries->count()) {
                 self::$allow_sales_cache = false;
             }
         }
     }
     return self::$allow_sales_cache;
 }
 public function debug()
 {
     $html = EcommerceTaskDebugCart::debug_object($this);
     $html .= "<ul>";
     $html .= "<li><hr />Links<hr /></li>";
     $html .= "<li><b>Link:</b> <a href=\"" . $this->Link() . "\">" . $this->Link() . "</a></li>";
     $html .= "<li><b>Ajax Link:</b> <a href=\"" . $this->AjaxLink() . "\">" . $this->AjaxLink() . "</a></li>";
     $html .= "<li><b>AddVariations Link:</b> <a href=\"" . $this->AddVariationsLink() . "\">" . $this->AddVariationsLink() . "</a></li>";
     $html .= "<li><b>Add to Cart Link:</b> <a href=\"" . $this->AddLink() . "\">" . $this->AddLink() . "</a></li>";
     $html .= "<li><b>Increment Link:</b> <a href=\"" . $this->IncrementLink() . "\">" . $this->IncrementLink() . "</a></li>";
     $html .= "<li><b>Decrement Link:</b> <a href=\"" . $this->DecrementLink() . "\">" . $this->DecrementLink() . "</a></li>";
     $html .= "<li><b>Remove Link:</b> <a href=\"" . $this->RemoveAllLink() . "\">" . $this->RemoveLink() . "</a></li>";
     $html .= "<li><b>Remove All Link:</b> <a href=\"" . $this->RemoveAllLink() . "\">" . $this->RemoveAllLink() . "</a></li>";
     $html .= "<li><b>Remove All and Edit Link:</b> <a href=\"" . $this->RemoveAllAndEditLink() . "\">" . $this->RemoveAllAndEditLink() . "</a></li>";
     $html .= "<li><b>Set Specific Quantity Item Link (e.g. 77):</b> <a href=\"" . $this->SetSpecificQuantityItemLink(77) . "\">" . $this->SetSpecificQuantityItemLink(77) . "</a></li>";
     $html .= "<li><hr />Cart<hr /></li>";
     $html .= "<li><b>Allow Purchase (DB Value):</b> " . $this->AllowPurchaseNice() . " </li>";
     $html .= "<li><b>Can Purchase (overal calculation):</b> " . ($this->canPurchase() ? "YES" : "NO") . " </li>";
     $html .= "<li><b>Shop Open:</b> " . ($this->EcomConfig() ? $this->EcomConfig()->ShopClosed ? "NO" : "YES" : "NO CONFIG") . " </li>";
     $html .= "<li><b>Extended Country Can Purchase:</b> " . ($this->extendedCan('canPurchaseByCountry', null) === null ? "no applicable" : ($this->extendedCan('canPurchaseByCountry', null) ? "CAN PURCHASE" : "CAN NOT PURCHASE")) . " </li>";
     $html .= "<li><b>Allow sales to this country (" . EcommerceCountry::get_country() . "):</b> " . (EcommerceCountry::allow_sales() ? "YES" : "NO") . " </li>";
     $html .= "<li><b>Class Name for OrderItem:</b> " . $this->classNameForOrderItem() . " </li>";
     $html .= "<li><b>Quantity Decimals:</b> " . $this->QuantityDecimals() . " </li>";
     $html .= "<li><b>Is In Cart:</b> " . ($this->IsInCart() ? "YES" : "NO") . " </li>";
     $html .= "<li><b>Has Been Sold:</b> " . ($this->HasBeenSold() ? "YES" : "NO") . " </li>";
     $html .= "<li><b>Calculated Price:</b> " . $this->CalculatedPrice() . " </li>";
     $html .= "<li><b>Calculated Price as Money:</b> " . $this->getCalculatedPriceAsMoney()->Nice() . " </li>";
     $html .= "<li><hr />Location<hr /></li>";
     $html .= "<li><b>Main Parent Group:</b> " . $this->MainParentGroup()->Title . "</li>";
     $html .= "<li><b>All Others Parent Groups:</b> " . ($this->AllParentGroups()->count() ? "<pre>" . print_r($this->AllParentGroups()->map()->toArray(), 1) . "</pre>" : "none") . "</li>";
     $html .= "<li><hr />Image<hr /></li>";
     $html .= "<li><b>Image:</b> " . ($this->BestAvailableImage() ? "<img src=" . $this->BestAvailableImage()->Link() . " />" : "no image") . " </li>";
     $productGroup = ProductGroup::get()->byID($this->ParentID);
     if ($productGroup) {
         $html .= "<li><hr />Product Example<hr /></li>";
         $html .= "<li><b>Product Group View:</b> <a href=\"" . $productGroup->Link() . "\">" . $productGroup->Title . "</a> </li>";
         $html .= "<li><b>Product Group Debug:</b> <a href=\"" . $productGroup->Link("debug") . "\">" . $productGroup->Title . "</a> </li>";
         $html .= "<li><b>Product Group Admin:</b> <a href=\"" . "/admin/pages/edit/show/" . $productGroup->ID . "\">" . $productGroup->Title . " Admin</a> </li>";
         $html .= "<li><b>Edit this Product:</b> <a href=\"" . "/admin/pages/edit/show/" . $this->ID . "\">" . $this->Title . " Admin</a> </li>";
     }
     $html .= "</ul>";
     return $html;
     $html .= "</ul>";
     return $html;
 }
 /**
  * Produces a debug of the shopping cart.
  */
 public function debug()
 {
     if (Director::isDev() || Permission::check("ADMIN")) {
         debug::show($this->currentOrder());
         echo "<hr /><hr /><hr /><hr /><hr /><hr /><h1>Country</h1>";
         echo "GEOIP Country: " . EcommerceCountry::get_country_from_ip() . "<br />";
         echo "Calculated Country Country: " . EcommerceCountry::get_country() . "<br />";
         echo "<blockquote><blockquote><blockquote><blockquote>";
         echo "<hr /><hr /><hr /><hr /><hr /><hr /><h1>Items</h1>";
         $items = $this->currentOrder()->Items();
         echo $items->sql();
         echo "<hr />";
         if ($items->count()) {
             foreach ($items as $item) {
                 Debug::show($item);
             }
         } else {
             echo "<p>there are no items for this order</p>";
         }
         echo "<hr /><hr /><hr /><hr /><hr /><hr /><h1>Modifiers</h1>";
         $modifiers = $this->currentOrder()->Modifiers();
         if ($modifiers->count()) {
             foreach ($modifiers as $modifier) {
                 Debug::show($modifier);
             }
         } else {
             echo "<p>there are no modifiers for this order</p>";
         }
         echo "<hr /><hr /><hr /><hr /><hr /><hr /><h1>Addresses</h1>";
         $billingAddress = $this->currentOrder()->BillingAddress();
         if ($billingAddress && $billingAddress->exists()) {
             Debug::show($billingAddress);
         } else {
             echo "<p>there is no billing address for this order</p>";
         }
         $shippingAddress = $this->currentOrder()->ShippingAddress();
         if ($shippingAddress && $shippingAddress->exists()) {
             Debug::show($shippingAddress);
         } else {
             echo "<p>there is no shipping address for this order</p>";
         }
         $currencyUsed = $this->currentOrder()->CurrencyUsed();
         if ($currencyUsed && $currencyUsed->exists()) {
             echo "<hr /><hr /><hr /><hr /><hr /><hr /><h1>Currency</h1>";
             Debug::show($currencyUsed);
         }
         $cancelledBy = $this->currentOrder()->CancelledBy();
         if ($cancelledBy && $cancelledBy->exists()) {
             echo "<hr /><hr /><hr /><hr /><hr /><hr /><h1>Cancelled By</h1>";
             Debug::show($cancelledBy);
         }
         $logs = $this->currentOrder()->OrderStatusLogs();
         if ($logs && $logs->count()) {
             echo "<hr /><hr /><hr /><hr /><hr /><hr /><h1>Logs</h1>";
             foreach ($logs as $log) {
                 Debug::show($log);
             }
         }
         $payments = $this->currentOrder()->Payments();
         if ($payments && $payments->count()) {
             echo "<hr /><hr /><hr /><hr /><hr /><hr /><h1>Payments</h1>";
             foreach ($payments as $payment) {
                 Debug::show($payment);
             }
         }
         $emails = $this->currentOrder()->Emails();
         if ($emails && $emails->count()) {
             echo "<hr /><hr /><hr /><hr /><hr /><hr /><h1>Emails</h1>";
             foreach ($emails as $email) {
                 Debug::show($email);
             }
         }
         echo "</blockquote></blockquote></blockquote></blockquote>";
     } else {
         echo "Please log in as admin first";
     }
 }
 /**
  * Returns the most likely country for the sale.
  * @return String
  */
 protected function LiveCountry()
 {
     return EcommerceCountry::get_country();
 }
 /**
  * put together a dropdown for the country field
  *
  * @param String $name - name of the field
  * @return DropdownField
  **/
 protected function getCountryField($name)
 {
     $countriesForDropdown = EcommerceCountry::list_of_allowed_entries_for_dropdown();
     $title = _t("OrderAddress." . strtoupper($name), "Country");
     $countryField = new DropdownField($name, $title, $countriesForDropdown, EcommerceCountry::get_country());
     $countryField->setRightTitle(_t("OrderAddress." . strtoupper($name) . "_RIGHT", ""));
     if (count($countriesForDropdown) < 2) {
         $countryField = $countryField->performReadonlyTransformation();
         if (count($countriesForDropdown) < 1) {
             $countryField = new HiddenField($name, '', "not available");
         }
     }
     $prefix = EcommerceConfig::get("OrderAddress", "field_class_and_id_prefix");
     $countryField->addExtraClass($prefix . 'ajaxCountryField');
     //important, otherwise loadData will override the default value....
     $this->{$name} = EcommerceCountry::get_country();
     return $countryField;
 }
 /**
  * put together a dropdown for the country field
  * @param String $name - name of the field
  * @return DropdownField
  **/
 protected function getCountryField($name)
 {
     $countriesForDropdown = EcommerceCountry::list_of_allowed_entries_for_dropdown();
     $countryField = new DropdownField($name, EcommerceCountry::i18n_singular_name(), $countriesForDropdown, EcommerceCountry::get_country());
     if (count($countriesForDropdown) < 2) {
         $countryField = $countryField->performReadonlyTransformation();
         if (count($countriesForDropdown) < 1) {
             $countryField = new HiddenField($name, '', "not available");
         }
     }
     $prefix = EcommerceConfig::get("OrderAddress", "field_class_and_id_prefix");
     $countryField->addExtraClass($prefix . 'ajaxCountryField');
     return $countryField;
 }