The MS SQL and NTEXT Problem (SOLVED)
So, the other day I ran into the problem of trying to pull data from a field which was of type ntext in a MS SQL database using PHP. I'm fairly new with MS SQL and Windows IIS server environments for that matter so please bare with me. Well, I found the solution!
When you're using PHP's mssql_ functions and you need to pull data from a table field which is of type ntext you can't simply pull it using typical select methods, you need to cast the variable as another because the ntext type is not supported in PHP's mssql_ functions.
Code Which Wasn't Working:
$r = mssql_query("select ProductID, Description from myTable where id = '1'");
Solution:
$r = mssql_query("select ProductID, CAST(Description AS TEXT) AS Description from myTable where id = '1'");
Display MSRP in product.SimpleProduct.xml XMLPackage in AspDotNetStorefront
ASPDNSF Version: 9 (C# + MS SQL)
By default in AspDotNetStorefront the MSRP for products is not displayed or used within the product.SimpleProduct.xml XMLPackage, so if you would like to use or display it you will need to make some fine-tuned adjustments.
The Quick and Dirty Way (not as efficient):
In your product.SimpleProduct.xml XMLPackage find the lines where database queries are being made, like:
...
<query name="Products" rowElementName="Product" runif="edit">
<sql>
<![CDATA[
exec dbo.aspdnsf_EditOrderProduct @ShoppingCartRecID, @CustomerLevelID
]]>
</sql>
<queryparam paramname="@ShoppingCartRecID" paramtype="request" requestparamname="CartRecID" sqlDataType="int" defvalue="0" validationpattern="^\d{1,10}$" />
<queryparam paramname="@CustomerLevelID" paramtype="system" requestparamname="CustomerLevelID" sqlDataType="int" defvalue="0" validationpattern="" />
</query>
...
and add a new database query by adding the following after the last query:
<query name="Variant" rowElementName="Price" runif="showproduct">
<sql>
<![CDATA[
select MSRP from dbo.ProductVariant with(NOLOCK) where ProductID=@ProductID and IsDefault=1
]]>
</sql>
<queryparam paramname="@ProductID" paramtype="request" requestparamname="ProductID" sqlDataType="int" defvalue="0" validationpattern="^\d{1,10}$" />
</query>
ex.
...
<query name="Products" rowElementName="Product" runif="edit">
<sql>
<![CDATA[
exec dbo.aspdnsf_EditOrderProduct @ShoppingCartRecID, @CustomerLevelID
]]>
</sql>
<queryparam paramname="@ShoppingCartRecID" paramtype="request" requestparamname="CartRecID" sqlDataType="int" defvalue="0" validationpattern="^\d{1,10}$" />
<queryparam paramname="@CustomerLevelID" paramtype="system" requestparamname="CustomerLevelID" sqlDataType="int" defvalue="0" validationpattern="" />
</query>
<query name="Variant" rowElementName="Price" runif="showproduct">
<sql>
<![CDATA[
select MSRP from dbo.ProductVariant with(NOLOCK) where ProductID=@ProductID and IsDefault=1
]]>
</sql>
<queryparam paramname="@ProductID" paramtype="request" requestparamname="ProductID" sqlDataType="int" defvalue="0" validationpattern="^\d{1,10}$" />
</query>
...
Now, in your XMLPackage wherever you'd like to display the MSRP, simply add the following:
<xsl:value-of select="aspdnsf:FormatCurrency(/root/Variant/Price/MSRP)" disable-output-escaping="yes" />
The Efficient Way (MS SQL):
Using SQL Management Studio, open up the stored procedure and locate near the bottom where it reads:
...
SELECT
p.*,
pv.VariantID, pv.name VariantName, pv.Price, pv.Description VariantDescription, isnull(pv.SalePrice, 0) SalePrice, isnull(SkuSuffix, '') SkuSuffix, pv.Dimensions, pv.Weight, isnull(pv.Points, 0) Points, pv.Inventory, pv.ImageFilenameOverride VariantImageFilenameOverride, pv.isdefault, pv.CustomerEntersPrice, isnull(pv.colors, '') Colors, isnull(pv.sizes, '') Sizes,
...
simply add the MSRP table call to the select statement, like:
...
SELECT
p.*,
pv.VariantID, pv.name VariantName, pv.Price, pv.MSRP, pv.Description VariantDescription, isnull(pv.SalePrice, 0) SalePrice, isnull(SkuSuffix, '') SkuSuffix, pv.Dimensions, pv.Weight, isnull(pv.Points, 0) Points, pv.Inventory, pv.ImageFilenameOverride VariantImageFilenameOverride, pv.isdefault, pv.CustomerEntersPrice, isnull(pv.colors, '') Colors, isnull(pv.sizes, '') Sizes,
...
Now, execute the statement.
Finally, in your XMLPackage where you'd like to display the MSRP simply add the following:
<xsl:value-of select="aspdnsf:FormatCurrency(MSRP)" disable-output-escaping="yes" />
Or, if you're calling it from outside of the Product template, use the full xpath, like:
<xsl:value-of select="aspdnsf:FormatCurrency(/root/Products/Product/MSRP)" disable-output-escaping="yes" />
